Skip to content

Commit

Permalink
chore(deps): remove dependency on github.com/prometheus/prometheus (#…
Browse files Browse the repository at this point in the history
…6204)

We were maintaining this dependency for a label check that
is very simple and unlikely to change. Opted for duplicating it
instead

Signed-off-by: Charly Molter <charly.molter@konghq.com>
  • Loading branch information
lahabana authored Mar 7, 2023
1 parent 1705b45 commit 0a72af7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ require (
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.40.0
github.com/prometheus/prometheus v0.42.0
github.com/sethvargo/go-retry v0.2.4
github.com/shopspring/decimal v1.3.1
github.com/slok/go-http-metrics v0.10.0
Expand Down Expand Up @@ -127,7 +126,6 @@ require (
github.com/google/pprof v0.0.0-20230111200839-76d1ae5aea2b // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,6 @@ github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd h1:PpuIBO5P3e9hpqBD0O/HjhShYuM6XE0i/lbE6J94kww=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand Down Expand Up @@ -1186,8 +1184,6 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/prometheus/prometheus v0.42.0 h1:G769v8covTkOiNckXFIwLx01XE04OE6Fr0JPA0oR2nI=
github.com/prometheus/prometheus v0.42.0/go.mod h1:Pfqb/MLnnR2KK+0vchiaH39jXxvLMBk+3lnIGP4N7Vk=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
Expand Down
18 changes: 13 additions & 5 deletions pkg/mads/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package mads
import (
"fmt"
"net"
"regexp"
"strconv"
"strings"

prom_util "github.com/prometheus/prometheus/util/strutil"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/xds/topology"
Expand Down Expand Up @@ -44,17 +43,17 @@ func DataplaneLabels(dataplane *core_mesh.DataplaneResource, meshGateways []*cor
value = values[0]
}
// while in general case a tag might have multiple values, we want to optimize for a single-value scenario
labels[prom_util.SanitizeLabelName(key)] = value
labels[sanitizeLabelName(key)] = value
// additionally, we also support a multi-value scenario by automatically pluralizing label name,
// e.g. `service => services`, `version => versions`, etc.
// if it happens that a user defined both `service` and `services` tags,
// user-defined `services` tag will override auto-generated one (since keys are iterated in a sorted order)
plural := fmt.Sprintf("%ss", key)
labels[prom_util.SanitizeLabelName(plural)] = MultiValue(values)
labels[sanitizeLabelName(plural)] = MultiValue(values)
}
// then, we turn name extensions into labels
for key, value := range dataplane.GetMeta().GetNameExtensions() {
labels[prom_util.SanitizeLabelName(key)] = value
labels[sanitizeLabelName(key)] = value
}

if dataplane.Spec.IsBuiltinGateway() {
Expand All @@ -73,3 +72,12 @@ func DataplaneAssignmentName(dataplane *core_mesh.DataplaneResource) string {
// unique name, e.g. REST API uri
return fmt.Sprintf("/meshes/%s/dataplanes/%s", dataplane.Meta.GetMesh(), dataplane.Meta.GetName())
}

var invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)

// SanitizeLabelName replaces anything that doesn't match
// client_label.LabelNameRE with an underscore.
// taken from: https://github.com/prometheus/prometheus/blob/d437f0bb6b53ec8594a43b871f92252980b13ddd/util/strutil/strconv.go#L40-L47
func sanitizeLabelName(name string) string {
return invalidLabelCharRE.ReplaceAllString(name, "_")
}

0 comments on commit 0a72af7

Please sign in to comment.