forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alerting] Telemetry for calling legacy routes (elastic#111885)
* Telemetry for calling legacy routes * Fix types * Use different counter type * PR feedback * Fix this test too # Conflicts: # x-pack/plugins/alerting/server/routes/legacy/create.ts
- Loading branch information
1 parent
2796926
commit a0060b1
Showing
37 changed files
with
569 additions
and
41 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/alerting/server/lib/track_legacy_route_usage.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,32 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { usageCountersServiceMock } from 'src/plugins/usage_collection/server/usage_counters/usage_counters_service.mock'; | ||
import { trackLegacyRouteUsage } from './track_legacy_route_usage'; | ||
|
||
describe('trackLegacyRouteUsage', () => { | ||
it('should call `usageCounter.incrementCounter`', () => { | ||
const mockUsageCountersSetup = usageCountersServiceMock.createSetupContract(); | ||
const mockUsageCounter = mockUsageCountersSetup.createUsageCounter('test'); | ||
|
||
trackLegacyRouteUsage('test', mockUsageCounter); | ||
expect(mockUsageCounter.incrementCounter).toHaveBeenCalledWith({ | ||
counterName: `legacyRoute_test`, | ||
counterType: 'legacyApiUsage', | ||
incrementBy: 1, | ||
}); | ||
}); | ||
|
||
it('should do nothing if no usage counter is provided', () => { | ||
let err; | ||
try { | ||
trackLegacyRouteUsage('test', undefined); | ||
} catch (e) { | ||
err = e; | ||
} | ||
expect(err).toBeUndefined(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/alerting/server/lib/track_legacy_route_usage.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,18 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { UsageCounter } from 'src/plugins/usage_collection/server'; | ||
|
||
export function trackLegacyRouteUsage(route: string, usageCounter?: UsageCounter) { | ||
if (usageCounter) { | ||
usageCounter.incrementCounter({ | ||
counterName: `legacyRoute_${route}`, | ||
counterType: 'legacyApiUsage', | ||
incrementBy: 1, | ||
}); | ||
} | ||
} |
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
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.