forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cmd/telemetrygen] Better defaults for HTTP exporter mode (open-telem…
…etry#27007) **Description:** - Refactored and moved `otlp-http-url-path` flag from the common flags for each command - Added flag to the `traces` command with the default `/v1/traces` - Added flag to the `metrics` command with the default `/v1/metrics` - Flag was not used for the `logs` command so no longer exposed - Handle changing the default endpoint based on the communication mode (gRPC or HTTP) - Flag `--otlp-endpoint` now defaults to empty string and targets a new attribute `CustomEndpoint` on `common.Config` - Added the `Endpoint()` getter function to the `common.Config` struct for retrieving the correct endpoint - When `CustomEndpoint` is empty then either `DefaultGRPCEndpoint` or `DefaultHTTPEndpoint` are chosen based upon the value of `config.UseHTTP` - **Misc**: Split out the creation of trace/metric exporters into standalone factory functions with docstrings available in `exporters.go` in both modules - **Misc**: Removed the "default value is" from the descriptions of some flags as it was repeated information **Link to tracking Issue:** open-telemetry#26999 **Testing:** Added new set of unit tests to cover the addition of the `config.Endpoint()` getter. Running `telemetrygen traces --otlp-http --otlp-insecure` now correctly sends traces using HTTP to the default HTTP endpoint. **Documentation:** No documentation added/changed but updated some command flag descriptions. --------- Co-authored-by: Alex Boten <[email protected]>
- Loading branch information
Showing
12 changed files
with
237 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: bug_fix | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: telemetrygen | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: better defaults for http exporter mode | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [26999] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
- the url path default is now correct for both traces and metrics | ||
- when not provided, the endpoint is automatically set to target a local gRPC or HTTP endpoint depending on the communication mode selected | ||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestConfig_HTTPPath verifies that the HTTPPath configuration defaults are correctly set for each sub-command. | ||
func TestConfig_HTTPPath(t *testing.T) { | ||
t.Run("LogsConfigEmptyDefaultUrlPath", func(t *testing.T) { | ||
assert.Equal(t, "", logsCfg.HTTPPath) | ||
}) | ||
|
||
t.Run("MetricsConfigValidDefaultUrlPath", func(t *testing.T) { | ||
assert.Equal(t, "/v1/metrics", metricsCfg.HTTPPath) | ||
}) | ||
|
||
t.Run("TracesConfigValidDefaultUrlPath", func(t *testing.T) { | ||
assert.Equal(t, "/v1/traces", tracesCfg.HTTPPath) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package metrics | ||
|
||
import ( | ||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" | ||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// grpcExporterOptions creates the configuration options for a gRPC-based OTLP metric exporter. | ||
// It configures the exporter with the provided endpoint, connection security settings, and headers. | ||
func grpcExporterOptions(cfg *Config) []otlpmetricgrpc.Option { | ||
grpcExpOpt := []otlpmetricgrpc.Option{ | ||
otlpmetricgrpc.WithEndpoint(cfg.Endpoint()), | ||
otlpmetricgrpc.WithDialOption( | ||
grpc.WithBlock(), | ||
), | ||
} | ||
|
||
if cfg.Insecure { | ||
grpcExpOpt = append(grpcExpOpt, otlpmetricgrpc.WithInsecure()) | ||
} | ||
|
||
if len(cfg.Headers) > 0 { | ||
grpcExpOpt = append(grpcExpOpt, otlpmetricgrpc.WithHeaders(cfg.Headers)) | ||
} | ||
|
||
return grpcExpOpt | ||
} | ||
|
||
// httpExporterOptions creates the configuration options for an HTTP-based OTLP metric exporter. | ||
// It configures the exporter with the provided endpoint, URL path, connection security settings, and headers. | ||
func httpExporterOptions(cfg *Config) []otlpmetrichttp.Option { | ||
httpExpOpt := []otlpmetrichttp.Option{ | ||
otlpmetrichttp.WithEndpoint(cfg.Endpoint()), | ||
otlpmetrichttp.WithURLPath(cfg.HTTPPath), | ||
} | ||
|
||
if cfg.Insecure { | ||
httpExpOpt = append(httpExpOpt, otlpmetrichttp.WithInsecure()) | ||
} | ||
|
||
if len(cfg.Headers) > 0 { | ||
httpExpOpt = append(httpExpOpt, otlpmetrichttp.WithHeaders(cfg.Headers)) | ||
} | ||
|
||
return httpExpOpt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package traces | ||
|
||
import ( | ||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" | ||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// grpcExporterOptions creates the configuration options for a gRPC-based OTLP trace exporter. | ||
// It configures the exporter with the provided endpoint, connection security settings, and headers. | ||
func grpcExporterOptions(cfg *Config) []otlptracegrpc.Option { | ||
grpcExpOpt := []otlptracegrpc.Option{ | ||
otlptracegrpc.WithEndpoint(cfg.Endpoint()), | ||
otlptracegrpc.WithDialOption( | ||
grpc.WithBlock(), | ||
), | ||
} | ||
|
||
if cfg.Insecure { | ||
grpcExpOpt = append(grpcExpOpt, otlptracegrpc.WithInsecure()) | ||
} | ||
|
||
if len(cfg.Headers) > 0 { | ||
grpcExpOpt = append(grpcExpOpt, otlptracegrpc.WithHeaders(cfg.Headers)) | ||
} | ||
|
||
return grpcExpOpt | ||
} | ||
|
||
// httpExporterOptions creates the configuration options for an HTTP-based OTLP trace exporter. | ||
// It configures the exporter with the provided endpoint, URL path, connection security settings, and headers. | ||
func httpExporterOptions(cfg *Config) []otlptracehttp.Option { | ||
httpExpOpt := []otlptracehttp.Option{ | ||
otlptracehttp.WithEndpoint(cfg.Endpoint()), | ||
otlptracehttp.WithURLPath(cfg.HTTPPath), | ||
} | ||
|
||
if cfg.Insecure { | ||
httpExpOpt = append(httpExpOpt, otlptracehttp.WithInsecure()) | ||
} | ||
|
||
if len(cfg.Headers) > 0 { | ||
httpExpOpt = append(httpExpOpt, otlptracehttp.WithHeaders(cfg.Headers)) | ||
} | ||
|
||
return httpExpOpt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters