Skip to content

Commit 41da859

Browse files
author
Israel Blancas
authored
Merge branch 'main' into service-extension
2 parents e27c2a1 + dfa7dcb commit 41da859

File tree

30 files changed

+349
-201
lines changed

30 files changed

+349
-201
lines changed

.chloggen/3446.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: 'bug_fix'
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Operator pod crashed if the Service Monitor for the operator metrics was created before by another operator pod.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3446]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
Operator fails when the pod is restarted and the Service Monitor for operator metrics was already created by another operator pod.
18+
To fix this, the operator now sets the owner reference on the Service Monitor to itself and checks if the Service Monitor already exists.
19+

.github/workflows/continuous-integration.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ jobs:
6262
with:
6363
path: |
6464
/home/runner/.cache/golangci-lint
65-
/home/runner/go/pkg/mod
66-
./bin
6765
key: golangcilint-${{ hashFiles('**/go.sum') }}
6866
restore-keys: |
6967
golangcilint-

autoinstrumentation/java/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.9.0
1+
2.10.0

cmd/otel-allocator/allocation/allocator_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package allocation
1717
import (
1818
"testing"
1919

20-
"github.com/prometheus/common/model"
20+
"github.com/prometheus/prometheus/model/labels"
2121
"github.com/stretchr/testify/assert"
2222

2323
"github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/target"
@@ -176,11 +176,11 @@ func TestAllocationCollision(t *testing.T) {
176176

177177
cols := MakeNCollectors(3, 0)
178178
allocator.SetCollectors(cols)
179-
firstLabels := model.LabelSet{
180-
"test": "test1",
179+
firstLabels := labels.Labels{
180+
{Name: "test", Value: "test1"},
181181
}
182-
secondLabels := model.LabelSet{
183-
"test": "test2",
182+
secondLabels := labels.Labels{
183+
{Name: "test", Value: "test2"},
184184
}
185185
firstTarget := target.NewItem("sample-name", "0.0.0.0:8000", firstLabels, "")
186186
secondTarget := target.NewItem("sample-name", "0.0.0.0:8000", secondLabels, "")

cmd/otel-allocator/allocation/consistent_hashing.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package allocation
1616

1717
import (
1818
"fmt"
19-
"strings"
2019

2120
"github.com/buraksezer/consistent"
2221
"github.com/cespare/xxhash/v2"
@@ -59,7 +58,7 @@ func (s *consistentHashingStrategy) GetName() string {
5958
}
6059

6160
func (s *consistentHashingStrategy) GetCollectorForTarget(collectors map[string]*Collector, item *target.Item) (*Collector, error) {
62-
hashKey := strings.Join(item.TargetURL, "")
61+
hashKey := item.TargetURL
6362
member := s.consistentHasher.LocateKey([]byte(hashKey))
6463
collectorName := member.String()
6564
collector, ok := collectors[collectorName]

cmd/otel-allocator/allocation/per_node_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package allocation
1717
import (
1818
"testing"
1919

20-
"github.com/prometheus/common/model"
20+
"github.com/prometheus/prometheus/model/labels"
2121
"github.com/stretchr/testify/assert"
2222
logf "sigs.k8s.io/controller-runtime/pkg/log"
2323

@@ -33,23 +33,23 @@ func TestAllocationPerNode(t *testing.T) {
3333

3434
cols := MakeNCollectors(4, 0)
3535
s.SetCollectors(cols)
36-
firstLabels := model.LabelSet{
37-
"test": "test1",
38-
"__meta_kubernetes_pod_node_name": "node-0",
36+
firstLabels := labels.Labels{
37+
{Name: "test", Value: "test1"},
38+
{Name: "__meta_kubernetes_pod_node_name", Value: "node-0"},
3939
}
40-
secondLabels := model.LabelSet{
41-
"test": "test2",
42-
"__meta_kubernetes_node_name": "node-1",
40+
secondLabels := labels.Labels{
41+
{Name: "test", Value: "test2"},
42+
{Name: "__meta_kubernetes_node_name", Value: "node-1"},
4343
}
4444
// no label, should be skipped
45-
thirdLabels := model.LabelSet{
46-
"test": "test3",
45+
thirdLabels := labels.Labels{
46+
{Name: "test", Value: "test3"},
4747
}
4848
// endpointslice target kind and name
49-
fourthLabels := model.LabelSet{
50-
"test": "test4",
51-
"__meta_kubernetes_endpointslice_address_target_kind": "Node",
52-
"__meta_kubernetes_endpointslice_address_target_name": "node-3",
49+
fourthLabels := labels.Labels{
50+
{Name: "test", Value: "test4"},
51+
{Name: "__meta_kubernetes_endpointslice_address_target_kind", Value: "Node"},
52+
{Name: "__meta_kubernetes_endpointslice_address_target_name", Value: "node-3"},
5353
}
5454

5555
firstTarget := target.NewItem("sample-name", "0.0.0.0:8000", firstLabels, "")

cmd/otel-allocator/allocation/testutils.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"strconv"
2222
"testing"
2323

24-
"github.com/prometheus/common/model"
24+
"github.com/prometheus/prometheus/model/labels"
2525
"github.com/stretchr/testify/require"
2626
logf "sigs.k8s.io/controller-runtime/pkg/log"
2727

@@ -39,9 +39,9 @@ func MakeNNewTargets(n int, numCollectors int, startingIndex int) map[string]*ta
3939
toReturn := map[string]*target.Item{}
4040
for i := startingIndex; i < n+startingIndex; i++ {
4141
collector := fmt.Sprintf("collector-%d", colIndex(i, numCollectors))
42-
label := model.LabelSet{
43-
"i": model.LabelValue(strconv.Itoa(i)),
44-
"total": model.LabelValue(strconv.Itoa(n + startingIndex)),
42+
label := labels.Labels{
43+
{Name: "i", Value: strconv.Itoa(i)},
44+
{Name: "total", Value: strconv.Itoa(n + startingIndex)},
4545
}
4646
newTarget := target.NewItem(fmt.Sprintf("test-job-%d", i), fmt.Sprintf("test-url-%d", i), label, collector)
4747
toReturn[newTarget.Hash()] = newTarget
@@ -65,10 +65,10 @@ func MakeNCollectors(n int, startingIndex int) map[string]*Collector {
6565
func MakeNNewTargetsWithEmptyCollectors(n int, startingIndex int) map[string]*target.Item {
6666
toReturn := map[string]*target.Item{}
6767
for i := startingIndex; i < n+startingIndex; i++ {
68-
label := model.LabelSet{
69-
"i": model.LabelValue(strconv.Itoa(i)),
70-
"total": model.LabelValue(strconv.Itoa(n + startingIndex)),
71-
"__meta_kubernetes_pod_node_name": model.LabelValue("node-0"),
68+
label := labels.Labels{
69+
{Name: "i", Value: strconv.Itoa(i)},
70+
{Name: "total", Value: strconv.Itoa(n + startingIndex)},
71+
{Name: "__meta_kubernetes_pod_node_name", Value: "node-0"},
7272
}
7373
newTarget := target.NewItem(fmt.Sprintf("test-job-%d", i), fmt.Sprintf("test-url-%d", i), label, "")
7474
toReturn[newTarget.Hash()] = newTarget

cmd/otel-allocator/benchmark_test.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"context"
1919
"fmt"
2020
"os"
21+
"strconv"
22+
"strings"
2123
"testing"
2224

2325
gokitlog "github.com/go-kit/log"
@@ -26,7 +28,9 @@ import (
2628
"github.com/prometheus/common/model"
2729
"github.com/prometheus/prometheus/discovery"
2830
"github.com/prometheus/prometheus/discovery/targetgroup"
31+
"github.com/prometheus/prometheus/model/labels"
2932
"github.com/prometheus/prometheus/model/relabel"
33+
"github.com/stretchr/testify/require"
3034
ctrl "sigs.k8s.io/controller-runtime"
3135
"sigs.k8s.io/controller-runtime/pkg/log"
3236

@@ -45,13 +49,14 @@ func BenchmarkProcessTargets(b *testing.B) {
4549
targetsPerGroup := 5
4650
groupsPerJob := 20
4751
tsets := prepareBenchmarkData(numTargets, targetsPerGroup, groupsPerJob)
52+
labelsBuilder := labels.NewBuilder(labels.EmptyLabels())
4853

4954
b.ResetTimer()
5055
for _, strategy := range allocation.GetRegisteredAllocatorNames() {
5156
b.Run(strategy, func(b *testing.B) {
5257
targetDiscoverer, allocator := createTestDiscoverer(strategy, map[string][]*relabel.Config{})
5358
for i := 0; i < b.N; i++ {
54-
targetDiscoverer.ProcessTargets(tsets, allocator.SetTargets)
59+
targetDiscoverer.ProcessTargets(labelsBuilder, tsets, allocator.SetTargets)
5560
}
5661
})
5762
}
@@ -64,12 +69,24 @@ func BenchmarkProcessTargetsWithRelabelConfig(b *testing.B) {
6469
targetsPerGroup := 5
6570
groupsPerJob := 20
6671
tsets := prepareBenchmarkData(numTargets, targetsPerGroup, groupsPerJob)
72+
labelsBuilder := labels.NewBuilder(labels.EmptyLabels())
6773
prehookConfig := make(map[string][]*relabel.Config, len(tsets))
6874
for jobName := range tsets {
75+
// keep all targets in half the jobs, drop the rest
76+
jobNrStr := strings.Split(jobName, "-")[1]
77+
jobNr, err := strconv.Atoi(jobNrStr)
78+
require.NoError(b, err)
79+
var action relabel.Action
80+
if jobNr%2 == 0 {
81+
action = "keep"
82+
} else {
83+
action = "drop"
84+
}
6985
prehookConfig[jobName] = []*relabel.Config{
7086
{
71-
Action: "keep",
72-
Regex: relabel.MustNewRegexp(".*"),
87+
Action: action,
88+
Regex: relabel.MustNewRegexp(".*"),
89+
SourceLabels: model.LabelNames{"__address__"},
7390
},
7491
}
7592
}
@@ -79,7 +96,7 @@ func BenchmarkProcessTargetsWithRelabelConfig(b *testing.B) {
7996
b.Run(strategy, func(b *testing.B) {
8097
targetDiscoverer, allocator := createTestDiscoverer(strategy, prehookConfig)
8198
for i := 0; i < b.N; i++ {
82-
targetDiscoverer.ProcessTargets(tsets, allocator.SetTargets)
99+
targetDiscoverer.ProcessTargets(labelsBuilder, tsets, allocator.SetTargets)
83100
}
84101
})
85102
}

cmd/otel-allocator/prehook/relabel.go

+5-24
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ package prehook
1616

1717
import (
1818
"github.com/go-logr/logr"
19-
"github.com/prometheus/common/model"
20-
"github.com/prometheus/prometheus/model/labels"
2119
"github.com/prometheus/prometheus/model/relabel"
2220

2321
"github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/target"
@@ -35,18 +33,6 @@ func NewRelabelConfigTargetFilter(log logr.Logger) Hook {
3533
}
3634
}
3735

38-
// helper function converts from model.LabelSet to []labels.Label.
39-
func convertLabelToPromLabelSet(lbls model.LabelSet) []labels.Label {
40-
newLabels := make([]labels.Label, len(lbls))
41-
index := 0
42-
for k, v := range lbls {
43-
newLabels[index].Name = string(k)
44-
newLabels[index].Value = string(v)
45-
index++
46-
}
47-
return newLabels
48-
}
49-
5036
func (tf *RelabelConfigTargetFilter) Apply(targets map[string]*target.Item) map[string]*target.Item {
5137
numTargets := len(targets)
5238

@@ -57,20 +43,15 @@ func (tf *RelabelConfigTargetFilter) Apply(targets map[string]*target.Item) map[
5743

5844
// Note: jobNameKey != tItem.JobName (jobNameKey is hashed)
5945
for jobNameKey, tItem := range targets {
60-
keepTarget := true
61-
lset := convertLabelToPromLabelSet(tItem.Labels)
46+
var keepTarget bool
47+
lset := tItem.Labels
6248
for _, cfg := range tf.relabelCfg[tItem.JobName] {
63-
if newLset, keep := relabel.Process(lset, cfg); !keep {
64-
keepTarget = false
49+
lset, keepTarget = relabel.Process(lset, cfg)
50+
if !keepTarget {
51+
delete(targets, jobNameKey)
6552
break // inner loop
66-
} else {
67-
lset = newLset
6853
}
6954
}
70-
71-
if !keepTarget {
72-
delete(targets, jobNameKey)
73-
}
7455
}
7556

7657
tf.log.V(2).Info("Filtering complete", "seen", numTargets, "kept", len(targets))

cmd/otel-allocator/prehook/relabel_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/prometheus/common/model"
25+
"github.com/prometheus/prometheus/model/labels"
2526
"github.com/prometheus/prometheus/model/relabel"
2627
"github.com/stretchr/testify/assert"
2728
logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -184,10 +185,10 @@ func makeNNewTargets(rCfgs []relabelConfigObj, n int, numCollectors int, startin
184185
relabelConfig := make(map[string][]*relabel.Config)
185186
for i := startingIndex; i < n+startingIndex; i++ {
186187
collector := fmt.Sprintf("collector-%d", colIndex(i, numCollectors))
187-
label := model.LabelSet{
188-
"collector": model.LabelValue(collector),
189-
"i": model.LabelValue(strconv.Itoa(i)),
190-
"total": model.LabelValue(strconv.Itoa(n + startingIndex)),
188+
label := labels.Labels{
189+
{Name: "collector", Value: collector},
190+
{Name: "i", Value: strconv.Itoa(i)},
191+
{Name: "total", Value: strconv.Itoa(n + startingIndex)},
191192
}
192193
jobName := fmt.Sprintf("test-job-%d", i)
193194
newTarget := target.NewItem(jobName, "test-url", label, collector)

cmd/otel-allocator/server/bench_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/gin-gonic/gin"
2525
"github.com/prometheus/common/model"
2626
promconfig "github.com/prometheus/prometheus/config"
27+
"github.com/prometheus/prometheus/model/labels"
2728
"github.com/stretchr/testify/assert"
2829

2930
"github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/allocation"
@@ -249,12 +250,13 @@ func makeNCollectorJSON(random rand.Rand, numCollectors, numItems int) map[strin
249250
}
250251

251252
func makeNTargetItems(random rand.Rand, numItems, numLabels int) []*target.Item {
253+
builder := labels.NewBuilder(labels.EmptyLabels())
252254
items := make([]*target.Item, 0, numItems)
253255
for i := 0; i < numItems; i++ {
254256
items = append(items, target.NewItem(
255257
randSeq(random, 80),
256258
randSeq(random, 150),
257-
makeNNewLabels(random, numLabels),
259+
makeNNewLabels(builder, random, numLabels),
258260
randSeq(random, 30),
259261
))
260262
}
@@ -270,10 +272,10 @@ func makeNTargetJSON(random rand.Rand, numItems, numLabels int) []*targetJSON {
270272
return targets
271273
}
272274

273-
func makeNNewLabels(random rand.Rand, n int) model.LabelSet {
274-
labels := make(map[model.LabelName]model.LabelValue, n)
275+
func makeNNewLabels(builder *labels.Builder, random rand.Rand, n int) labels.Labels {
276+
builder.Reset(labels.EmptyLabels())
275277
for i := 0; i < n; i++ {
276-
labels[model.LabelName(randSeq(random, 20))] = model.LabelValue(randSeq(random, 20))
278+
builder.Set(randSeq(random, 20), randSeq(random, 20))
277279
}
278-
return labels
280+
return builder.Labels()
279281
}

cmd/otel-allocator/server/server.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"github.com/prometheus/client_golang/prometheus/promauto"
3535
"github.com/prometheus/client_golang/prometheus/promhttp"
3636
promcommconfig "github.com/prometheus/common/config"
37-
"github.com/prometheus/common/model"
3837
promconfig "github.com/prometheus/prometheus/config"
38+
"github.com/prometheus/prometheus/model/labels"
3939
"gopkg.in/yaml.v2"
4040

4141
"github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/allocation"
@@ -67,8 +67,8 @@ type linkJSON struct {
6767
}
6868

6969
type targetJSON struct {
70-
TargetURL []string `json:"targets"`
71-
Labels model.LabelSet `json:"labels"`
70+
TargetURL []string `json:"targets"`
71+
Labels labels.Labels `json:"labels"`
7272
}
7373

7474
type Server struct {
@@ -374,7 +374,7 @@ func registerPprof(g *gin.RouterGroup) {
374374

375375
func targetJsonFromTargetItem(item *target.Item) *targetJSON {
376376
return &targetJSON{
377-
TargetURL: item.TargetURL,
377+
TargetURL: []string{item.TargetURL},
378378
Labels: item.Labels,
379379
}
380380
}

0 commit comments

Comments
 (0)