-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry for SDK usage from DBR (#851)
## Changes This PR adds telemetry through the user agent for DBR usage from the SDK. We use the same mechanism and key as the Python SDK to add this to the user agent (PR: databricks/databricks-sdk-py#287). ## Tests Using unit tests
- Loading branch information
1 parent
9cdad94
commit 750e4b6
Showing
7 changed files
with
260 additions
and
15 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
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,30 @@ | ||
package useragent | ||
|
||
import ( | ||
"os" | ||
"sync" | ||
) | ||
|
||
// Clear cached user agent values like the DBR version or the CI/CD provider | ||
// being used. This is useful for testing. | ||
func ClearCache() { | ||
// Reset the sync.Once to their default values. This will recompute the | ||
// values on the next call to Runtime() or CiCdProvider(). | ||
runtimeOnce = sync.Once{} | ||
providerOnce = sync.Once{} | ||
} | ||
|
||
var runtimeOnce sync.Once | ||
var runtimeVersion string | ||
|
||
func getRuntimeVersion() string { | ||
v := os.Getenv("DATABRICKS_RUNTIME_VERSION") | ||
return Sanitize(v) | ||
} | ||
|
||
func Runtime() string { | ||
runtimeOnce.Do(func() { | ||
runtimeVersion = getRuntimeVersion() | ||
}) | ||
return runtimeVersion | ||
} |
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,26 @@ | ||
package useragent | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUserAgentRuntime(t *testing.T) { | ||
for _, tc := range []string{ | ||
"1.2.3", | ||
"0.0.0-dev+2e014739024a", | ||
"client.0", | ||
"foo", | ||
"15.0", | ||
"13.3", | ||
} { | ||
t.Run(tc, func(t *testing.T) { | ||
t.Setenv("DATABRICKS_RUNTIME_VERSION", tc) | ||
|
||
v := getRuntimeVersion() | ||
assert.Equal(t, tc, v) | ||
assert.NoError(t, matchAlphanumOrSemVer(v)) | ||
}) | ||
} | ||
} |
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