Skip to content

Commit d6315c3

Browse files
Status reporter extension.
Status reporter extension.
1 parent 3b0fcd3 commit d6315c3

File tree

10 files changed

+1013
-0
lines changed

10 files changed

+1013
-0
lines changed

cmd/otelcontribcol/builder-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extensions:
5858
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/googlecloudlogentryencodingextension v0.136.0
5959
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/k8sleaderelector v0.136.0
6060
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/cgroupruntimeextension v0.136.0
61+
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/statusreporterextension v0.136.0
6162

6263
exporters:
6364
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.136.1-0.20251002223229-5ec1466578ef
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package statusreporterextension
2+
3+
// Config holds the configuration for the statusreporter extension.
4+
// This extension exposes health information about the collector at the "/api/otel-status" endpoint.
5+
type Config struct {
6+
MetricsEndpoint string `mapstructure:"metrics_endpoint"` // endpoint to scrape metrics from
7+
StaleThreshold int `mapstructure:"stale_threshold"` // threshold in seconds to consider data stale
8+
EngineID string `mapstructure:"engine_id"` // identifier for the engine (e.g., presto-01)
9+
PodName string `mapstructure:"pod_name"` // name of the pod where OTeL sidecar is attached
10+
Port int `mapstructure:"port"` // port on which the status reporter server listens
11+
AuthEnabled bool `mapstructure:"auth_enabled"` // whether authentication is enabled
12+
SecretValue string `mapstructure:"secret_value"` // fallback secret value if LH_INSTANCE_SECRET is not set
13+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package statusreporterextension
5+
6+
import (
7+
"testing"
8+
)
9+
10+
func TestConfigValidation(t *testing.T) {
11+
// Test with default config
12+
cfg := createDefaultConfig().(*Config)
13+
if cfg.MetricsEndpoint != "http://localhost:8888/metrics" {
14+
t.Errorf("Expected default MetricsEndpoint to be http://localhost:8888/metrics, got %s", cfg.MetricsEndpoint)
15+
}
16+
17+
// Test with custom values
18+
cfg.MetricsEndpoint = "http://custom:9090/metrics"
19+
cfg.StaleThreshold = 600
20+
cfg.EngineID = "custom-engine"
21+
cfg.PodName = "custom-pod"
22+
cfg.Port = 9000
23+
cfg.AuthEnabled = true
24+
cfg.SecretValue = "custom-secret"
25+
26+
// Verify custom values
27+
if cfg.MetricsEndpoint != "http://custom:9090/metrics" {
28+
t.Errorf("Failed to set custom MetricsEndpoint")
29+
}
30+
31+
if cfg.StaleThreshold != 600 {
32+
t.Errorf("Failed to set custom StaleThreshold")
33+
}
34+
35+
if cfg.EngineID != "custom-engine" {
36+
t.Errorf("Failed to set custom EngineID")
37+
}
38+
39+
if cfg.PodName != "custom-pod" {
40+
t.Errorf("Failed to set custom PodName")
41+
}
42+
43+
if cfg.Port != 9000 {
44+
t.Errorf("Failed to set custom Port")
45+
}
46+
47+
if !cfg.AuthEnabled {
48+
t.Errorf("Failed to set custom AuthEnabled")
49+
}
50+
51+
if cfg.SecretValue != "custom-secret" {
52+
t.Errorf("Failed to set custom SecretValue")
53+
}
54+
}
55+
56+
func TestConfigEdgeCases(t *testing.T) {
57+
cfg := createDefaultConfig().(*Config)
58+
59+
// Test with empty metrics endpoint
60+
cfg.MetricsEndpoint = ""
61+
// This should be allowed, as the extension will use a default value
62+
63+
// Test with negative stale threshold
64+
cfg.StaleThreshold = -1
65+
// This should be allowed, though it might not be practical
66+
67+
// Test with zero port (should use system-assigned port)
68+
cfg.Port = 0
69+
// This should be allowed, as the HTTP server can use a system-assigned port
70+
71+
// Test with empty engine ID
72+
cfg.EngineID = ""
73+
// This should be allowed, though it might not be useful
74+
75+
// Test with empty pod name
76+
cfg.PodName = ""
77+
// This should be allowed, though it might not be useful
78+
79+
// Test with auth enabled but empty secret
80+
cfg.AuthEnabled = true
81+
cfg.SecretValue = ""
82+
// This should be allowed, as the secret might be provided via environment variable
83+
}
84+

0 commit comments

Comments
 (0)