-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Telemetry] Add telemetry.sendUsageTo config (#107396)
- Loading branch information
Showing
23 changed files
with
492 additions
and
94 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
48 changes: 48 additions & 0 deletions
48
src/plugins/telemetry/common/telemetry_config/get_telemetry_channel_endpoint.test.ts
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,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getTelemetryChannelEndpoint } from './get_telemetry_channel_endpoint'; | ||
import { TELEMETRY_ENDPOINT } from '../constants'; | ||
|
||
describe('getTelemetryChannelEndpoint', () => { | ||
it('throws on unknown env', () => { | ||
expect(() => | ||
// @ts-expect-error | ||
getTelemetryChannelEndpoint({ env: 'ANY', channelName: 'main' }) | ||
).toThrowErrorMatchingInlineSnapshot(`"Unknown telemetry endpoint env ANY."`); | ||
}); | ||
|
||
it('throws on unknown channelName', () => { | ||
expect(() => | ||
// @ts-expect-error | ||
getTelemetryChannelEndpoint({ env: 'prod', channelName: 'ANY' }) | ||
).toThrowErrorMatchingInlineSnapshot(`"Unknown telemetry channel ANY."`); | ||
}); | ||
|
||
describe('main channel', () => { | ||
it('returns correct prod endpoint', () => { | ||
const endpoint = getTelemetryChannelEndpoint({ env: 'prod', channelName: 'main' }); | ||
expect(endpoint).toBe(TELEMETRY_ENDPOINT.MAIN_CHANNEL.PROD); | ||
}); | ||
it('returns correct staging endpoint', () => { | ||
const endpoint = getTelemetryChannelEndpoint({ env: 'staging', channelName: 'main' }); | ||
expect(endpoint).toBe(TELEMETRY_ENDPOINT.MAIN_CHANNEL.STAGING); | ||
}); | ||
}); | ||
|
||
describe('optInStatus channel', () => { | ||
it('returns correct prod endpoint', () => { | ||
const endpoint = getTelemetryChannelEndpoint({ env: 'prod', channelName: 'optInStatus' }); | ||
expect(endpoint).toBe(TELEMETRY_ENDPOINT.OPT_IN_STATUS_CHANNEL.PROD); | ||
}); | ||
it('returns correct staging endpoint', () => { | ||
const endpoint = getTelemetryChannelEndpoint({ env: 'staging', channelName: 'optInStatus' }); | ||
expect(endpoint).toBe(TELEMETRY_ENDPOINT.OPT_IN_STATUS_CHANNEL.STAGING); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/plugins/telemetry/common/telemetry_config/get_telemetry_channel_endpoint.ts
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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { TELEMETRY_ENDPOINT } from '../constants'; | ||
|
||
export interface GetTelemetryChannelEndpointConfig { | ||
channelName: 'main' | 'optInStatus'; | ||
env: 'staging' | 'prod'; | ||
} | ||
|
||
export function getTelemetryChannelEndpoint({ | ||
channelName, | ||
env, | ||
}: GetTelemetryChannelEndpointConfig): string { | ||
if (env !== 'staging' && env !== 'prod') { | ||
throw new Error(`Unknown telemetry endpoint env ${env}.`); | ||
} | ||
|
||
const endpointEnv = env === 'staging' ? 'STAGING' : 'PROD'; | ||
|
||
switch (channelName) { | ||
case 'main': | ||
return TELEMETRY_ENDPOINT.MAIN_CHANNEL[endpointEnv]; | ||
case 'optInStatus': | ||
return TELEMETRY_ENDPOINT.OPT_IN_STATUS_CHANNEL[endpointEnv]; | ||
default: | ||
throw new Error(`Unknown telemetry channel ${channelName}.`); | ||
} | ||
} |
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
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
Oops, something went wrong.