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

gRPC Exporter Endpoint Configuration Variable Update #124

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/124.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release:enhancement
cli: added `CO_OTEL_GRPC_ENDPOINT` and `grpc-collector-endpoint` user configurable parameters to set external metrics collection gRPC endpoint.
```
315 changes: 308 additions & 7 deletions go.work.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions internal/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewAgentCmd(ui cli.Ui) (*Command, error) {
c.flags.StringVar(&c.flagConfig.Cloud.ClientSecret, HCPClientSecretOpt, "", fmt.Sprintf("HCP Service Principal Client Secret Environment variable %s", "HCP_CLIENT_SECRET"))
c.flags.StringVar(&c.flagConfig.Cloud.ResourceID, HCPResourceIDOpt, "", fmt.Sprintf("HCP Resource ID Environment variable %s", "HCP_RESOURCE_ID"))
c.flags.StringVar(&c.flagConfig.HTTPCollectorEndpoint, COOtelHTTPEndpointOpt, "", fmt.Sprintf("OTLP HTTP endpoint to forward telemetry to Environment variable %s", "CO_OTEL_HTTP_ENDPOINT"))
c.flags.StringVar(&c.flagConfig.GRPCCollectorEndpoint, COOtelGRPCEndpointOpt, "", fmt.Sprintf("OTLP gRPC endpoint to forward telemetry to Environment variable %s", "CO_OTEL_GRPC_ENDPOINT"))
c.help = flags.Usage(help, c.flags)

return c, nil
Expand Down
2 changes: 2 additions & 0 deletions internal/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func configFromEnvVars() *Config {
},
ConfigFile: os.Getenv(COOConfigPath),
HTTPCollectorEndpoint: os.Getenv(COOtelHTTPEndpoint),
GRPCCollectorEndpoint: os.Getenv(COOtelGRPCEndpoint),
}
}

Expand Down Expand Up @@ -73,6 +74,7 @@ func readConfiguration(reader io.Reader, filename string) (*Config, error) {
type Config struct {
Cloud *Cloud `hcl:"cloud,block"`
HTTPCollectorEndpoint string `hcl:"http_collector_endpoint,optional"`
GRPCCollectorEndpoint string `hcl:"grpc_collector_endpoint,optional"`
ConfigFile string
ExporterConfig *ExporterConfig `hcl:"exporter_config,block"`
}
Expand Down
6 changes: 6 additions & 0 deletions internal/agent/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ const (
// COOtelHTTPEndpoint is the environment variable for OpenTelemetry HTTP Endpoints where metrics are forwarded.
COOtelHTTPEndpoint = "CO_OTEL_HTTP_ENDPOINT"

// COOtelGRPCEndpoint is the environment variable for OpenTelemetry gRPC Endpoints where metrics are forwarded.
COOtelGRPCEndpoint = "CO_OTEL_GRPC_ENDPOINT"

// COOtelHTTPEndpointOpt is the cli opt for the OpenTelemetry HTTP Endpoints where metrics are forwarded.
COOtelHTTPEndpointOpt = "http-collector-endpoint"

// COOtelGRPCEndpointOpt is the cli opt for the OpenTelemetry HTTP Endpoints where metrics are forwarded.
COOtelGRPCEndpointOpt = "grpc-collector-endpoint"

// COOConfigPath is the environment variable for path to the config.
COOConfigPath = "COO_CONFIG_PATH"

Expand Down
9 changes: 9 additions & 0 deletions internal/agent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func NewService(cfg *Config) (*Service, error) {
}
}

if cfg.GRPCCollectorEndpoint != "" {
s.cfg.ExporterConfig = &config.ExporterConfig{
ID: exporters.GRPCOtlpExporterID,
Exporter: &exporters.ExporterConfig{
Endpoint: cfg.GRPCCollectorEndpoint,
},
}
}

if cfg.Cloud != nil && cfg.Cloud.IsEnabled() {
hcpClient, err := hcp.New(&hcp.Params{
ClientID: cfg.Cloud.ClientID,
Expand Down
40 changes: 40 additions & 0 deletions internal/otel/providers/external/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,46 @@ func Test_InMem(t *testing.T) {
otlp := asMap(t, exporters["otlphttp"])
test.Eq(t, otlp["endpoint"], "https://localhost:6060")
})

t.Run("with tls grpc forwarder", func(t *testing.T) {
provider := NewProvider(&config.ExporterConfig{
ID: exporters.GRPCOtlpExporterID,
Exporter: &exporters.ExporterConfig{
Endpoint: "https://localhost:6060",
},
}, providers.SharedParams{})
retrieved, err := provider.Retrieve(context.Background(), "", nil)
test.NoError(t, err)

conf, err := retrieved.AsConf()
test.NoError(t, err)
confMap := conf.ToStringMap()
exporters := asMap(t, confMap["exporters"])
otlp := asMap(t, exporters["otlp"])
test.Eq(t, otlp["endpoint"], "https://localhost:6060")
test.Eq(t, otlp["tls"], nil)
})

t.Run("with non-tls grpc forwarder", func(t *testing.T) {
provider := NewProvider(&config.ExporterConfig{
ID: exporters.GRPCOtlpExporterID,
Exporter: &exporters.ExporterConfig{
Endpoint: "http://localhost:6060",
},
}, providers.SharedParams{})
retrieved, err := provider.Retrieve(context.Background(), "", nil)
test.NoError(t, err)

conf, err := retrieved.AsConf()
test.NoError(t, err)
confMap := conf.ToStringMap()
exporters := asMap(t, confMap["exporters"])
otlp := asMap(t, exporters["otlp"])
test.Eq(t, otlp["endpoint"], "http://localhost:6060")
tlsSetting := asMap(t, otlp["tls"])
test.Eq(t, tlsSetting["insecure"], true)
test.Eq(t, tlsSetting["insecure_skip_verify"], false)
})
}

func asMap(t *testing.T, a any) map[string]any {
Expand Down
Loading