Skip to content

Commit 0b0ff4e

Browse files
committed
add __meta_inventor_sd_module, bump redis to 7.2
1 parent d27de8c commit 0b0ff4e

File tree

11 files changed

+45
-19
lines changed

11 files changed

+45
-19
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ scrape_configs:
6161
* `API_TOKEN`: API token for manipulating targets
6262
* `SD_TOKEN`: Options token for Prometheus HTTP SD, is empty by default and not validating (header `x-sd-token`)
6363

64+
65+
## Custom discovered labels
66+
67+
* `__meta_inventor_sd_module`: contains element of `modules: []`, useful fo relabeling to add `__param_module`
68+
69+
6470
## API Methods
6571

6672
* **GET /discover**

charts/inventor/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v2
22
name: inventor
3-
version: 0.0.3
3+
version: 0.1.0
44
sources:
55
- https://github.com/shcherbak/inventor

charts/inventor/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ secret:
1313
SD_TOKEN: 'ChangeMe'
1414

1515
main:
16-
image: "jushcherbak/inventor:0.0.3"
16+
image: "jushcherbak/inventor:0.1.1"
1717
pullPolicy: "IfNotPresent"
1818

1919
redis:
2020
enabled: true
21-
image: "redis:6.2.14"
21+
image: "redis:7.2.11"
2222
pullPolicy: "IfNotPresent"
2323

2424
service:

docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21.11-bullseye AS builder
1+
FROM golang:1.23.12-bookworm AS builder
22
ARG BUILD_VERSION='1.2.3'
33
ENV LISTEN_PORT=9101
44
WORKDIR /opt/inventor/
@@ -8,7 +8,7 @@ COPY src ./src
88
RUN go mod download
99
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${BUILD_VERSION}" -a -installsuffix cgo -o inventor src/main.go
1010

11-
FROM debian:bullseye
11+
FROM debian:bookworm
1212
WORKDIR /opt/inventor/
1313
RUN apt-get update \
1414
&& apt-get install -y --no-install-recommends \

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module inventor
22

3-
go 1.21
3+
go 1.23
44

55
require (
66
github.com/go-redis/redis/v9 v9.0.0-beta.2
@@ -14,7 +14,6 @@ require (
1414
github.com/cespare/xxhash/v2 v2.1.2 // indirect
1515
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
1616
github.com/golang/protobuf v1.5.2 // indirect
17-
github.com/gorilla/mux v1.8.1
1817
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
1918
github.com/prometheus/client_model v0.2.0 // indirect
2019
github.com/prometheus/common v0.37.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
132132
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
133133
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
134134
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
135-
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
136-
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
137135
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
138136
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
139137
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

src/handler/middleware.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"io"
7+
"maps"
78
"net/http"
89
"strings"
910
"sync"
@@ -87,7 +88,17 @@ func (s *SDTargetsMiddleware) handleGetAll(w http.ResponseWriter, r *http.Reques
8788
res := []HttpSD{}
8889
targets, _ := s.SDTargets.Scan(s.Context, s.Client)
8990
for _, target := range targets.Items {
90-
res = append(res, HttpSD{target.Targets, target.Labels})
91+
if len(target.Modules) > 0 {
92+
for _, module := range target.Modules {
93+
additionalLabels := map[string]string{
94+
"__meta_inventor_sd_module": module,
95+
}
96+
maps.Copy(additionalLabels, target.Labels)
97+
res = append(res, HttpSD{target.Targets, additionalLabels})
98+
}
99+
} else {
100+
res = append(res, HttpSD{target.Targets, target.Labels})
101+
}
91102
}
92103
err := json.NewEncoder(w).Encode(res)
93104
if err != nil {
@@ -107,7 +118,17 @@ func (s *SDTargetsMiddleware) handleGetByGroupName(w http.ResponseWriter, r *htt
107118
targets, _ := s.SDTargets.Scan(s.Context, s.Client)
108119
for _, target := range targets.Items {
109120
if target.Group == grp {
110-
res = append(res, HttpSD{target.Targets, target.Labels})
121+
if len(target.Modules) > 0 {
122+
for _, module := range target.Modules {
123+
additionalLabels := map[string]string{
124+
"__meta_inventor_sd_module": module,
125+
}
126+
maps.Copy(additionalLabels, target.Labels)
127+
res = append(res, HttpSD{target.Targets, additionalLabels})
128+
}
129+
} else {
130+
res = append(res, HttpSD{target.Targets, target.Labels})
131+
}
111132
}
112133
}
113134
err := json.NewEncoder(w).Encode(res)

src/handler/targets.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type StaticConfig struct {
1818
Targets []string `json:"targets"`
1919
Labels map[string]string `json:"labels"`
2020
Group string `json:"target_group"`
21+
Modules []string `json:"modules,omitempty"`
2122
UpdatedAt string `json:"updated_at"` // unix timestamp
2223
}
2324

tests/end-to-end/example-001.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"static_config": {
33
"targets": ["10.0.10.2:9100", "10.0.10.3:9100", "10.0.10.4:9100", "10.0.10.5:9100"],
44
"labels": {
5-
"__meta_datacenter": "dc-01",
6-
"__meta_prometheus_job": "node"
5+
"__meta_datacenter": "dc-01",
6+
"__meta_prometheus_job": "smart"
77
},
8-
"target_group": "node-exporter-group"
8+
"target_group": "smartctl-exporter-group"
99
}
1010
}

tests/end-to-end/example-002.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"static_config": {
33
"targets": ["10.0.40.2:9093", "10.0.40.3:9093"],
4+
"modules": ["ipmi_exporter"],
45
"labels": {
5-
"__meta_datacenter": "dc-02",
6-
"__meta_prometheus_job": "alertmanager"
6+
"__meta_datacenter": "dc-02",
7+
"__meta_prometheus_job": "ipmi"
78
},
8-
"target_group": "alertmanager-exporter-group"
9+
"target_group": "ipmi-exporter-group"
910
}
1011
}

0 commit comments

Comments
 (0)