Skip to content

Commit

Permalink
add unit tests and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski committed Jul 12, 2024
1 parent ff6f53b commit ae8c284
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions pkg/beyla/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@ func TestConfig_OtelGoAutoEnv(t *testing.T) {
assert.True(t, cfg.Exec.IsSet()) // Exec maps to BEYLA_EXECUTABLE_NAME
}

func TestConfig_NetworkImplicit(t *testing.T) {
// OTEL_GO_AUTO_TARGET_EXE is an alias to BEYLA_EXECUTABLE_NAME
// (Compatibility with OpenTelemetry)
require.NoError(t, os.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4318"))
require.NoError(t, os.Setenv("BEYLA_OTEL_METRIC_FEATURES", "network"))
cfg, err := LoadConfig(bytes.NewReader(nil))
require.NoError(t, err)
assert.True(t, cfg.Enabled(FeatureNetO11y)) // Net o11y should be on
}

func TestConfig_NetworkImplicitProm(t *testing.T) {
// OTEL_GO_AUTO_TARGET_EXE is an alias to BEYLA_EXECUTABLE_NAME
// (Compatibility with OpenTelemetry)
require.NoError(t, os.Setenv("BEYLA_PROMETHEUS_PORT", "9090"))
require.NoError(t, os.Setenv("BEYLA_PROMETHEUS_FEATURES", "network"))
cfg, err := LoadConfig(bytes.NewReader(nil))
require.NoError(t, err)
assert.True(t, cfg.Enabled(FeatureNetO11y)) // Net o11y should be on
}

func loadConfig(t *testing.T, env map[string]string) *Config {
for k, v := range env {
require.NoError(t, os.Setenv(k, v))
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/export/otel/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (m *MetricsConfig) NetworkMetricsEnabled() bool {
}

func (m *MetricsConfig) Enabled() bool {
return m.EndpointEnabled() && (m.OTelMetricsEnabled() || m.SpanMetricsEnabled() || m.ServiceGraphMetricsEnabled())
return m.EndpointEnabled() && (m.OTelMetricsEnabled() || m.SpanMetricsEnabled() || m.ServiceGraphMetricsEnabled() || m.NetworkMetricsEnabled())
}

// MetricsReporter implements the graph node that receives request.Span
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/export/prom/prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (p *PrometheusConfig) EndpointEnabled() bool {

// nolint:gocritic
func (p *PrometheusConfig) Enabled() bool {
return p.EndpointEnabled() && (p.OTelMetricsEnabled() || p.SpanMetricsEnabled() || p.ServiceGraphMetricsEnabled())
return p.EndpointEnabled() && (p.OTelMetricsEnabled() || p.SpanMetricsEnabled() || p.ServiceGraphMetricsEnabled() || p.NetworkMetricsEnabled())
}

type metricsReporter struct {
Expand Down

0 comments on commit ae8c284

Please sign in to comment.