Skip to content

Commit

Permalink
Fix target allocator readiness check
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Apr 29, 2024
1 parent a1b581e commit 661d079
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix_load-initial-servicemonitors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix target allocator readiness check

# One or more tracking issues related to the change
issues: [2903]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 1 addition & 1 deletion cmd/otel-allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func main() {
runGroup.Add(
func() error {
// Initial loading of the config file's scrape config
if cfg.PromConfig != nil {
if cfg.PromConfig != nil && len(cfg.PromConfig.ScrapeConfigs) > 0 {
err = targetDiscoverer.ApplyConfig(allocatorWatcher.EventSourceConfigMap, cfg.PromConfig.ScrapeConfigs)
if err != nil {
setupLog.Error(err, "Unable to apply initial configuration")
Expand Down
2 changes: 1 addition & 1 deletion internal/manifests/targetallocator/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
taConfig["collector_selector"] = taSpec.CollectorSelector

// Add scrape configs if present
if instance.Spec.ScrapeConfigs != nil {
if instance.Spec.ScrapeConfigs != nil && len(instance.Spec.ScrapeConfigs) > 0 {
taConfig["config"] = map[string]interface{}{
"scrape_configs": instance.Spec.ScrapeConfigs,
}
Expand Down
38 changes: 38 additions & 0 deletions internal/manifests/targetallocator/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/open-telemetry/opentelemetry-operator/internal/config"
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
)
Expand Down Expand Up @@ -78,6 +79,43 @@ prometheus_cr:
assert.Equal(t, expectedLabels, actual.Labels)
assert.Equal(t, expectedData[targetAllocatorFilename], actual.Data[targetAllocatorFilename])

})
t.Run("should return target allocator config map without scrape configs", func(t *testing.T) {
expectedLabels["app.kubernetes.io/component"] = "opentelemetry-targetallocator"
expectedLabels["app.kubernetes.io/name"] = "my-instance-targetallocator"

expectedData := map[string]string{
targetAllocatorFilename: `allocation_strategy: consistent-hashing
collector_selector:
matchlabels:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/instance: default.my-instance
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
matchexpressions: []
filter_strategy: relabel-config
prometheus_cr:
pod_monitor_selector: null
service_monitor_selector: null
`,
}
collector := collectorInstance()
targetAllocator := targetAllocatorInstance()
targetAllocator.Spec.ScrapeConfigs = []v1beta1.AnyConfig{}
cfg := config.New()
params := manifests.Params{
OtelCol: collector,
TargetAllocator: targetAllocator,
Config: cfg,
Log: logr.Discard(),
}
actual, err := ConfigMap(params)
require.NoError(t, err)

assert.Equal(t, "my-instance-targetallocator", actual.Name)
assert.Equal(t, expectedLabels, actual.Labels)
assert.Equal(t, expectedData[targetAllocatorFilename], actual.Data[targetAllocatorFilename])

})
t.Run("should return expected target allocator config map with label selectors", func(t *testing.T) {
expectedLabels["app.kubernetes.io/component"] = "opentelemetry-targetallocator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,5 @@ spec:
enabled: true
prometheusCR:
enabled: true
scrapeInterval: 1s
scrapeInterval: 1s
serviceAccount: ta
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: prometheus-cr
spec:
endpoints:
- port: monitoring
selector:
matchLabels:
app.kubernetes.io/managed-by: opentelemetry-operator
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: prometheus-cr
spec:
endpoints:
- port: monitoring
selector:
matchLabels:
app.kubernetes.io/managed-by: opentelemetry-operator
---
apiVersion: batch/v1
kind: Job
metadata:
Expand Down

0 comments on commit 661d079

Please sign in to comment.