[Cloud] Add deploymentId to the EBT context (#155182)

This commit is contained in:
Alejandro Fernández Haro 2023-04-20 17:22:31 +02:00 committed by GitHub
parent 4c79ef4009
commit 031bc369bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 4 deletions

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { parseDeploymentIdFromDeploymentUrl } from './utils';
import { parseDeploymentIdFromDeploymentUrl } from './parse_deployment_id_from_deployment_url';
describe('parseDeploymentIdFromDeploymentUrl', () => {
it('should return undefined if there is no deploymentUrl configured', () => {

View file

@ -29,4 +29,17 @@ describe('registerCloudDeploymentIdAnalyticsContext', () => {
cloudId: 'cloud_id',
});
});
test('it registers the context provider and emits the cloudId and deploymentId', async () => {
registerCloudDeploymentMetadataAnalyticsContext(analytics, {
id: 'cloud_id',
deployment_url: 'deployments/uuid-of-my-deployment',
});
expect(analytics.registerContextProvider).toHaveBeenCalledTimes(1);
const [{ context$ }] = analytics.registerContextProvider.mock.calls[0];
await expect(firstValueFrom(context$)).resolves.toEqual({
cloudId: 'cloud_id',
deploymentId: 'uuid-of-my-deployment',
});
});
});

View file

@ -7,11 +7,13 @@
import type { AnalyticsClient } from '@kbn/analytics-client';
import { of } from 'rxjs';
import { parseDeploymentIdFromDeploymentUrl } from './parse_deployment_id_from_deployment_url';
export interface CloudDeploymentMetadata {
id?: string;
trial_end_date?: string;
is_elastic_staff_owned?: boolean;
deployment_url?: string;
}
export function registerCloudDeploymentMetadataAnalyticsContext(
@ -29,11 +31,20 @@ export function registerCloudDeploymentMetadataAnalyticsContext(
analytics.registerContextProvider({
name: 'Cloud Deployment Metadata',
context$: of({ cloudId, cloudTrialEndDate, cloudIsElasticStaffOwned }),
context$: of({
cloudId,
deploymentId: parseDeploymentIdFromDeploymentUrl(cloudMetadata.deployment_url),
cloudTrialEndDate,
cloudIsElasticStaffOwned,
}),
schema: {
cloudId: {
type: 'keyword',
_meta: { description: 'The Cloud Deployment ID' },
_meta: { description: 'The Cloud ID' },
},
deploymentId: {
type: 'keyword',
_meta: { description: 'The Deployment ID', optional: true },
},
cloudTrialEndDate: {
type: 'date',

View file

@ -11,7 +11,7 @@ import { registerCloudDeploymentMetadataAnalyticsContext } from '../common/regis
import type { CloudConfigType } from './config';
import { registerCloudUsageCollector } from './collectors';
import { getIsCloudEnabled } from '../common/is_cloud_enabled';
import { parseDeploymentIdFromDeploymentUrl } from './utils';
import { parseDeploymentIdFromDeploymentUrl } from '../common/parse_deployment_id_from_deployment_url';
import { readInstanceSizeMb } from './env';
interface PluginsSetup {