-
Notifications
You must be signed in to change notification settings - Fork 26
[CFX-6327] feat(telemetry): send to Amplitude EU ingest #740
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
Open
ajalon1
wants to merge
7
commits into
datarobot-oss:main
Choose a base branch
from
ajalon1:cfx-6327-telemetry-server-zone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2b99e25
[CFX-6327] feat(telemetry): support DATAROBOT_CLI_TELEMETRY_SERVER_ZONE
ajalon1 ea4dfd9
[CFX-6327] refactor(telemetry): make --telemetry-server-zone universal
ajalon1 6fbbba8
[CFX-6327] docs(telemetry): reconcile EU references with post-CFX-744…
ajalon1 3ca6d9f
docs(telemetry): simplify
ajalon1 dbee015
chore: copyright
ajalon1 cca6b69
[CFX-6327] fix(telemetry): parse hostname for zone inference + drop d…
ajalon1 aeb0078
[CFX-6327] test(telemetry): assert known MTS prod host routing
ajalon1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,96 @@ | ||
| // Copyright 2026 DataRobot, Inc. and its affiliates. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package telemetry | ||
|
|
||
| import ( | ||
| "net/url" | ||
| "strings" | ||
|
|
||
| "github.com/amplitude/analytics-go/amplitude/types" | ||
| "github.com/datarobot/cli/internal/config" | ||
| "github.com/datarobot/cli/internal/config/viperx" | ||
| "github.com/datarobot/cli/internal/log" | ||
| ) | ||
|
|
||
| // euHostPatterns lists the host substrings that identify a DataRobot instance | ||
| // in the EU data-residency zone. The Amplitude SDK has no APAC data center, so | ||
| // only US and EU are meaningful here. To extend inference (e.g. a new EU host | ||
| // pattern), append to this slice — no other changes are required. | ||
| // | ||
| // A host is treated as EU when, after lowercasing, it either contains ".eu." | ||
| // or ends with ".eu". The trailing-dot variant avoids false positives on hosts | ||
| // such as "host.europe.datarobot.com". | ||
| var euHostPatterns = []string{".eu."} | ||
|
|
||
| // inferServerZone derives the Amplitude ServerZone from a DataRobot base URL. | ||
| // EU-matching hosts return ServerZoneEU; everything else (including the empty | ||
| // string) defaults to ServerZoneUS. | ||
| func inferServerZone(baseURL string) types.ServerZone { | ||
| host := strings.ToLower(baseURL) | ||
|
|
||
| // Match against the hostname (port-stripped) rather than the full URL so | ||
| // that an EU endpoint with an explicit port (e.g. "https://mytenant.eu:8443") | ||
| // still satisfies the ".eu" suffix rule. Fall back to the lowercased full | ||
| // string if parsing fails or no host is present. | ||
| if u, err := url.Parse(baseURL); err == nil && u.Hostname() != "" { | ||
| host = strings.ToLower(u.Hostname()) | ||
| } | ||
|
|
||
| if strings.HasSuffix(host, ".eu") { | ||
| return types.ServerZoneEU | ||
| } | ||
|
|
||
| for _, pattern := range euHostPatterns { | ||
| if strings.Contains(host, pattern) { | ||
| return types.ServerZoneEU | ||
| } | ||
| } | ||
|
|
||
| return types.ServerZoneUS | ||
| } | ||
|
|
||
| // resolveServerZone determines the Amplitude ServerZone to use at client | ||
| // initialization. An explicit override (flag, env var, or config file) takes | ||
| // precedence over the value inferred from the configured DataRobot endpoint. | ||
| // | ||
| // Precedence follows viper's own ordering (flag > env > config). An empty or | ||
| // whitespace-only override is treated as "unset" and falls back to inference. | ||
| // An invalid value (not "US" or "EU", case-insensitive) logs a warning to the | ||
| // debug log and falls back to the inferred zone rather than failing CLI | ||
| // execution — telemetry initialization must never block or error visibly. | ||
| func resolveServerZone() types.ServerZone { | ||
| inferred := inferServerZone(config.GetBaseURL()) | ||
|
|
||
| raw := strings.TrimSpace(viperx.GetString(config.TelemetryServerZone)) | ||
| if raw == "" { | ||
| return inferred | ||
| } | ||
|
|
||
| switch strings.ToUpper(raw) { | ||
| case "EU": | ||
| return types.ServerZoneEU | ||
|
|
||
| case "US": | ||
| return types.ServerZoneUS | ||
|
|
||
| default: | ||
| log.Warnf( | ||
| "invalid value %q for telemetry-server-zone (expected US or EU); falling back to inferred zone %s", | ||
| raw, inferred, | ||
| ) | ||
|
|
||
| return inferred | ||
| } | ||
| } | ||
This file contains hidden or 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,111 @@ | ||
| // Copyright 2026 DataRobot, Inc. and its affiliates. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package telemetry | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/amplitude/analytics-go/amplitude/types" | ||
| "github.com/datarobot/cli/internal/config" | ||
| "github.com/datarobot/cli/internal/config/viperx" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestInferServerZone(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| baseURL string | ||
| want types.ServerZone | ||
| }{ | ||
| {name: "US default", baseURL: "https://app.datarobot.com", want: types.ServerZoneUS}, | ||
| {name: "EU subdomain", baseURL: "https://app.eu.datarobot.com", want: types.ServerZoneEU}, | ||
| {name: "Japan cloud routes to US (no APAC Amplitude DC)", baseURL: "https://app.jp.datarobot.com", want: types.ServerZoneUS}, | ||
| {name: "EU suffix", baseURL: "https://mytenant.eu", want: types.ServerZoneEU}, | ||
| {name: "EU suffix with explicit port", baseURL: "https://mytenant.eu:8443", want: types.ServerZoneEU}, | ||
| {name: "EU subdomain with explicit port", baseURL: "https://app.eu.datarobot.com:443", want: types.ServerZoneEU}, | ||
| {name: "EU segment with trailing dot", baseURL: "https://app.eu.datarobot.com/api/v2", want: types.ServerZoneEU}, | ||
| {name: "europe is not EU", baseURL: "https://host.europe.datarobot.com", want: types.ServerZoneUS}, | ||
| {name: "empty defaults to US", baseURL: "", want: types.ServerZoneUS}, | ||
| {name: "uppercase host matched case-insensitively", baseURL: "https://APP.EU.DATAROBOT.COM", want: types.ServerZoneEU}, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| assert.Equal(t, tc.want, inferServerZone(tc.baseURL)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestResolveServerZone_EmptyUsesInferred(t *testing.T) { | ||
| viperx.Reset() | ||
| t.Cleanup(viperx.Reset) | ||
|
|
||
| viperx.Set(config.DataRobotURL, "https://app.eu.datarobot.com") | ||
|
|
||
| assert.Equal(t, types.ServerZoneEU, resolveServerZone()) | ||
| } | ||
|
|
||
| func TestResolveServerZone_OverrideWinsOverInference(t *testing.T) { | ||
| viperx.Reset() | ||
| t.Cleanup(viperx.Reset) | ||
|
|
||
| // EU endpoint, explicit US override → US. | ||
| viperx.Set(config.DataRobotURL, "https://app.eu.datarobot.com") | ||
| viperx.Set(config.TelemetryServerZone, "US") | ||
|
|
||
| assert.Equal(t, types.ServerZoneUS, resolveServerZone()) | ||
|
|
||
| // US endpoint, explicit EU override → EU. | ||
| viperx.Set(config.DataRobotURL, "https://app.datarobot.com") | ||
| viperx.Set(config.TelemetryServerZone, "EU") | ||
|
|
||
| assert.Equal(t, types.ServerZoneEU, resolveServerZone()) | ||
| } | ||
|
|
||
| func TestResolveServerZone_CaseInsensitive(t *testing.T) { | ||
| viperx.Reset() | ||
| t.Cleanup(viperx.Reset) | ||
|
|
||
| viperx.Set(config.DataRobotURL, "https://app.datarobot.com") | ||
|
|
||
| for _, val := range []string{"eu", "Eu", "eU"} { | ||
| viperx.Set(config.TelemetryServerZone, val) | ||
|
|
||
| assert.Equal(t, types.ServerZoneEU, resolveServerZone(), | ||
| "override %q should resolve to EU", val) | ||
| } | ||
| } | ||
|
|
||
| func TestResolveServerZone_InvalidFallsBackToInferred(t *testing.T) { | ||
| viperx.Reset() | ||
| t.Cleanup(viperx.Reset) | ||
|
|
||
| // EU endpoint with an unsupported value (APAC has no Amplitude DC) → warn | ||
| // and fall back to the inferred EU zone, not a hard-coded US. | ||
| viperx.Set(config.DataRobotURL, "https://app.eu.datarobot.com") | ||
| viperx.Set(config.TelemetryServerZone, "APAC") | ||
|
|
||
| assert.Equal(t, types.ServerZoneEU, resolveServerZone()) | ||
| } | ||
|
|
||
| func TestResolveServerZone_WhitespaceOnlyTreatedAsUnset(t *testing.T) { | ||
| viperx.Reset() | ||
| t.Cleanup(viperx.Reset) | ||
|
|
||
| viperx.Set(config.DataRobotURL, "https://app.datarobot.com") | ||
| viperx.Set(config.TelemetryServerZone, " ") | ||
|
|
||
| assert.Equal(t, types.ServerZoneUS, resolveServerZone()) | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.