mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
Add a counter for total number of environments (#1964)
This commit is contained in:
parent
8648649047
commit
4ed05047f3
@ -81,6 +81,13 @@ export default class EnvironmentStore implements IEnvironmentStore {
|
|||||||
await this.db(TABLE).del();
|
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> {
|
async get(key: string): Promise<IEnvironment> {
|
||||||
const row = await this.db<IEnvironmentsTable>(TABLE)
|
const row = await this.db<IEnvironmentsTable>(TABLE)
|
||||||
.where({ name: key })
|
.where({ name: key })
|
||||||
|
@ -40,8 +40,13 @@ export default class MetricsMonitor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { eventStore, featureToggleStore, userStore, projectStore } =
|
const {
|
||||||
stores;
|
eventStore,
|
||||||
|
featureToggleStore,
|
||||||
|
userStore,
|
||||||
|
projectStore,
|
||||||
|
environmentStore,
|
||||||
|
} = stores;
|
||||||
|
|
||||||
client.collectDefaultMetrics();
|
client.collectDefaultMetrics();
|
||||||
|
|
||||||
@ -84,6 +89,10 @@ export default class MetricsMonitor {
|
|||||||
name: 'projects_total',
|
name: 'projects_total',
|
||||||
help: 'Number of projects',
|
help: 'Number of projects',
|
||||||
});
|
});
|
||||||
|
const environmentsTotal = new client.Gauge({
|
||||||
|
name: 'environments_total',
|
||||||
|
help: 'Number of environments',
|
||||||
|
});
|
||||||
|
|
||||||
const clientSdkVersionUsage = new client.Counter({
|
const clientSdkVersionUsage = new client.Counter({
|
||||||
name: 'client_sdk_versions',
|
name: 'client_sdk_versions',
|
||||||
@ -95,12 +104,14 @@ export default class MetricsMonitor {
|
|||||||
let togglesCount: number = 0;
|
let togglesCount: number = 0;
|
||||||
let usersCount: number;
|
let usersCount: number;
|
||||||
let projectsCount: number;
|
let projectsCount: number;
|
||||||
|
let environmentsCount: number;
|
||||||
try {
|
try {
|
||||||
togglesCount = await featureToggleStore.count({
|
togglesCount = await featureToggleStore.count({
|
||||||
archived: false,
|
archived: false,
|
||||||
});
|
});
|
||||||
usersCount = await userStore.count();
|
usersCount = await userStore.count();
|
||||||
projectsCount = await projectStore.count();
|
projectsCount = await projectStore.count();
|
||||||
|
environmentsCount = await environmentStore.count();
|
||||||
// eslint-disable-next-line no-empty
|
// eslint-disable-next-line no-empty
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
@ -114,6 +125,10 @@ export default class MetricsMonitor {
|
|||||||
projectsTotal.reset();
|
projectsTotal.reset();
|
||||||
projectsTotal.set(projectsCount);
|
projectsTotal.set(projectsCount);
|
||||||
}
|
}
|
||||||
|
if (environmentsCount) {
|
||||||
|
environmentsTotal.reset();
|
||||||
|
environmentsTotal.set(environmentsCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collectStaticCounters();
|
collectStaticCounters();
|
||||||
|
@ -18,4 +18,5 @@ export interface IEnvironmentStore extends Store<IEnvironment, string> {
|
|||||||
delete(name: string): Promise<void>;
|
delete(name: string): Promise<void>;
|
||||||
disable(environments: IEnvironment[]): Promise<void>;
|
disable(environments: IEnvironment[]): Promise<void>;
|
||||||
enable(environments: IEnvironment[]): Promise<void>;
|
enable(environments: IEnvironment[]): Promise<void>;
|
||||||
|
count(): Promise<number>;
|
||||||
}
|
}
|
||||||
|
6
src/test/fixtures/fake-environment-store.ts
vendored
6
src/test/fixtures/fake-environment-store.ts
vendored
@ -26,8 +26,12 @@ export default class FakeEnvironmentStore implements IEnvironmentStore {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count(): Promise<number> {
|
||||||
|
return Promise.resolve(this.environments.length);
|
||||||
|
}
|
||||||
|
|
||||||
async getAll(): Promise<IEnvironment[]> {
|
async getAll(): Promise<IEnvironment[]> {
|
||||||
return this.environments;
|
return Promise.resolve(this.environments);
|
||||||
}
|
}
|
||||||
|
|
||||||
async exists(name: string): Promise<boolean> {
|
async exists(name: string): Promise<boolean> {
|
||||||
|
Loading…
Reference in New Issue
Block a user