@@ -44,12 +44,12 @@ func NewSingleHostReverseProxy(target *url.URL, timeout time.Duration) *httputil
44
44
}
45
45
46
46
type httpServer struct {
47
- context * Context
47
+ ctx * Context
48
48
counters map [string ]map [string ]int64
49
49
proxy * httputil.ReverseProxy
50
50
}
51
51
52
- func NewHTTPServer (context * Context ) * httpServer {
52
+ func NewHTTPServer (ctx * Context ) * httpServer {
53
53
var proxy * httputil.ReverseProxy
54
54
55
55
templates .T .Funcs (template.FuncMap {
@@ -58,7 +58,7 @@ func NewHTTPServer(context *Context) *httpServer {
58
58
"floatToPercent" : util .FloatToPercent ,
59
59
"percSuffix" : util .PercSuffix ,
60
60
"getNodeConsistencyClass" : func (node * lookupd.Producer ) string {
61
- if node .IsInconsistent (len (context .nsqadmin .options .NSQLookupdHTTPAddresses )) {
61
+ if node .IsInconsistent (len (ctx .nsqadmin .options .NSQLookupdHTTPAddresses )) {
62
62
return "btn-warning"
63
63
}
64
64
return ""
@@ -67,17 +67,17 @@ func NewHTTPServer(context *Context) *httpServer {
67
67
68
68
templates .Parse ()
69
69
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 )
72
72
if err != nil {
73
73
log .Fatalf ("ERROR: failed to parse --graphite-url='%s' - %s" ,
74
- context .nsqadmin .options .GraphiteURL , err .Error ())
74
+ ctx .nsqadmin .options .GraphiteURL , err .Error ())
75
75
}
76
76
proxy = NewSingleHostReverseProxy (url , 20 * time .Second )
77
77
}
78
78
79
79
return & httpServer {
80
- context : context ,
80
+ ctx : ctx ,
81
81
counters : make (map [string ]map [string ]int64 ),
82
82
proxy : proxy ,
83
83
}
@@ -137,7 +137,7 @@ func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
137
137
case "/graphite_data" :
138
138
s .graphiteDataHandler (w , req )
139
139
case "/render" :
140
- if ! s .context .nsqadmin .options .ProxyGraphite {
140
+ if ! s .ctx .nsqadmin .options .ProxyGraphite {
141
141
http .NotFound (w , req )
142
142
return
143
143
}
@@ -190,10 +190,10 @@ func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request) {
190
190
}
191
191
192
192
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 )
195
195
} else {
196
- topics , _ = lookupd .GetNSQDTopics (s .context .nsqadmin .options .NSQDHTTPAddresses )
196
+ topics , _ = lookupd .GetNSQDTopics (s .ctx .nsqadmin .options .NSQDHTTPAddresses )
197
197
}
198
198
199
199
p := struct {
@@ -203,7 +203,7 @@ func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request) {
203
203
Version string
204
204
}{
205
205
Title : "NSQ" ,
206
- GraphOptions : NewGraphOptions (w , req , reqParams , s .context ),
206
+ GraphOptions : NewGraphOptions (w , req , reqParams , s .ctx ),
207
207
Topics : TopicsFromStrings (topics ),
208
208
Version : util .BINARY_VERSION ,
209
209
}
@@ -273,7 +273,7 @@ func (s *httpServer) topicHandler(w http.ResponseWriter, req *http.Request) {
273
273
HasE2eLatency bool
274
274
}{
275
275
Title : fmt .Sprintf ("NSQ %s" , topicName ),
276
- GraphOptions : NewGraphOptions (w , req , reqParams , s .context ),
276
+ GraphOptions : NewGraphOptions (w , req , reqParams , s .ctx ),
277
277
Version : util .BINARY_VERSION ,
278
278
Topic : topicName ,
279
279
TopicProducers : producers ,
@@ -322,7 +322,7 @@ func (s *httpServer) channelHandler(w http.ResponseWriter, req *http.Request, to
322
322
HasE2eLatency bool
323
323
}{
324
324
Title : fmt .Sprintf ("NSQ %s / %s" , topicName , channelName ),
325
- GraphOptions : NewGraphOptions (w , req , reqParams , s .context ),
325
+ GraphOptions : NewGraphOptions (w , req , reqParams , s .ctx ),
326
326
Version : util .BINARY_VERSION ,
327
327
Topic : topicName ,
328
328
Channel : channelName ,
@@ -348,12 +348,12 @@ func (s *httpServer) lookupHandler(w http.ResponseWriter, req *http.Request) {
348
348
}
349
349
350
350
channels := make (map [string ][]string )
351
- allTopics , _ := lookupd .GetLookupdTopics (s .context .nsqadmin .options .NSQLookupdHTTPAddresses )
351
+ allTopics , _ := lookupd .GetLookupdTopics (s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses )
352
352
for _ , topicName := range allTopics {
353
353
var producers []string
354
- producers , _ = lookupd .GetLookupdTopicProducers (topicName , s .context .nsqadmin .options .NSQLookupdHTTPAddresses )
354
+ producers , _ = lookupd .GetLookupdTopicProducers (topicName , s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses )
355
355
if len (producers ) == 0 {
356
- topicChannels , _ := lookupd .GetLookupdTopicChannels (topicName , s .context .nsqadmin .options .NSQLookupdHTTPAddresses )
356
+ topicChannels , _ := lookupd .GetLookupdTopicChannels (topicName , s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses )
357
357
channels [topicName ] = topicChannels
358
358
}
359
359
}
@@ -366,9 +366,9 @@ func (s *httpServer) lookupHandler(w http.ResponseWriter, req *http.Request) {
366
366
Version string
367
367
}{
368
368
Title : "NSQ Lookup" ,
369
- GraphOptions : NewGraphOptions (w , req , reqParams , s .context ),
369
+ GraphOptions : NewGraphOptions (w , req , reqParams , s .ctx ),
370
370
TopicMap : channels ,
371
- Lookupd : s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
371
+ Lookupd : s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
372
372
Version : util .BINARY_VERSION ,
373
373
}
374
374
err = templates .T .ExecuteTemplate (w , "lookup.html" , p )
@@ -398,7 +398,7 @@ func (s *httpServer) createTopicChannelHandler(w http.ResponseWriter, req *http.
398
398
return
399
399
}
400
400
401
- for _ , addr := range s .context .nsqadmin .options .NSQLookupdHTTPAddresses {
401
+ for _ , addr := range s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses {
402
402
nsqlookupdVersion , err := lookupd .GetVersion (addr )
403
403
if err != nil {
404
404
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.
441
441
if len (channelName ) > 0 {
442
442
// TODO: we can remove this when we push new channel information from nsqlookupd -> nsqd
443
443
producerAddrs , _ := lookupd .GetLookupdTopicProducers (topicName ,
444
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses )
444
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses )
445
445
446
446
performVersionNegotiatedRequestsToNSQD (
447
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
447
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
448
448
producerAddrs ,
449
449
"create_channel" ,
450
450
"channel/create" ,
@@ -483,7 +483,7 @@ func (s *httpServer) tombstoneTopicProducerHandler(w http.ResponseWriter, req *h
483
483
}
484
484
485
485
// 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 {
487
487
nsqlookupdVersion , err := lookupd .GetVersion (addr )
488
488
if err != nil {
489
489
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
551
551
producerAddrs := s .getProducers (topicName )
552
552
553
553
// 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 {
555
555
nsqlookupdVersion , err := lookupd .GetVersion (addr )
556
556
if err != nil {
557
557
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
572
572
}
573
573
574
574
performVersionNegotiatedRequestsToNSQD (
575
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
575
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
576
576
producerAddrs ,
577
577
"delete_topic" ,
578
578
"topic/delete" ,
@@ -602,7 +602,7 @@ func (s *httpServer) deleteChannelHandler(w http.ResponseWriter, req *http.Reque
602
602
rd = fmt .Sprintf ("/topic/%s" , url .QueryEscape (topicName ))
603
603
}
604
604
605
- for _ , addr := range s .context .nsqadmin .options .NSQLookupdHTTPAddresses {
605
+ for _ , addr := range s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses {
606
606
nsqlookupdVersion , err := lookupd .GetVersion (addr )
607
607
if err != nil {
608
608
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
627
627
628
628
producerAddrs := s .getProducers (topicName )
629
629
performVersionNegotiatedRequestsToNSQD (
630
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
630
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
631
631
producerAddrs ,
632
632
"delete_channel" ,
633
633
"channel/delete" ,
@@ -655,7 +655,7 @@ func (s *httpServer) emptyTopicHandler(w http.ResponseWriter, req *http.Request)
655
655
656
656
producerAddrs := s .getProducers (topicName )
657
657
performVersionNegotiatedRequestsToNSQD (
658
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
658
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
659
659
producerAddrs ,
660
660
"empty_topic" ,
661
661
"topic/empty" ,
@@ -688,7 +688,7 @@ func (s *httpServer) pauseTopicHandler(w http.ResponseWriter, req *http.Request)
688
688
689
689
producerAddrs := s .getProducers (topicName )
690
690
performVersionNegotiatedRequestsToNSQD (
691
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
691
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
692
692
producerAddrs ,
693
693
verb + "_topic" ,
694
694
"topic/" + verb ,
@@ -716,7 +716,7 @@ func (s *httpServer) emptyChannelHandler(w http.ResponseWriter, req *http.Reques
716
716
717
717
producerAddrs := s .getProducers (topicName )
718
718
performVersionNegotiatedRequestsToNSQD (
719
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
719
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
720
720
producerAddrs ,
721
721
"empty_channel" ,
722
722
"channel/empty" ,
@@ -750,7 +750,7 @@ func (s *httpServer) pauseChannelHandler(w http.ResponseWriter, req *http.Reques
750
750
751
751
producerAddrs := s .getProducers (topicName )
752
752
performVersionNegotiatedRequestsToNSQD (
753
- s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
753
+ s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
754
754
producerAddrs ,
755
755
verb + "_channel" ,
756
756
"channel/" + verb ,
@@ -780,13 +780,13 @@ func (s *httpServer) nodeHandler(w http.ResponseWriter, req *http.Request) {
780
780
node := parts [0 ]
781
781
782
782
found := false
783
- for _ , n := range s .context .nsqadmin .options .NSQDHTTPAddresses {
783
+ for _ , n := range s .ctx .nsqadmin .options .NSQDHTTPAddresses {
784
784
if node == n {
785
785
found = true
786
786
break
787
787
}
788
788
}
789
- producers , _ := lookupd .GetLookupdProducers (s .context .nsqadmin .options .NSQLookupdHTTPAddresses )
789
+ producers , _ := lookupd .GetLookupdProducers (s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses )
790
790
for _ , p := range producers {
791
791
if node == fmt .Sprintf ("%s:%d" , p .BroadcastAddress , p .HttpPort ) {
792
792
found = true
@@ -821,7 +821,7 @@ func (s *httpServer) nodeHandler(w http.ResponseWriter, req *http.Request) {
821
821
}{
822
822
Title : "NSQ Node - " + node ,
823
823
Version : util .BINARY_VERSION ,
824
- GraphOptions : NewGraphOptions (w , req , reqParams , s .context ),
824
+ GraphOptions : NewGraphOptions (w , req , reqParams , s .ctx ),
825
825
Node : Node (node ),
826
826
TopicStats : topicStats ,
827
827
ChannelStats : channelStats ,
@@ -842,7 +842,7 @@ func (s *httpServer) nodesHandler(w http.ResponseWriter, req *http.Request) {
842
842
http .Error (w , "INVALID_REQUEST" , 500 )
843
843
return
844
844
}
845
- producers , _ := lookupd .GetLookupdProducers (s .context .nsqadmin .options .NSQLookupdHTTPAddresses )
845
+ producers , _ := lookupd .GetLookupdProducers (s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses )
846
846
847
847
p := struct {
848
848
Title string
@@ -853,9 +853,9 @@ func (s *httpServer) nodesHandler(w http.ResponseWriter, req *http.Request) {
853
853
}{
854
854
Title : "NSQ Nodes" ,
855
855
Version : util .BINARY_VERSION ,
856
- GraphOptions : NewGraphOptions (w , req , reqParams , s .context ),
856
+ GraphOptions : NewGraphOptions (w , req , reqParams , s .ctx ),
857
857
Producers : producers ,
858
- Lookupd : s .context .nsqadmin .options .NSQLookupdHTTPAddresses ,
858
+ Lookupd : s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses ,
859
859
}
860
860
err = templates .T .ExecuteTemplate (w , "nodes.html" , p )
861
861
if err != nil {
@@ -889,7 +889,7 @@ func (s *httpServer) counterHandler(w http.ResponseWriter, req *http.Request) {
889
889
}{
890
890
Title : "NSQ Message Counts" ,
891
891
Version : util .BINARY_VERSION ,
892
- GraphOptions : NewGraphOptions (w , req , reqParams , s .context ),
892
+ GraphOptions : NewGraphOptions (w , req , reqParams , s .ctx ),
893
893
Target : counterTarget {},
894
894
}
895
895
err = templates .T .ExecuteTemplate (w , "counter.html" , p )
@@ -925,7 +925,7 @@ func (s *httpServer) counterDataHandler(w http.ResponseWriter, req *http.Request
925
925
newStats := make (map [string ]int64 )
926
926
newStats ["time" ] = now .Unix ()
927
927
928
- producers , _ := lookupd .GetLookupdProducers (s .context .nsqadmin .options .NSQLookupdHTTPAddresses )
928
+ producers , _ := lookupd .GetLookupdProducers (s .ctx .nsqadmin .options .NSQLookupdHTTPAddresses )
929
929
addresses := make ([]string , len (producers ))
930
930
for i , p := range producers {
931
931
addresses [i ] = p .HTTPAddress ()
@@ -990,7 +990,7 @@ func (s *httpServer) graphiteDataHandler(w http.ResponseWriter, req *http.Reques
990
990
}
991
991
992
992
query := queryFunc (target )
993
- url := s .context .nsqadmin .options .GraphiteURL + query
993
+ url := s .ctx .nsqadmin .options .GraphiteURL + query
994
994
log .Printf ("GRAPHITE: %s" , url )
995
995
response , err := graphiteGet (url )
996
996
if err != nil {
@@ -1032,10 +1032,10 @@ func graphiteGet(request_url string) ([]byte, error) {
1032
1032
1033
1033
func (s * httpServer ) getProducers (topicName string ) []string {
1034
1034
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 )
1037
1037
} else {
1038
- producers , _ = lookupd .GetNSQDTopicProducers (topicName , s .context .nsqadmin .options .NSQDHTTPAddresses )
1038
+ producers , _ = lookupd .GetNSQDTopicProducers (topicName , s .ctx .nsqadmin .options .NSQDHTTPAddresses )
1039
1039
}
1040
1040
return producers
1041
1041
}
0 commit comments