-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send environment type (tests, prod) in telemetry events (#944)
## Changes Set the type based on a presence of TEST_DEFAULT_CLUSTER_ID env var, which is only set in e2e tests. Also don't sent telemetry to a prod endpoint when we run unit tests.p ## Tests Manually and with new unit tests
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import TelemetryReporter from "@vscode/extension-telemetry"; | ||
import assert from "assert"; | ||
import {mock, instance, capture, when} from "ts-mockito"; | ||
import {Telemetry, toUserMetadata} from "."; | ||
import {Telemetry, getContextMetadata, toUserMetadata} from "."; | ||
import {Events, Metadata} from "./constants"; | ||
import {DatabricksWorkspace} from "../configuration/DatabricksWorkspace"; | ||
import {Uri} from "vscode"; | ||
|
@@ -12,10 +12,14 @@ import {ApiClient, Config} from "@databricks/databricks-sdk"; | |
describe(__filename, () => { | ||
let reporter: TelemetryReporter; | ||
let telemetry: Telemetry; | ||
const defaultClusterId = process.env["TEST_DEFAULT_CLUSTER_ID"]; | ||
beforeEach(async () => { | ||
reporter = mock(TelemetryReporter); | ||
telemetry = new Telemetry(instance(reporter)); | ||
}); | ||
afterEach(() => { | ||
process.env["TEST_DEFAULT_CLUSTER_ID"] = defaultClusterId; | ||
}); | ||
it("should record expected properties and metrics", async () => { | ||
telemetry.recordEvent(Events.COMMAND_EXECUTION, { | ||
command: "testCommand", | ||
|
@@ -36,6 +40,42 @@ describe(__filename, () => { | |
}); | ||
}); | ||
|
||
it("sets context metadata with prod env type", async () => { | ||
delete process.env["TEST_DEFAULT_CLUSTER_ID"]; | ||
telemetry.setMetadata(Metadata.CONTEXT, getContextMetadata()); | ||
telemetry.recordEvent(Events.COMMAND_EXECUTION, { | ||
command: "testCommand", | ||
success: true, | ||
duration: 100, | ||
}); | ||
const [eventName, props] = capture(reporter.sendTelemetryEvent).last(); | ||
assert.equal(eventName, "commandExecution"); | ||
assert.deepEqual(props, { | ||
"version": "1.0", | ||
"event.command": "testCommand", | ||
"event.success": "true", | ||
"context.environmentType": "prod", | ||
}); | ||
}); | ||
|
||
it("sets context metadata with tests env type", async () => { | ||
process.env["TEST_DEFAULT_CLUSTER_ID"] = "123"; | ||
telemetry.setMetadata(Metadata.CONTEXT, getContextMetadata()); | ||
telemetry.recordEvent(Events.COMMAND_EXECUTION, { | ||
command: "testCommand", | ||
success: true, | ||
duration: 100, | ||
}); | ||
const [eventName, props] = capture(reporter.sendTelemetryEvent).last(); | ||
assert.equal(eventName, "commandExecution"); | ||
assert.deepEqual(props, { | ||
"version": "1.0", | ||
"event.command": "testCommand", | ||
"event.success": "true", | ||
"context.environmentType": "tests", | ||
}); | ||
}); | ||
|
||
it("sets user metadata correctly after logged in", async () => { | ||
const ws = mock(DatabricksWorkspace); | ||
when(ws.userName).thenReturn("[email protected]"); | ||
|
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