Skip to content

Commit

Permalink
ref: add simple func to get map keys, drop lo dep
Browse files Browse the repository at this point in the history
Stop being lazy and just implement a stupid simple key getter func.
Allows for dropping `lo`, which was pulled in entirely as a convenience
package.
  • Loading branch information
tjhop committed Nov 4, 2024
1 parent e3e6c5f commit 1e8aee3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/common v0.59.1
github.com/prometheus/exporter-toolkit v0.13.0
github.com/samber/lo v1.47.0
github.com/stretchr/testify v1.9.0
gopkg.in/ns1/ns1-go.v2 v2.12.1
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
17 changes: 14 additions & 3 deletions pkg/servicediscovery/sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"time"

promModel "github.com/prometheus/common/model"
"github.com/samber/lo"
api "gopkg.in/ns1/ns1-go.v2/rest"
"gopkg.in/ns1/ns1-go.v2/rest/model/account"
"gopkg.in/ns1/ns1-go.v2/rest/model/data"
Expand Down Expand Up @@ -103,7 +102,7 @@ func metaAsPrometheusMetaLabel(meta *data.Meta, innerDelim, outerDelim string) s

fmt.Fprintf(&builder, "meta[%s", innerDelim)

metaMapKeys := lo.Keys(metaMap)
metaMapKeys := getMapKeys(metaMap)
sort.Strings(metaMapKeys)
for _, key := range metaMapKeys {
fmt.Fprintf(&builder, "%s=%v%s", key, metaMap[key], innerDelim)
Expand Down Expand Up @@ -152,7 +151,7 @@ func recordFiltersAsPrometheusMetaLabel(filters []*filter.Filter) string {
}

builder.WriteString("config[|")
configKeys := lo.Keys(filter.Config)
configKeys := getMapKeys(filter.Config)
sort.Strings(configKeys)
for _, key := range configKeys {
fmt.Fprintf(&builder, "%s=%v|", key, filter.Config[key])
Expand Down Expand Up @@ -345,3 +344,15 @@ func (w *Worker) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
w.logger.Error("Failed to write full HTTP response", "err", err, "bytes", bytesWritten)
}
}

func getMapKeys(m map[string]any) []string {
keys := make([]string, len(m))

i := 0
for key := range m {
keys[i] = key
i++
}

return keys
}

0 comments on commit 1e8aee3

Please sign in to comment.