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