Skip to content

Commit

Permalink
Correct the comment for the priority of options and environments on o…
Browse files Browse the repository at this point in the history
…tlpmetric (#5641)

Part of #5379
  • Loading branch information
XSAM authored Jul 25, 2024
1 parent 3e17ef9 commit 48f6a11
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Correct the `Meter` name used in `go.opentelemetry.io/otel/example/prometheus`. (#5612)
- Correct the `Tracer` names used in `go.opentelemetry.io/otel/example/zipkin`. (#5612)
- Pass the underlying error rather than a generic retry-able failure in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`, `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` and `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5541)
- Correct comments for the priority of the `WithEndpoint` and `WithEndpointURL` options and their corresponding environment variables in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` and `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#5641)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
10 changes: 6 additions & 4 deletions exporters/otlp/otlpmetric/otlpmetricgrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func WithInsecure() Option {
//
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// environment variable is set, and this option is not passed, that variable
// value will be used. If both are set, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// will take precedence.
// value will be used. If both environment variables are set,
// OTEL_EXPORTER_OTLP_METRICS_ENDPOINT will take precedence. If an environment
// variable is set, and this option is passed, this option will take precedence.
//
// If both this option and WithEndpointURL are used, the last used option will
// take precedence.
Expand All @@ -84,8 +85,9 @@ func WithEndpoint(endpoint string) Option {
//
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// environment variable is set, and this option is not passed, that variable
// value will be used. If both are set, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// will take precedence.
// value will be used. If both environment variables are set,
// OTEL_EXPORTER_OTLP_METRICS_ENDPOINT will take precedence. If an environment
// variable is set, and this option is passed, this option will take precedence.
//
// If both this option and WithEndpoint are used, the last used option will
// take precedence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ func TestConfigs(t *testing.T) {
assert.Equal(t, "/v1/metrics", c.Metrics.URLPath)
},
},
{
name: "Test With Endpoint last used",
opts: []GenericOption{
WithEndpointURL("https://someendpoint/somepath"),
WithEndpoint("someendpoint2"),
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "someendpoint2", c.Metrics.Endpoint)
},
},
{
name: "Test With WithEndpointURL last used",
opts: []GenericOption{
WithEndpoint("someendpoint2"),
WithEndpointURL("https://someendpoint/somepath"),
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "someendpoint", c.Metrics.Endpoint)
},
},
{
name: "Test Environment Endpoint",
env: map[string]string{
Expand Down Expand Up @@ -161,15 +181,31 @@ func TestConfigs(t *testing.T) {
{
name: "Test Mixed Environment and With Endpoint",
opts: []GenericOption{
WithEndpointURL("https://metrics_endpoint2/somepath"),
WithEndpoint("metrics_endpoint"),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "env_endpoint2",
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "metrics_endpoint", c.Metrics.Endpoint)
},
},
{
name: "Test Mixed Environment and With Endpoint",
opts: []GenericOption{
WithEndpoint("metrics_endpoint"),
WithEndpointURL("https://metrics_endpoint2/somepath"),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "env_endpoint2",
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "metrics_endpoint2", c.Metrics.Endpoint)
},
},
{
name: "Test Environment Endpoint with HTTP scheme",
env: map[string]string{
Expand Down
10 changes: 6 additions & 4 deletions exporters/otlp/otlpmetric/otlpmetrichttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func (w wrappedOption) applyHTTPOption(cfg oconf.Config) oconf.Config {
//
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// environment variable is set, and this option is not passed, that variable
// value will be used. If both are set, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// will take precedence.
// value will be used. If both environment variables are set,
// OTEL_EXPORTER_OTLP_METRICS_ENDPOINT will take precedence. If an environment
// variable is set, and this option is passed, this option will take precedence.
//
// By default, if an environment variable is not set, and this option is not
// passed, "localhost:4318" will be used.
Expand All @@ -76,8 +77,9 @@ func WithEndpoint(endpoint string) Option {
//
// If the OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// environment variable is set, and this option is not passed, that variable
// value will be used. If both are set, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
// will take precedence.
// value will be used. If both environment variables are set,
// OTEL_EXPORTER_OTLP_METRICS_ENDPOINT will take precedence. If an environment
// variable is set, and this option is passed, this option will take precedence.
//
// If both this option and WithEndpoint are used, the last used option will
// take precedence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ func TestConfigs(t *testing.T) {
assert.Equal(t, "/v1/metrics", c.Metrics.URLPath)
},
},
{
name: "Test With Endpoint last used",
opts: []GenericOption{
WithEndpointURL("https://someendpoint/somepath"),
WithEndpoint("someendpoint2"),
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "someendpoint2", c.Metrics.Endpoint)
},
},
{
name: "Test With WithEndpointURL last used",
opts: []GenericOption{
WithEndpoint("someendpoint2"),
WithEndpointURL("https://someendpoint/somepath"),
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "someendpoint", c.Metrics.Endpoint)
},
},
{
name: "Test Environment Endpoint",
env: map[string]string{
Expand Down Expand Up @@ -161,15 +181,31 @@ func TestConfigs(t *testing.T) {
{
name: "Test Mixed Environment and With Endpoint",
opts: []GenericOption{
WithEndpointURL("https://metrics_endpoint2/somepath"),
WithEndpoint("metrics_endpoint"),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "env_endpoint2",
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "metrics_endpoint", c.Metrics.Endpoint)
},
},
{
name: "Test Mixed Environment and With Endpoint",
opts: []GenericOption{
WithEndpoint("metrics_endpoint"),
WithEndpointURL("https://metrics_endpoint2/somepath"),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "env_endpoint2",
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "metrics_endpoint2", c.Metrics.Endpoint)
},
},
{
name: "Test Environment Endpoint with HTTP scheme",
env: map[string]string{
Expand Down
38 changes: 37 additions & 1 deletion internal/shared/otlp/otlpmetric/oconf/options_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ func TestConfigs(t *testing.T) {
assert.Equal(t, "/v1/metrics", c.Metrics.URLPath)
},
},
{
name: "Test With Endpoint last used",
opts: []GenericOption{
WithEndpointURL("https://someendpoint/somepath"),
WithEndpoint("someendpoint2"),
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "someendpoint2", c.Metrics.Endpoint)
},
},
{
name: "Test With WithEndpointURL last used",
opts: []GenericOption{
WithEndpoint("someendpoint2"),
WithEndpointURL("https://someendpoint/somepath"),
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "someendpoint", c.Metrics.Endpoint)
},
},
{
name: "Test Environment Endpoint",
env: map[string]string{
Expand Down Expand Up @@ -161,15 +181,31 @@ func TestConfigs(t *testing.T) {
{
name: "Test Mixed Environment and With Endpoint",
opts: []GenericOption{
WithEndpointURL("https://metrics_endpoint2/somepath"),
WithEndpoint("metrics_endpoint"),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "env_endpoint2",
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "metrics_endpoint", c.Metrics.Endpoint)
},
},
{
name: "Test Mixed Environment and With Endpoint",
opts: []GenericOption{
WithEndpoint("metrics_endpoint"),
WithEndpointURL("https://metrics_endpoint2/somepath"),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "env_endpoint2",
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, "metrics_endpoint2", c.Metrics.Endpoint)
},
},
{
name: "Test Environment Endpoint with HTTP scheme",
env: map[string]string{
Expand Down

0 comments on commit 48f6a11

Please sign in to comment.