Skip to content

Commit

Permalink
Merge branch 'main' into add_error_tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
marctc authored Jul 15, 2024
2 parents 9b7d4ca + c2f300b commit dd270be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 2 additions & 13 deletions pkg/components/beyla.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ""
Expand Down
10 changes: 10 additions & 0 deletions pkg/components/beyla_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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), "")
}

0 comments on commit dd270be

Please sign in to comment.