Skip to content

Commit 4d8f241

Browse files
committed
rename context variables
1 parent 9efaa69 commit 4d8f241

14 files changed

+274
-274
lines changed

nsqadmin/graphs.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func GraphIntervalForTimeframe(t string, selected bool) (*GraphInterval, error)
114114
}
115115

116116
type GraphOptions struct {
117-
context *Context
117+
ctx *Context
118118
Configured bool
119119
Enabled bool
120120
GraphiteUrl string
@@ -124,7 +124,7 @@ type GraphOptions struct {
124124
}
125125

126126
func NewGraphOptions(rw http.ResponseWriter, req *http.Request,
127-
r *util.ReqParams, context *Context) *GraphOptions {
127+
r *util.ReqParams, ctx *Context) *GraphOptions {
128128
selectedTimeString, err := r.Get("t")
129129
if err != nil && selectedTimeString == "" {
130130
// get from cookie
@@ -151,14 +151,14 @@ func NewGraphOptions(rw http.ResponseWriter, req *http.Request,
151151
if err != nil {
152152
g, _ = GraphIntervalForTimeframe("2h", true)
153153
}
154-
base := context.nsqadmin.options.GraphiteURL
155-
if context.nsqadmin.options.ProxyGraphite {
154+
base := ctx.nsqadmin.options.GraphiteURL
155+
if ctx.nsqadmin.options.ProxyGraphite {
156156
base = ""
157157
}
158158
o := &GraphOptions{
159-
context: context,
160-
Configured: context.nsqadmin.options.GraphiteURL != "",
161-
Enabled: g.Timeframe != "off" && context.nsqadmin.options.GraphiteURL != "",
159+
ctx: ctx,
160+
Configured: ctx.nsqadmin.options.GraphiteURL != "",
161+
Enabled: g.Timeframe != "off" && ctx.nsqadmin.options.GraphiteURL != "",
162162
GraphiteUrl: base,
163163
AllGraphIntervals: DefaultGraphTimeframes(selectedTimeString),
164164
GraphInterval: g,
@@ -169,13 +169,13 @@ func NewGraphOptions(rw http.ResponseWriter, req *http.Request,
169169
func (g *GraphOptions) Prefix(host string, metricType string) string {
170170
prefix := ""
171171
statsdHostKey := util.StatsdHostKey(host)
172-
prefixWithHost := strings.Replace(g.context.nsqadmin.options.StatsdPrefix, "%s", statsdHostKey, -1)
172+
prefixWithHost := strings.Replace(g.ctx.nsqadmin.options.StatsdPrefix, "%s", statsdHostKey, -1)
173173
if prefixWithHost[len(prefixWithHost)-1] != '.' {
174174
prefixWithHost += "."
175175
}
176-
if g.context.nsqadmin.options.UseStatsdPrefixes && metricType == "counter" {
176+
if g.ctx.nsqadmin.options.UseStatsdPrefixes && metricType == "counter" {
177177
prefix += "stats_counts."
178-
} else if g.context.nsqadmin.options.UseStatsdPrefixes && metricType == "gauge" {
178+
} else if g.ctx.nsqadmin.options.UseStatsdPrefixes && metricType == "gauge" {
179179
prefix += "stats.gauges."
180180
}
181181
prefix += prefixWithHost

nsqadmin/http.go

+43-43
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ func NewSingleHostReverseProxy(target *url.URL, timeout time.Duration) *httputil
4444
}
4545

4646
type httpServer struct {
47-
context *Context
47+
ctx *Context
4848
counters map[string]map[string]int64
4949
proxy *httputil.ReverseProxy
5050
}
5151

52-
func NewHTTPServer(context *Context) *httpServer {
52+
func NewHTTPServer(ctx *Context) *httpServer {
5353
var proxy *httputil.ReverseProxy
5454

5555
templates.T.Funcs(template.FuncMap{
@@ -58,7 +58,7 @@ func NewHTTPServer(context *Context) *httpServer {
5858
"floatToPercent": util.FloatToPercent,
5959
"percSuffix": util.PercSuffix,
6060
"getNodeConsistencyClass": func(node *lookupd.Producer) string {
61-
if node.IsInconsistent(len(context.nsqadmin.options.NSQLookupdHTTPAddresses)) {
61+
if node.IsInconsistent(len(ctx.nsqadmin.options.NSQLookupdHTTPAddresses)) {
6262
return "btn-warning"
6363
}
6464
return ""
@@ -67,17 +67,17 @@ func NewHTTPServer(context *Context) *httpServer {
6767

6868
templates.Parse()
6969

70-
if context.nsqadmin.options.ProxyGraphite {
71-
url, err := url.Parse(context.nsqadmin.options.GraphiteURL)
70+
if ctx.nsqadmin.options.ProxyGraphite {
71+
url, err := url.Parse(ctx.nsqadmin.options.GraphiteURL)
7272
if err != nil {
7373
log.Fatalf("ERROR: failed to parse --graphite-url='%s' - %s",
74-
context.nsqadmin.options.GraphiteURL, err.Error())
74+
ctx.nsqadmin.options.GraphiteURL, err.Error())
7575
}
7676
proxy = NewSingleHostReverseProxy(url, 20*time.Second)
7777
}
7878

7979
return &httpServer{
80-
context: context,
80+
ctx: ctx,
8181
counters: make(map[string]map[string]int64),
8282
proxy: proxy,
8383
}
@@ -137,7 +137,7 @@ func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
137137
case "/graphite_data":
138138
s.graphiteDataHandler(w, req)
139139
case "/render":
140-
if !s.context.nsqadmin.options.ProxyGraphite {
140+
if !s.ctx.nsqadmin.options.ProxyGraphite {
141141
http.NotFound(w, req)
142142
return
143143
}
@@ -190,10 +190,10 @@ func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request) {
190190
}
191191

192192
var topics []string
193-
if len(s.context.nsqadmin.options.NSQLookupdHTTPAddresses) != 0 {
194-
topics, _ = lookupd.GetLookupdTopics(s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
193+
if len(s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses) != 0 {
194+
topics, _ = lookupd.GetLookupdTopics(s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
195195
} else {
196-
topics, _ = lookupd.GetNSQDTopics(s.context.nsqadmin.options.NSQDHTTPAddresses)
196+
topics, _ = lookupd.GetNSQDTopics(s.ctx.nsqadmin.options.NSQDHTTPAddresses)
197197
}
198198

199199
p := struct {
@@ -203,7 +203,7 @@ func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request) {
203203
Version string
204204
}{
205205
Title: "NSQ",
206-
GraphOptions: NewGraphOptions(w, req, reqParams, s.context),
206+
GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx),
207207
Topics: TopicsFromStrings(topics),
208208
Version: util.BINARY_VERSION,
209209
}
@@ -273,7 +273,7 @@ func (s *httpServer) topicHandler(w http.ResponseWriter, req *http.Request) {
273273
HasE2eLatency bool
274274
}{
275275
Title: fmt.Sprintf("NSQ %s", topicName),
276-
GraphOptions: NewGraphOptions(w, req, reqParams, s.context),
276+
GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx),
277277
Version: util.BINARY_VERSION,
278278
Topic: topicName,
279279
TopicProducers: producers,
@@ -322,7 +322,7 @@ func (s *httpServer) channelHandler(w http.ResponseWriter, req *http.Request, to
322322
HasE2eLatency bool
323323
}{
324324
Title: fmt.Sprintf("NSQ %s / %s", topicName, channelName),
325-
GraphOptions: NewGraphOptions(w, req, reqParams, s.context),
325+
GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx),
326326
Version: util.BINARY_VERSION,
327327
Topic: topicName,
328328
Channel: channelName,
@@ -348,12 +348,12 @@ func (s *httpServer) lookupHandler(w http.ResponseWriter, req *http.Request) {
348348
}
349349

350350
channels := make(map[string][]string)
351-
allTopics, _ := lookupd.GetLookupdTopics(s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
351+
allTopics, _ := lookupd.GetLookupdTopics(s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
352352
for _, topicName := range allTopics {
353353
var producers []string
354-
producers, _ = lookupd.GetLookupdTopicProducers(topicName, s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
354+
producers, _ = lookupd.GetLookupdTopicProducers(topicName, s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
355355
if len(producers) == 0 {
356-
topicChannels, _ := lookupd.GetLookupdTopicChannels(topicName, s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
356+
topicChannels, _ := lookupd.GetLookupdTopicChannels(topicName, s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
357357
channels[topicName] = topicChannels
358358
}
359359
}
@@ -366,9 +366,9 @@ func (s *httpServer) lookupHandler(w http.ResponseWriter, req *http.Request) {
366366
Version string
367367
}{
368368
Title: "NSQ Lookup",
369-
GraphOptions: NewGraphOptions(w, req, reqParams, s.context),
369+
GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx),
370370
TopicMap: channels,
371-
Lookupd: s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
371+
Lookupd: s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
372372
Version: util.BINARY_VERSION,
373373
}
374374
err = templates.T.ExecuteTemplate(w, "lookup.html", p)
@@ -398,7 +398,7 @@ func (s *httpServer) createTopicChannelHandler(w http.ResponseWriter, req *http.
398398
return
399399
}
400400

401-
for _, addr := range s.context.nsqadmin.options.NSQLookupdHTTPAddresses {
401+
for _, addr := range s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses {
402402
nsqlookupdVersion, err := lookupd.GetVersion(addr)
403403
if err != nil {
404404
log.Printf("ERROR: failed to get nsqlookupd %s version - %s", addr, err)
@@ -441,10 +441,10 @@ func (s *httpServer) createTopicChannelHandler(w http.ResponseWriter, req *http.
441441
if len(channelName) > 0 {
442442
// TODO: we can remove this when we push new channel information from nsqlookupd -> nsqd
443443
producerAddrs, _ := lookupd.GetLookupdTopicProducers(topicName,
444-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
444+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
445445

446446
performVersionNegotiatedRequestsToNSQD(
447-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
447+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
448448
producerAddrs,
449449
"create_channel",
450450
"channel/create",
@@ -483,7 +483,7 @@ func (s *httpServer) tombstoneTopicProducerHandler(w http.ResponseWriter, req *h
483483
}
484484

485485
// tombstone the topic on all the lookupds
486-
for _, addr := range s.context.nsqadmin.options.NSQLookupdHTTPAddresses {
486+
for _, addr := range s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses {
487487
nsqlookupdVersion, err := lookupd.GetVersion(addr)
488488
if err != nil {
489489
log.Printf("ERROR: failed to get nsqlookupd %s version - %s", addr, err)
@@ -551,7 +551,7 @@ func (s *httpServer) deleteTopicHandler(w http.ResponseWriter, req *http.Request
551551
producerAddrs := s.getProducers(topicName)
552552

553553
// remove the topic from all the lookupds
554-
for _, addr := range s.context.nsqadmin.options.NSQLookupdHTTPAddresses {
554+
for _, addr := range s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses {
555555
nsqlookupdVersion, err := lookupd.GetVersion(addr)
556556
if err != nil {
557557
log.Printf("ERROR: failed to get nsqlookupd %s version - %s", addr, err)
@@ -572,7 +572,7 @@ func (s *httpServer) deleteTopicHandler(w http.ResponseWriter, req *http.Request
572572
}
573573

574574
performVersionNegotiatedRequestsToNSQD(
575-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
575+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
576576
producerAddrs,
577577
"delete_topic",
578578
"topic/delete",
@@ -602,7 +602,7 @@ func (s *httpServer) deleteChannelHandler(w http.ResponseWriter, req *http.Reque
602602
rd = fmt.Sprintf("/topic/%s", url.QueryEscape(topicName))
603603
}
604604

605-
for _, addr := range s.context.nsqadmin.options.NSQLookupdHTTPAddresses {
605+
for _, addr := range s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses {
606606
nsqlookupdVersion, err := lookupd.GetVersion(addr)
607607
if err != nil {
608608
log.Printf("ERROR: failed to get nsqlookupd %s version - %s", addr, err)
@@ -627,7 +627,7 @@ func (s *httpServer) deleteChannelHandler(w http.ResponseWriter, req *http.Reque
627627

628628
producerAddrs := s.getProducers(topicName)
629629
performVersionNegotiatedRequestsToNSQD(
630-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
630+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
631631
producerAddrs,
632632
"delete_channel",
633633
"channel/delete",
@@ -655,7 +655,7 @@ func (s *httpServer) emptyTopicHandler(w http.ResponseWriter, req *http.Request)
655655

656656
producerAddrs := s.getProducers(topicName)
657657
performVersionNegotiatedRequestsToNSQD(
658-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
658+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
659659
producerAddrs,
660660
"empty_topic",
661661
"topic/empty",
@@ -688,7 +688,7 @@ func (s *httpServer) pauseTopicHandler(w http.ResponseWriter, req *http.Request)
688688

689689
producerAddrs := s.getProducers(topicName)
690690
performVersionNegotiatedRequestsToNSQD(
691-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
691+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
692692
producerAddrs,
693693
verb+"_topic",
694694
"topic/"+verb,
@@ -716,7 +716,7 @@ func (s *httpServer) emptyChannelHandler(w http.ResponseWriter, req *http.Reques
716716

717717
producerAddrs := s.getProducers(topicName)
718718
performVersionNegotiatedRequestsToNSQD(
719-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
719+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
720720
producerAddrs,
721721
"empty_channel",
722722
"channel/empty",
@@ -750,7 +750,7 @@ func (s *httpServer) pauseChannelHandler(w http.ResponseWriter, req *http.Reques
750750

751751
producerAddrs := s.getProducers(topicName)
752752
performVersionNegotiatedRequestsToNSQD(
753-
s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
753+
s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
754754
producerAddrs,
755755
verb+"_channel",
756756
"channel/"+verb,
@@ -780,13 +780,13 @@ func (s *httpServer) nodeHandler(w http.ResponseWriter, req *http.Request) {
780780
node := parts[0]
781781

782782
found := false
783-
for _, n := range s.context.nsqadmin.options.NSQDHTTPAddresses {
783+
for _, n := range s.ctx.nsqadmin.options.NSQDHTTPAddresses {
784784
if node == n {
785785
found = true
786786
break
787787
}
788788
}
789-
producers, _ := lookupd.GetLookupdProducers(s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
789+
producers, _ := lookupd.GetLookupdProducers(s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
790790
for _, p := range producers {
791791
if node == fmt.Sprintf("%s:%d", p.BroadcastAddress, p.HttpPort) {
792792
found = true
@@ -821,7 +821,7 @@ func (s *httpServer) nodeHandler(w http.ResponseWriter, req *http.Request) {
821821
}{
822822
Title: "NSQ Node - " + node,
823823
Version: util.BINARY_VERSION,
824-
GraphOptions: NewGraphOptions(w, req, reqParams, s.context),
824+
GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx),
825825
Node: Node(node),
826826
TopicStats: topicStats,
827827
ChannelStats: channelStats,
@@ -842,7 +842,7 @@ func (s *httpServer) nodesHandler(w http.ResponseWriter, req *http.Request) {
842842
http.Error(w, "INVALID_REQUEST", 500)
843843
return
844844
}
845-
producers, _ := lookupd.GetLookupdProducers(s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
845+
producers, _ := lookupd.GetLookupdProducers(s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
846846

847847
p := struct {
848848
Title string
@@ -853,9 +853,9 @@ func (s *httpServer) nodesHandler(w http.ResponseWriter, req *http.Request) {
853853
}{
854854
Title: "NSQ Nodes",
855855
Version: util.BINARY_VERSION,
856-
GraphOptions: NewGraphOptions(w, req, reqParams, s.context),
856+
GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx),
857857
Producers: producers,
858-
Lookupd: s.context.nsqadmin.options.NSQLookupdHTTPAddresses,
858+
Lookupd: s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses,
859859
}
860860
err = templates.T.ExecuteTemplate(w, "nodes.html", p)
861861
if err != nil {
@@ -889,7 +889,7 @@ func (s *httpServer) counterHandler(w http.ResponseWriter, req *http.Request) {
889889
}{
890890
Title: "NSQ Message Counts",
891891
Version: util.BINARY_VERSION,
892-
GraphOptions: NewGraphOptions(w, req, reqParams, s.context),
892+
GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx),
893893
Target: counterTarget{},
894894
}
895895
err = templates.T.ExecuteTemplate(w, "counter.html", p)
@@ -925,7 +925,7 @@ func (s *httpServer) counterDataHandler(w http.ResponseWriter, req *http.Request
925925
newStats := make(map[string]int64)
926926
newStats["time"] = now.Unix()
927927

928-
producers, _ := lookupd.GetLookupdProducers(s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
928+
producers, _ := lookupd.GetLookupdProducers(s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
929929
addresses := make([]string, len(producers))
930930
for i, p := range producers {
931931
addresses[i] = p.HTTPAddress()
@@ -990,7 +990,7 @@ func (s *httpServer) graphiteDataHandler(w http.ResponseWriter, req *http.Reques
990990
}
991991

992992
query := queryFunc(target)
993-
url := s.context.nsqadmin.options.GraphiteURL + query
993+
url := s.ctx.nsqadmin.options.GraphiteURL + query
994994
log.Printf("GRAPHITE: %s", url)
995995
response, err := graphiteGet(url)
996996
if err != nil {
@@ -1032,10 +1032,10 @@ func graphiteGet(request_url string) ([]byte, error) {
10321032

10331033
func (s *httpServer) getProducers(topicName string) []string {
10341034
var producers []string
1035-
if len(s.context.nsqadmin.options.NSQLookupdHTTPAddresses) != 0 {
1036-
producers, _ = lookupd.GetLookupdTopicProducers(topicName, s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
1035+
if len(s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses) != 0 {
1036+
producers, _ = lookupd.GetLookupdTopicProducers(topicName, s.ctx.nsqadmin.options.NSQLookupdHTTPAddresses)
10371037
} else {
1038-
producers, _ = lookupd.GetNSQDTopicProducers(topicName, s.context.nsqadmin.options.NSQDHTTPAddresses)
1038+
producers, _ = lookupd.GetNSQDTopicProducers(topicName, s.ctx.nsqadmin.options.NSQDHTTPAddresses)
10391039
}
10401040
return producers
10411041
}

nsqadmin/notify.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func basicAuthUser(req *http.Request) string {
3636

3737
func (s *httpServer) notifyAdminAction(actionType string, topicName string,
3838
channelName string, node string, req *http.Request) {
39-
if s.context.nsqadmin.options.NotificationHTTPEndpoint == "" {
39+
if s.ctx.nsqadmin.options.NotificationHTTPEndpoint == "" {
4040
return
4141
}
4242
action := &AdminAction{
@@ -50,5 +50,5 @@ func (s *httpServer) notifyAdminAction(actionType string, topicName string,
5050
req.UserAgent(),
5151
}
5252
// Perform all work in a new goroutine so this never blocks
53-
go func() { s.context.nsqadmin.notifications <- action }()
53+
go func() { s.ctx.nsqadmin.notifications <- action }()
5454
}

0 commit comments

Comments
 (0)