Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OPENTELEMETRY_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.148.0
v0.149.0
2 changes: 1 addition & 1 deletion TARGETALLOCATOR_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.148.0
v0.149.0
2 changes: 1 addition & 1 deletion otelcollector/configuration-reader-builder/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ require (
github.com/onsi/gomega v1.36.2 // indirect
github.com/prometheus/client_golang v1.20.4 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ processors:
receivers:
prometheus:
api_server:
enabled: true
server_config:
endpoint: "localhost:9092"
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ processors:
receivers:
prometheus:
api_server:
enabled: true
server_config:
endpoint: "localhost:9092"
target_allocator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ processors:
receivers:
prometheus:
api_server:
enabled: true
server_config:
endpoint: "localhost:9092"
config:
Expand Down
178 changes: 89 additions & 89 deletions otelcollector/opentelemetry-collector-builder/go.mod

Large diffs are not rendered by default.

393 changes: 196 additions & 197 deletions otelcollector/opentelemetry-collector-builder/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion otelcollector/opentelemetry-collector-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
info := component.BuildInfo{
Command: "custom-collector-distro",
Description: "Custom OpenTelemetry Collector distribution",
Version: "0.148.0",
Version: "0.149.0",
}

set := otelcol.CollectorSettings{
Expand Down
211 changes: 107 additions & 104 deletions otelcollector/otel-allocator/go.mod

Large diffs are not rendered by default.

477 changes: 239 additions & 238 deletions otelcollector/otel-allocator/go.sum

Large diffs are not rendered by default.

186 changes: 186 additions & 0 deletions otelcollector/otel-allocator/internal/allocation/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,189 @@ func TestAllocationCollision(t *testing.T) {
}
})
}

func TestGetTargetsForCollectorAndJobNonExistent(t *testing.T) {
RunForAllStrategies(t, func(t *testing.T, allocator Allocator) {
cols := MakeNCollectors(3, 0)
targets := MakeNNewTargetsWithEmptyCollectors(6, 0)
allocator.SetCollectors(cols)
allocator.SetTargets(targets)

// Non-existent collector returns empty slice
result := allocator.GetTargetsForCollectorAndJob("non-existent-collector", "test-job-0")
assert.Empty(t, result)

// Non-existent job returns empty slice
result = allocator.GetTargetsForCollectorAndJob("collector-0", "non-existent-job")
assert.Empty(t, result)

// Both non-existent returns empty slice
result = allocator.GetTargetsForCollectorAndJob("no-collector", "no-job")
assert.Empty(t, result)
})
}

func TestSetEmptyTargets(t *testing.T) {
RunForAllStrategies(t, func(t *testing.T, allocator Allocator) {
cols := MakeNCollectors(3, 0)
allocator.SetCollectors(cols)

// Set some targets first
targets := MakeNNewTargetsWithEmptyCollectors(5, 0)
allocator.SetTargets(targets)
assert.Len(t, allocator.TargetItems(), 5)

// Set empty targets - should clear all
allocator.SetTargets([]*target.Item{})
assert.Empty(t, allocator.TargetItems())

// Collectors should still be present
assert.Len(t, allocator.Collectors(), 3)
})
}

func TestSetEmptyCollectors(t *testing.T) {
RunForAllStrategies(t, func(t *testing.T, allocator Allocator) {
cols := MakeNCollectors(3, 0)
allocator.SetCollectors(cols)
targets := MakeNNewTargetsWithEmptyCollectors(6, 0)
allocator.SetTargets(targets)

// All targets should be assigned
for _, item := range allocator.TargetItems() {
assert.NotEmpty(t, item.CollectorName)
}

// Remove all collectors
allocator.SetCollectors(map[string]*Collector{})
assert.Empty(t, allocator.Collectors())

// Targets should still exist but be unassigned
assert.Len(t, allocator.TargetItems(), 6)
for _, item := range allocator.TargetItems() {
assert.Empty(t, item.CollectorName)
}
})
}

func TestTargetUpdatePreservesCount(t *testing.T) {
RunForAllStrategies(t, func(t *testing.T, allocator Allocator) {
cols := MakeNCollectors(3, 0)
allocator.SetCollectors(cols)
targets := MakeNNewTargetsWithEmptyCollectors(10, 0)
allocator.SetTargets(targets)

// Update with same targets - counts should not change
allocator.SetTargets(targets)

totalAssigned := 0
for _, col := range allocator.Collectors() {
totalAssigned += col.NumTargets
}
assert.Equal(t, 10, totalAssigned)
})
}

func TestNewAllocatorInvalidStrategy(t *testing.T) {
_, err := New("invalid-strategy", logger)
assert.Error(t, err)
assert.Contains(t, err.Error(), "unregistered strategy")
}

func TestGetRegisteredAllocatorNames(t *testing.T) {
names := GetRegisteredAllocatorNames()
assert.GreaterOrEqual(t, len(names), 3)
assert.Contains(t, names, "consistent-hashing")
assert.Contains(t, names, "least-weighted")
assert.Contains(t, names, "per-node")
}

