mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* [installer] make sure dashboard is deployed after server and papi-server * fix build * Add unit tests * address feedback * wait feature flag until get actual value of timed out * default config cat client nil * log avg fetch time * 1 * mock feature flag hang * Add metric * fixup
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package metrics
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gitpod-io/gitpod/common-go/log"
|
|
)
|
|
|
|
// service_waiter_skip_components
|
|
const WaitComponentFeatureFlagMetricName = "service_waiter_skip_components_result_total"
|
|
|
|
func AddSkipComponentsCounter(host, value string, isActual bool) {
|
|
labels := map[string]string{
|
|
"value": value,
|
|
"ok": strconv.FormatBool(isActual),
|
|
}
|
|
addCounter(host, WaitComponentFeatureFlagMetricName, labels)
|
|
}
|
|
|
|
func addCounter(host, metricName string, labels map[string]string) {
|
|
if host == "" {
|
|
log.Error("host is empty")
|
|
return
|
|
}
|
|
body := map[string]interface{}{
|
|
"labels": labels,
|
|
"value": 1,
|
|
}
|
|
b, err := json.Marshal(body)
|
|
if err != nil {
|
|
log.WithError(err).Error("cannot marshal body")
|
|
return
|
|
}
|
|
resp, err := http.Post(host+"/metrics-api/metrics/counter/add/"+metricName, "application/json", bytes.NewReader(b))
|
|
if err != nil {
|
|
log.WithError(err).Error("cannot post metrics")
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
log.WithField("status", resp.Status).Error("failed to post metrics")
|
|
}
|
|
log.Info("metric reported")
|
|
}
|