From c2f300bc47423689aea8fb6537a2ccc7875852ca Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:58:30 -0400 Subject: [PATCH] Fix PR conflict (#1018) --- pkg/components/beyla.go | 15 ++------------- pkg/components/beyla_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/components/beyla.go b/pkg/components/beyla.go index a3d8faf89..9350a434a 100644 --- a/pkg/components/beyla.go +++ b/pkg/components/beyla.go @@ -4,14 +4,12 @@ import ( "context" "fmt" "log/slog" - "slices" "sync" "github.com/grafana/beyla/pkg/beyla" "github.com/grafana/beyla/pkg/internal/appolly" "github.com/grafana/beyla/pkg/internal/connector" "github.com/grafana/beyla/pkg/internal/export/attributes" - "github.com/grafana/beyla/pkg/internal/export/otel" "github.com/grafana/beyla/pkg/internal/imetrics" "github.com/grafana/beyla/pkg/internal/kube" "github.com/grafana/beyla/pkg/internal/netolly/agent" @@ -94,17 +92,8 @@ func setupNetO11y(ctx context.Context, ctxInfo *global.ContextInfo, cfg *beyla.C } func mustSkip(cfg *beyla.Config) string { - otelEnabled := cfg.Metrics.Enabled() - otelFeature := slices.Contains(cfg.Metrics.Features, otel.FeatureNetwork) - promEnabled := cfg.Prometheus.Enabled() - promFeature := slices.Contains(cfg.Prometheus.Features, otel.FeatureNetwork) - if otelEnabled && !otelFeature && !promEnabled { - return "network not present in BEYLA_OTEL_METRICS_FEATURES" - } - if promEnabled && !promFeature && !otelEnabled { - return "network not present in BEYLA_PROMETHEUS_FEATURES" - } - if promEnabled && !promFeature && otelEnabled && !otelFeature { + enabled := cfg.Enabled(beyla.FeatureNetO11y) + if !enabled { return "network not present neither in BEYLA_PROMETHEUS_FEATURES nor BEYLA_OTEL_METRICS_FEATURES" } return "" diff --git a/pkg/components/beyla_test.go b/pkg/components/beyla_test.go index 351be37f3..65f21898a 100644 --- a/pkg/components/beyla_test.go +++ b/pkg/components/beyla_test.go @@ -3,9 +3,12 @@ package components import ( + "bytes" "context" + "os" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/grafana/beyla/pkg/beyla" @@ -71,3 +74,10 @@ func TestRun_DontPanic(t *testing.T) { }) } } + +func Test_NetworkEnabled(t *testing.T) { + require.NoError(t, os.Setenv("BEYLA_NETWORK_METRICS", "true")) + cfg, err := beyla.LoadConfig(bytes.NewReader(nil)) + assert.NoError(t, err) + assert.Equal(t, mustSkip(cfg), "") +}