@@ -130,7 +130,7 @@ func (c *PromClient) setUrl(url string) {
130
130
131
131
// instanceConfigRequest is the HTTP request received for generating instance config
132
132
type instanceConfigRequest struct {
133
- //Config is the content of the yaml file
133
+ // Config is the content of the yaml file
134
134
Config string `json:"config"`
135
135
Insecure bool `json:"insecure"`
136
136
}
@@ -140,15 +140,15 @@ func (c *PromClient) UpdatePrometheusTargets(
140
140
ctx context.Context ,
141
141
clusterName string ,
142
142
forceFetchCreds bool ,
143
- nodes map [ int ][] * NodeInfo ,
143
+ nodeTargets NodeTargets ,
144
144
insecure bool ,
145
145
l * logger.Logger ,
146
146
) error {
147
147
if c .disabled {
148
148
l .Printf ("Prometheus registration is disabled" )
149
149
return nil
150
150
}
151
- req , err := buildCreateRequest (nodes , insecure )
151
+ req , err := buildCreateRequest (nodeTargets , insecure )
152
152
if err != nil {
153
153
return err
154
154
}
@@ -171,7 +171,7 @@ func (c *PromClient) UpdatePrometheusTargets(
171
171
defer func () { _ = response .Body .Close () }()
172
172
if response .StatusCode == http .StatusUnauthorized && ! forceFetchCreds {
173
173
l .Printf ("request failed - this may be due to a stale token. retrying with forceFetchCreds true ..." )
174
- return c .UpdatePrometheusTargets (ctx , clusterName , true , nodes , insecure , l )
174
+ return c .UpdatePrometheusTargets (ctx , clusterName , true , nodeTargets , insecure , l )
175
175
}
176
176
body , err := io .ReadAll (response .Body )
177
177
if err != nil {
@@ -253,8 +253,23 @@ type NodeInfo struct {
253
253
CustomLabels map [string ]string // Custom labels to be added to the cluster config
254
254
}
255
255
256
+ // NodeTargets contains prometheus scrape targets for each node.
257
+ type NodeTargets map [int ][]* NodeInfo
258
+
259
+ func (nt NodeTargets ) String () string {
260
+ var parts []string
261
+ for port , infos := range nt {
262
+ var targets []string
263
+ for _ , info := range infos {
264
+ targets = append (targets , info .Target )
265
+ }
266
+ parts = append (parts , fmt .Sprintf ("%d:[%s]" , port , strings .Join (targets , "," )))
267
+ }
268
+ return strings .Join (parts , " " )
269
+ }
270
+
256
271
// createClusterConfigFile creates the cluster config file per node
257
- func buildCreateRequest (nodes map [ int ][] * NodeInfo , insecure bool ) (io.Reader , error ) {
272
+ func buildCreateRequest (nodes NodeTargets , insecure bool ) (io.Reader , error ) {
258
273
configs := make ([]* CCParams , 0 )
259
274
for _ , n := range nodes {
260
275
for _ , node := range n {
0 commit comments