Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: obsy tests #578

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 15 additions & 12 deletions e2e/basic/observability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
prometheusPort = observability.DefaultOtelMetricsPort
prometheusImage = "prom/prometheus:latest"
prometheusConfig = "/etc/prometheus/prometheus.yml"
prometheusArgs = "--config.file=/etc/prometheus/prometheus.yml"
prometheusArgs = "--config.file=" + prometheusConfig

curlImage = "curlimages/curl:latest"
otlpPort = observability.DefaultOtelOtlpPort
Expand All @@ -23,10 +23,13 @@ const (
// TestObservabilityCollector is a test function that verifies the functionality of the otel collector setup
func (s *Suite) TestObservabilityCollector() {
const (
namePrefix = "observability"
targetStartCommand = "while true; do curl -X POST http://localhost:8888/v1/traces; sleep 5; done"
namePrefix = "observability"
scrapeInterval = "2s"
)
var (
targetStartCommand = fmt.Sprintf("while true; do curl -X POST http://localhost:%d/v1/traces; sleep 5; done", otlpPort)
ctx = context.Background()
)
ctx := context.Background()

// Setup Prometheus
prometheus, err := s.Knuu.NewInstance(namePrefix + "-prometheus")
Expand All @@ -44,12 +47,12 @@ func (s *Suite) TestObservabilityCollector() {
// Add Prometheus config file
prometheusConfigContent := fmt.Sprintf(`
global:
scrape_interval: '10s'
scrape_interval: '%s'

scrape_configs:
- job_name: 'otel-collector'
static_configs:
- targets: ['otel-collector:%d']
`, otlpPort)
- targets: ['otel-collector:%d']`, scrapeInterval, otlpPort)
s.Require().NoError(prometheus.Storage().AddFileBytes([]byte(prometheusConfigContent), prometheusConfig, "0:0"))

s.Require().NoError(prometheus.Build().SetArgs(prometheusArgs))
Expand All @@ -59,12 +62,12 @@ scrape_configs:
observabilitySidecar := observability.New()

s.Require().NoError(observabilitySidecar.SetOtelEndpoint(4318))
s.Require().NoError(observabilitySidecar.SetPrometheusEndpoint(otlpPort, fmt.Sprintf("knuu-%s", s.Knuu.Scope), "10s"))
s.Require().NoError(observabilitySidecar.SetPrometheusEndpoint(otlpPort, fmt.Sprintf("knuu-%s", s.Knuu.Scope), scrapeInterval))
s.Require().NoError(observabilitySidecar.SetJaegerEndpoint(14250, 6831, 14268))
s.Require().NoError(observabilitySidecar.SetOtlpExporter("prometheus:9090", "", ""))

// Create and start a target pod and configure it to use the obsySidecar to push metrics
target, err := s.Knuu.NewInstance(namePrefix + "target")
target, err := s.Knuu.NewInstance(namePrefix + "-target")
s.Require().NoError(err)

s.Require().NoError(target.Build().SetImage(ctx, curlImage))
Expand All @@ -73,15 +76,15 @@ scrape_configs:
s.Require().NoError(err)

s.Require().NoError(target.Sidecars().Add(ctx, observabilitySidecar))

s.Require().NoError(target.Build().Commit(ctx))
s.Require().NoError(target.Execution().Start(ctx))

// Wait for the target pod to push data to the otel collector
s.T().Log("Waiting one minute for the target pod to push data to the otel collector")
time.Sleep(1 * time.Minute)
s.T().Log("Waiting 20 seconds for the target pod to push data to the otel collector")
time.Sleep(20 * time.Second)

// Verify that data has been pushed to Prometheus

prometheusURL := fmt.Sprintf("%s/api/v1/query?query=up", prometheusEndpoint)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
12 changes: 12 additions & 0 deletions pkg/sidecars/observability/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ func (o *Obsy) prepareMetricsForServicePipeline() Metrics {
metrics.Exporters = append(metrics.Exporters, prometheusRemoteWriteExporterName)
}
metrics.Processors = []string{attributesProcessorName}

// if no metrics receiver or exporter is added, remove any metrics pipeline
if len(metrics.Receivers) == 0 || len(metrics.Exporters) == 0 {
metrics = Metrics{}
}

return metrics
}

Expand All @@ -377,6 +383,12 @@ func (o *Obsy) prepareTracesForServicePipeline() Traces {
traces.Exporters = append(traces.Exporters, jaegerExporterName)
}
traces.Processors = []string{attributesProcessorName}

// if no trace receiver or exporter is added, remove any trace pipeline
if len(traces.Receivers) == 0 || len(traces.Exporters) == 0 {
traces = Traces{}
}

return traces
}

Expand Down
Loading