Skip to content

Commit

Permalink
append the endpoint to the profiles URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Sep 11, 2024
1 parent b25e4b2 commit de932f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
17 changes: 11 additions & 6 deletions exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func createDefaultConfig() component.Config {
}
}

func composeSignalURL(oCfg *Config, signalOverrideURL string, signalName string) (string, error) {
func composeSignalURL(oCfg *Config, signalOverrideURL, signalName, signalVersion string) (string, error) {
switch {
case signalOverrideURL != "":
_, err := url.Parse(signalOverrideURL)
Expand All @@ -63,9 +63,9 @@ func composeSignalURL(oCfg *Config, signalOverrideURL string, signalName string)
return "", fmt.Errorf("either endpoint or %s_endpoint must be specified", signalName)
default:
if strings.HasSuffix(oCfg.Endpoint, "/") {
return oCfg.Endpoint + "v1/" + signalName, nil
return oCfg.Endpoint + signalVersion + "/" + signalName, nil
}
return oCfg.Endpoint + "/v1/" + signalName, nil
return oCfg.Endpoint + "/" + signalVersion + "/" + signalName, nil
}
}

Expand All @@ -80,7 +80,7 @@ func createTracesExporter(
}
oCfg := cfg.(*Config)

oce.tracesURL, err = composeSignalURL(oCfg, oCfg.TracesEndpoint, "traces")
oce.tracesURL, err = composeSignalURL(oCfg, oCfg.TracesEndpoint, "traces", "v1")
if err != nil {
return nil, err
}
Expand All @@ -106,7 +106,7 @@ func createMetricsExporter(
}
oCfg := cfg.(*Config)

oce.metricsURL, err = composeSignalURL(oCfg, oCfg.MetricsEndpoint, "metrics")
oce.metricsURL, err = composeSignalURL(oCfg, oCfg.MetricsEndpoint, "metrics", "v1")
if err != nil {
return nil, err
}
Expand All @@ -132,7 +132,7 @@ func createLogsExporter(
}
oCfg := cfg.(*Config)

oce.logsURL, err = composeSignalURL(oCfg, oCfg.LogsEndpoint, "logs")
oce.logsURL, err = composeSignalURL(oCfg, oCfg.LogsEndpoint, "logs", "v1")
if err != nil {
return nil, err
}
Expand All @@ -158,6 +158,11 @@ func createProfilesExporter(
}
oCfg := cfg.(*Config)

oce.profilesURL, err = composeSignalURL(oCfg, "", "profiles", "v1development")
if err != nil {
return nil, err

Check warning on line 163 in exporter/otlphttpexporter/factory.go

View check run for this annotation

Codecov / codecov/patch

exporter/otlphttpexporter/factory.go#L163

Added line #L163 was not covered by tests
}

return exporterhelper.NewProfilesExporter(ctx, set, cfg,
oce.pushProfiles,
exporterhelper.WithStart(oce.start),
Expand Down
10 changes: 8 additions & 2 deletions exporter/otlphttpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,19 @@ func TestComposeSignalURL(t *testing.T) {

// Has slash at end
cfg.ClientConfig.Endpoint = "http://localhost:4318/"
url, err := composeSignalURL(cfg, "", "traces")
url, err := composeSignalURL(cfg, "", "traces", "v1")
require.NoError(t, err)
assert.Equal(t, "http://localhost:4318/v1/traces", url)

// No slash at end
cfg.ClientConfig.Endpoint = "http://localhost:4318"
url, err = composeSignalURL(cfg, "", "traces")
url, err = composeSignalURL(cfg, "", "traces", "v1")
require.NoError(t, err)
assert.Equal(t, "http://localhost:4318/v1/traces", url)

// Different version
cfg.ClientConfig.Endpoint = "http://localhost:4318"
url, err = composeSignalURL(cfg, "", "traces", "v2")
require.NoError(t, err)
assert.Equal(t, "http://localhost:4318/v2/traces", url)
}
19 changes: 9 additions & 10 deletions exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ import (
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
)

const defaultProfilesURL = "/v1development/profiles"

type baseExporter struct {
// Input configuration.
config *Config
client *http.Client
tracesURL string
metricsURL string
logsURL string
logger *zap.Logger
settings component.TelemetrySettings
config *Config
client *http.Client
tracesURL string
metricsURL string
logsURL string
profilesURL string
logger *zap.Logger
settings component.TelemetrySettings
// Default user-agent header.
userAgent string
}
Expand Down Expand Up @@ -171,7 +170,7 @@ func (e *baseExporter) pushProfiles(ctx context.Context, td pprofile.Profiles) e
return consumererror.NewPermanent(err)

Check warning on line 170 in exporter/otlphttpexporter/otlp.go

View check run for this annotation

Codecov / codecov/patch

exporter/otlphttpexporter/otlp.go#L170

Added line #L170 was not covered by tests
}

return e.export(ctx, defaultProfilesURL, request, e.profilesPartialSuccessHandler)
return e.export(ctx, e.profilesURL, request, e.profilesPartialSuccessHandler)
}

func (e *baseExporter) export(ctx context.Context, url string, request []byte, partialSuccessHandler partialSuccessHandler) error {
Expand Down

0 comments on commit de932f1

Please sign in to comment.