func TestNewCollector(t *testing.T) {
col := NewCollector("my-collector", "node-1")
assert.Equal(t, "my-collector", col.Name)
assert.Equal(t, "node-1", col.NodeName)
assert.Equal(t, 0, col.NumTargets)
assert.NotNil(t, col.TargetsPerJob)
assert.Equal(t, "my-collector", col.Hash())
assert.Equal(t, "my-collector", col.String())
}

func TestWithFilterOption(t *testing.T) {
RunForAllStrategies(t, func(t *testing.T, allocator Allocator) {
filterCalled := false
mockFilter := &mockFilterImpl{
applyFunc: func(_ []*target.Item) []*target.Item {
filterCalled = true
// drop all targets
return []*target.Item{}
},
}
allocator.SetFilter(mockFilter)

cols := MakeNCollectors(3, 0)
allocator.SetCollectors(cols)
targets := MakeNNewTargetsWithEmptyCollectors(5, 0)
allocator.SetTargets(targets)

assert.True(t, filterCalled)
assert.Empty(t, allocator.TargetItems())
})
}

type mockFilterImpl struct {
applyFunc func([]*target.Item) []*target.Item
}

func (m *mockFilterImpl) Apply(targets []*target.Item) []*target.Item {
return m.applyFunc(targets)
}

func TestRepeatedSetCollectorsIdempotent(t *testing.T) {
RunForAllStrategies(t, func(t *testing.T, allocator Allocator) {
cols := MakeNCollectors(3, 0)
targets := MakeNNewTargetsWithEmptyCollectors(9, 0)

allocator.SetCollectors(cols)
allocator.SetTargets(targets)

firstSnapshot := make(map[string]string)
for hash, item := range allocator.TargetItems() {
firstSnapshot[hash.String()] = item.CollectorName
}

// Set the same collectors again - assignments should not change
allocator.SetCollectors(cols)

for hash, item := range allocator.TargetItems() {
assert.Equal(t, firstSnapshot[hash.String()], item.CollectorName,
"target %s assignment changed after idempotent SetCollectors", hash)
}
})
}

func TestMultiJobAllocation(t *testing.T) {
RunForAllStrategies(t, func(t *testing.T, allocator Allocator) {
cols := MakeNCollectors(3, 0)
allocator.SetCollectors(cols)

job1Targets := MakeNTargetsForJob(3, "job-alpha", 0)
job2Targets := MakeNTargetsForJob(3, "job-beta", 100)
allTargets := append(job1Targets, job2Targets...)

allocator.SetTargets(allTargets)
assert.Len(t, allocator.TargetItems(), 6)

// All targets should be tracked (per-node may leave some unassigned
// since MakeNTargetsForJob doesn't add node labels)
assignedCount := 0
for _, item := range allocator.TargetItems() {
if item.CollectorName != "" {
assignedCount++
}
}
// For least-weighted and consistent-hashing, all should be assigned
// For per-node, none will be assigned due to missing node labels
assert.True(t, assignedCount == 0 || assignedCount == 6,
"expected all targets assigned or none, got %d/6", assignedCount)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package allocation

import (
"fmt"
"reflect"
"testing"

"github.com/stretchr/testify/assert"

"github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/internal/diff"
)

Expand Down Expand Up @@ -117,9 +118,8 @@ func TestCollectorDiff(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := diff.Maps(tt.args.current, tt.args.new); !reflect.DeepEqual(got, tt.want) {
t.Errorf("DiffMaps() = %v, want %v", got, tt.want)
}
got := diff.Maps(tt.args.current, tt.args.new)
assert.Equal(t, tt.want, got)
})
}
}
11 changes: 0 additions & 11 deletions otelcollector/otel-allocator/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ type PrometheusCRConfig struct {
Enabled bool `yaml:"enabled,omitempty"`
AllowNamespaces []string `yaml:"allow_namespaces,omitempty"`
DenyNamespaces []string `yaml:"deny_namespaces,omitempty"`
SecretsAccessNamespaces []string `yaml:"secrets_access_namespaces,omitempty"`
PodMonitorSelector *metav1.LabelSelector `yaml:"pod_monitor_selector,omitempty"`
PodMonitorNamespaceSelector *metav1.LabelSelector `yaml:"pod_monitor_namespace_selector,omitempty"`
ServiceMonitorSelector *metav1.LabelSelector `yaml:"service_monitor_selector,omitempty"`
Expand Down Expand Up @@ -442,16 +441,6 @@ func (c HTTPSServerConfig) NewTLSConfig(logger logr.Logger) (*tls.Config, *certw
return tlsConfig, certWatcher, nil
}

// GetSecretsAllowList converts SecretsAccessNamespaces into a map suitable for
// NewMetadataInformerFactory. An empty/nil slice results in an empty map (watch nothing).
func (c PrometheusCRConfig) GetSecretsAllowList() map[string]struct{} {
secretsAllowList := make(map[string]struct{})
for _, ns := range c.SecretsAccessNamespaces {
secretsAllowList[ns] = struct{}{}
}
return secretsAllowList
}

// GetAllowDenyLists returns the allow and deny lists as maps. If the allow list is empty, it defaults to all namespaces.
// If the deny list is empty, it defaults to an empty map.
func (c PrometheusCRConfig) GetAllowDenyLists() (allowList, denyList map[string]struct{}) {
Expand Down
12 changes: 12 additions & 0 deletions otelcollector/otel-allocator/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestLoadFromFile(t *testing.T) {
MetricNameValidationScheme: model.UTF8Validation,
MetricNameEscapingScheme: model.AllowUTF8,
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
},
Runtime: promconfig.DefaultRuntimeConfig,
OTLPConfig: promconfig.DefaultOTLPConfig,
Expand All @@ -91,6 +92,7 @@ func TestLoadFromFile(t *testing.T) {
AlwaysScrapeClassicHistograms: ptr.Bool(false),
ConvertClassicHistogramsToNHCB: ptr.Bool(false),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
MetricsPath: "/metrics",
Scheme: "http",
HTTPClientConfig: commonconfig.HTTPClientConfig{
Expand Down Expand Up @@ -164,6 +166,7 @@ func TestLoadFromFile(t *testing.T) {
EvaluationInterval: model.Duration(60 * time.Second),
MetricNameValidationScheme: model.UTF8Validation,
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
},
Runtime: promconfig.DefaultRuntimeConfig,
OTLPConfig: promconfig.DefaultOTLPConfig,
Expand All @@ -180,6 +183,7 @@ func TestLoadFromFile(t *testing.T) {
AlwaysScrapeClassicHistograms: ptr.Bool(false),
ConvertClassicHistogramsToNHCB: ptr.Bool(false),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
MetricsPath: "/metrics",
Scheme: "http",
HTTPClientConfig: commonconfig.HTTPClientConfig{
Expand Down Expand Up @@ -265,6 +269,7 @@ func TestLoadFromFile(t *testing.T) {
MetricNameValidationScheme: model.UTF8Validation,
MetricNameEscapingScheme: model.AllowUTF8,
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
},
Runtime: promconfig.DefaultRuntimeConfig,
OTLPConfig: promconfig.DefaultOTLPConfig,
Expand All @@ -281,6 +286,7 @@ func TestLoadFromFile(t *testing.T) {
AlwaysScrapeClassicHistograms: ptr.Bool(false),
ConvertClassicHistogramsToNHCB: ptr.Bool(false),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
MetricsPath: "/metrics",
Scheme: "http",
HTTPClientConfig: commonconfig.HTTPClientConfig{
Expand Down Expand Up @@ -352,6 +358,7 @@ func TestLoadFromFile(t *testing.T) {
ScrapeInterval: model.Duration(60 * time.Second),
ScrapeTimeout: model.Duration(10 * time.Second),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
EvaluationInterval: model.Duration(60 * time.Second),
MetricNameValidationScheme: model.UTF8Validation,
MetricNameEscapingScheme: model.AllowUTF8,
Expand All @@ -371,6 +378,7 @@ func TestLoadFromFile(t *testing.T) {
AlwaysScrapeClassicHistograms: ptr.Bool(false),
ConvertClassicHistogramsToNHCB: ptr.Bool(false),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
MetricsPath: "/metrics",
Scheme: "http",
HTTPClientConfig: commonconfig.HTTPClientConfig{
Expand Down Expand Up @@ -466,6 +474,7 @@ func TestLoadFromFile(t *testing.T) {
ScrapeInterval: model.Duration(60 * time.Second),
ScrapeTimeout: model.Duration(10 * time.Second),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
EvaluationInterval: model.Duration(60 * time.Second),
MetricNameValidationScheme: model.UTF8Validation,
MetricNameEscapingScheme: model.AllowUTF8,
Expand All @@ -485,6 +494,7 @@ func TestLoadFromFile(t *testing.T) {
AlwaysScrapeClassicHistograms: ptr.Bool(false),
ConvertClassicHistogramsToNHCB: ptr.Bool(false),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
MetricsPath: "/metrics",
Scheme: "http",
HTTPClientConfig: commonconfig.HTTPClientConfig{
Expand Down Expand Up @@ -579,6 +589,7 @@ func TestLoadFromFile(t *testing.T) {
GlobalConfig: promconfig.GlobalConfig{
ScrapeInterval: model.Duration(60 * time.Second),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
ScrapeTimeout: model.Duration(10 * time.Second),
EvaluationInterval: model.Duration(60 * time.Second),
MetricNameValidationScheme: model.UTF8Validation,
Expand All @@ -599,6 +610,7 @@ func TestLoadFromFile(t *testing.T) {
AlwaysScrapeClassicHistograms: ptr.Bool(false),
ConvertClassicHistogramsToNHCB: ptr.Bool(false),
ScrapeNativeHistograms: ptr.Bool(false),
ExtraScrapeMetrics: ptr.Bool(false),
MetricsPath: "/metrics",
Scheme: "http",
HTTPClientConfig: commonconfig.HTTPClientConfig{
Expand Down
Loading
Loading