1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

Add a counter for total number of environments (#1964)

This commit is contained in:
Christopher Kolstad 2022-09-06 13:24:13 +02:00 committed by GitHub
parent 8648649047
commit 4ed05047f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View File

@ -81,6 +81,13 @@ export default class EnvironmentStore implements IEnvironmentStore {
await this.db(TABLE).del();
}
count(): Promise<number> {
return this.db
.from(TABLE)
.count('*')
.then((res) => Number(res[0].count));
}
async get(key: string): Promise<IEnvironment> {
const row = await this.db<IEnvironmentsTable>(TABLE)
.where({ name: key })

View File

@ -40,8 +40,13 @@ export default class MetricsMonitor {
return;
}
const { eventStore, featureToggleStore, userStore, projectStore } =
stores;
const {
eventStore,
featureToggleStore,
userStore,
projectStore,
environmentStore,
} = stores;
client.collectDefaultMetrics();
@ -84,6 +89,10 @@ export default class MetricsMonitor {
name: 'projects_total',
help: 'Number of projects',
});
const environmentsTotal = new client.Gauge({
name: 'environments_total',
help: 'Number of environments',
});
const clientSdkVersionUsage = new client.Counter({
name: 'client_sdk_versions',
@ -95,12 +104,14 @@ export default class MetricsMonitor {
let togglesCount: number = 0;
let usersCount: number;
let projectsCount: number;
let environmentsCount: number;
try {
togglesCount = await featureToggleStore.count({
archived: false,
});
usersCount = await userStore.count();
projectsCount = await projectStore.count();
environmentsCount = await environmentStore.count();
// eslint-disable-next-line no-empty
} catch (e) {}
@ -114,6 +125,10 @@ export default class MetricsMonitor {
projectsTotal.reset();
projectsTotal.set(projectsCount);
}
if (environmentsCount) {
environmentsTotal.reset();
environmentsTotal.set(environmentsCount);
}
}
collectStaticCounters();

View File

@ -18,4 +18,5 @@ export interface IEnvironmentStore extends Store<IEnvironment, string> {
delete(name: string): Promise<void>;
disable(environments: IEnvironment[]): Promise<void>;
enable(environments: IEnvironment[]): Promise<void>;
count(): Promise<number>;
}

View File

@ -26,8 +26,12 @@ export default class FakeEnvironmentStore implements IEnvironmentStore {
return Promise.resolve();
}
count(): Promise<number> {
return Promise.resolve(this.environments.length);
}
async getAll(): Promise<IEnvironment[]> {
return this.environments;
return Promise.resolve(this.environments);
}
async exists(name: string): Promise<boolean> {