Skip to content

Commit db853fa

Browse files
committed
[supervisor] report metrics with x-client
1 parent 543914a commit db853fa

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

components/supervisor/pkg/metrics/reporter.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,16 @@ func doAddCounter(gitpodHost string, name string, labels map[string]string, valu
174174
return
175175
}
176176
url := fmt.Sprintf("https://ide.%s/metrics-api/metrics/counter/add/%s", gitpodHost, name)
177-
resp, err := http.Post(url, "application/json", bytes.NewReader(body))
177+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
178+
defer cancel()
179+
request, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
180+
if err != nil {
181+
log.WithError(err).Error("supervisor: grpc metric: failed to create request")
182+
return
183+
}
184+
request.Header.Set("Content-Type", "application/json")
185+
request.Header.Set("X-Client", "supervisor")
186+
resp, err := http.DefaultClient.Do(request)
178187
var statusCode int
179188
if resp != nil {
180189
statusCode = resp.StatusCode
@@ -217,7 +226,16 @@ func doAddHistogram(gitpodHost string, name string, labels map[string]string, co
217226
return
218227
}
219228
url := fmt.Sprintf("https://ide.%s/metrics-api/metrics/histogram/add/%s", gitpodHost, name)
220-
resp, err := http.Post(url, "application/json", bytes.NewReader(body))
229+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
230+
defer cancel()
231+
request, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
232+
if err != nil {
233+
log.WithError(err).Error("supervisor: grpc metric: failed to create request")
234+
return
235+
}
236+
request.Header.Set("Content-Type", "application/json")
237+
request.Header.Set("X-Client", "supervisor")
238+
resp, err := http.DefaultClient.Do(request)
221239
var statusCode int
222240
if resp != nil {
223241
statusCode = resp.StatusCode

0 commit comments

Comments
 (0)