1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: collect prometheus data about archived features (#6728)

This commit is contained in:
Jaanus Sellin 2024-03-28 13:40:30 +02:00 committed by GitHub
parent 5b325568d1
commit d3847fd8ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View File

@ -39,6 +39,7 @@ export interface InstanceStats {
serviceAccounts: number; serviceAccounts: number;
apiTokens: Map<string, number>; apiTokens: Map<string, number>;
featureToggles: number; featureToggles: number;
archivedFeatureToggles: number;
projects: ProjectModeCount[]; projects: ProjectModeCount[];
contextFields: number; contextFields: number;
roles: number; roles: number;
@ -192,6 +193,12 @@ export class InstanceStatsService {
}); });
} }
getArchivedToggleCount(): Promise<number> {
return this.featureToggleStore.count({
archived: true,
});
}
async hasOIDC(): Promise<boolean> { async hasOIDC(): Promise<boolean> {
const settings = await this.settingStore.get<{ enabled: boolean }>( const settings = await this.settingStore.get<{ enabled: boolean }>(
'unleash.enterprise.auth.oidc', 'unleash.enterprise.auth.oidc',
@ -215,6 +222,7 @@ export class InstanceStatsService {
const versionInfo = await this.versionService.getVersionInfo(); const versionInfo = await this.versionService.getVersionInfo();
const [ const [
featureToggles, featureToggles,
archivedFeatureToggles,
users, users,
serviceAccounts, serviceAccounts,
apiTokens, apiTokens,
@ -237,6 +245,7 @@ export class InstanceStatsService {
previousDayMetricsBucketsCount, previousDayMetricsBucketsCount,
] = await Promise.all([ ] = await Promise.all([
this.getToggleCount(), this.getToggleCount(),
this.getArchivedToggleCount(),
this.userStore.count(), this.userStore.count(),
this.userStore.countServiceAccounts(), this.userStore.countServiceAccounts(),
this.apiTokenStore.countByType(), this.apiTokenStore.countByType(),
@ -269,6 +278,7 @@ export class InstanceStatsService {
apiTokens, apiTokens,
activeUsers, activeUsers,
featureToggles, featureToggles,
archivedFeatureToggles,
projects, projects,
contextFields, contextFields,
roles, roles,

View File

@ -190,6 +190,11 @@ test('should collect metrics for feature toggle size', async () => {
expect(metrics).toMatch(/feature_toggles_total\{version="(.*)"\} 0/); expect(metrics).toMatch(/feature_toggles_total\{version="(.*)"\} 0/);
}); });
test('should collect metrics for archived feature toggle size', async () => {
const metrics = await prometheusRegister.metrics();
expect(metrics).toMatch(/feature_toggles_archived_total 0/);
});
test('should collect metrics for total client apps', async () => { test('should collect metrics for total client apps', async () => {
await statsService.refreshAppCountSnapshot(); await statsService.refreshAppCountSnapshot();
const metrics = await prometheusRegister.metrics(); const metrics = await prometheusRegister.metrics();

View File

@ -108,6 +108,11 @@ export default class MetricsMonitor {
help: 'Number of feature toggles', help: 'Number of feature toggles',
labelNames: ['version'], labelNames: ['version'],
}); });
const featureTogglesArchivedTotal = createGauge({
name: 'feature_toggles_archived_total',
help: 'Number of archived feature toggles',
});
const usersTotal = createGauge({ const usersTotal = createGauge({
name: 'users_total', name: 'users_total',
help: 'Number of users', help: 'Number of users',
@ -262,6 +267,9 @@ export default class MetricsMonitor {
.labels({ version }) .labels({ version })
.set(stats.featureToggles); .set(stats.featureToggles);
featureTogglesArchivedTotal.reset();
featureTogglesArchivedTotal.set(stats.archivedFeatureToggles);
usersTotal.reset(); usersTotal.reset();
usersTotal.set(stats.users); usersTotal.set(stats.users);

View File

@ -94,6 +94,7 @@ class InstanceAdminController extends Controller {
featureExports: 0, featureExports: 0,
featureImports: 0, featureImports: 0,
featureToggles: 29, featureToggles: 29,
archivedFeatureToggles: 10,
groups: 3, groups: 3,
instanceId: 'ed3861ae-78f9-4e8c-8e57-b57efc15f82b', instanceId: 'ed3861ae-78f9-4e8c-8e57-b57efc15f82b',
projects: 4, projects: 4,