mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-18 13:48:58 +02:00
feat: add project collaboration mode to prometheus
This commit is contained in:
parent
ac018447f9
commit
7cded94ece
@ -7,6 +7,7 @@ import {
|
||||
IFlagResolver,
|
||||
IProject,
|
||||
IProjectWithCount,
|
||||
ProjectMode,
|
||||
} from '../types';
|
||||
import {
|
||||
IProjectHealthUpdate,
|
||||
@ -49,6 +50,11 @@ export interface IEnvironmentProjectLink {
|
||||
projectId: string;
|
||||
}
|
||||
|
||||
export interface ProjectModeCount {
|
||||
mode: ProjectMode;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface IProjectMembersCount {
|
||||
count: number;
|
||||
project: string;
|
||||
@ -551,6 +557,28 @@ class ProjectStore implements IProjectStore {
|
||||
.then((res) => Number(res[0].count));
|
||||
}
|
||||
|
||||
async getProjectModeCounts(): Promise<ProjectModeCount[]> {
|
||||
const result: ProjectModeCount[] = await this.db
|
||||
.select(`${SETTINGS_TABLE}.project_mode as mode`)
|
||||
.count(`${TABLE}.id as count`)
|
||||
.from(`${TABLE}`)
|
||||
.join(
|
||||
`${SETTINGS_TABLE}`,
|
||||
`${TABLE}.id`,
|
||||
`${SETTINGS_TABLE}.project`,
|
||||
)
|
||||
.groupBy(`${SETTINGS_TABLE}.project_mode`);
|
||||
return result.map(this.mapProjectModeCount);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
mapProjectModeCount(row): ProjectModeCount {
|
||||
return {
|
||||
mode: row.mode,
|
||||
count: parseInt(row.count, 10),
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
mapLinkRow(row): IEnvironmentProjectLink {
|
||||
return {
|
||||
|
@ -20,6 +20,7 @@ import { ISettingStore } from '../../types/stores/settings-store';
|
||||
import { FEATURES_EXPORTED, FEATURES_IMPORTED } from '../../types';
|
||||
import { CUSTOM_ROOT_ROLE_TYPE } from '../../util';
|
||||
import { type GetActiveUsers } from './getActiveUsers';
|
||||
import { ProjectModeCount } from '../../db/project-store';
|
||||
|
||||
export type TimeRange = 'allTime' | '30d' | '7d';
|
||||
|
||||
@ -30,7 +31,7 @@ export interface InstanceStats {
|
||||
versionEnterprise?: string;
|
||||
users: number;
|
||||
featureToggles: number;
|
||||
projects: number;
|
||||
projects: ProjectModeCount[];
|
||||
contextFields: number;
|
||||
roles: number;
|
||||
customRootRoles: number;
|
||||
@ -152,6 +153,10 @@ export class InstanceStatsService {
|
||||
}
|
||||
}
|
||||
|
||||
getProjectModeCount(): Promise<ProjectModeCount[]> {
|
||||
return this.projectStore.getProjectModeCounts();
|
||||
}
|
||||
|
||||
getToggleCount(): Promise<number> {
|
||||
return this.featureToggleStore.count({
|
||||
archived: false,
|
||||
@ -201,7 +206,7 @@ export class InstanceStatsService {
|
||||
this.getToggleCount(),
|
||||
this.userStore.count(),
|
||||
this.getActiveUsers(),
|
||||
this.projectStore.count(),
|
||||
this.getProjectModeCount(),
|
||||
this.contextFieldStore.count(),
|
||||
this.groupStore.count(),
|
||||
this.roleStore.count(),
|
||||
|
@ -105,6 +105,7 @@ export default class MetricsMonitor {
|
||||
const projectsTotal = new client.Gauge({
|
||||
name: 'projects_total',
|
||||
help: 'Number of projects',
|
||||
labelNames: ['mode'],
|
||||
});
|
||||
const environmentsTotal = new client.Gauge({
|
||||
name: 'environments_total',
|
||||
@ -193,7 +194,11 @@ export default class MetricsMonitor {
|
||||
usersActive90days.set(stats.activeUsers.last90);
|
||||
|
||||
projectsTotal.reset();
|
||||
projectsTotal.set(stats.projects);
|
||||
stats.projects.forEach((projectStat) => {
|
||||
projectsTotal
|
||||
.labels({ mode: projectStat.mode })
|
||||
.set(projectStat.count);
|
||||
});
|
||||
|
||||
environmentsTotal.reset();
|
||||
environmentsTotal.set(stats.environments);
|
||||
|
@ -97,7 +97,11 @@ class InstanceAdminController extends Controller {
|
||||
featureToggles: 29,
|
||||
groups: 3,
|
||||
instanceId: 'ed3861ae-78f9-4e8c-8e57-b57efc15f82b',
|
||||
projects: 1,
|
||||
projects: [
|
||||
{ mode: 'open', count: 5 },
|
||||
{ mode: 'protected', count: 2 },
|
||||
{ mode: 'private', count: 1 },
|
||||
],
|
||||
roles: 5,
|
||||
customRootRoles: 2,
|
||||
customRootRolesInUse: 1,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {
|
||||
IEnvironmentProjectLink,
|
||||
IProjectMembersCount,
|
||||
ProjectModeCount,
|
||||
} from '../../db/project-store';
|
||||
import {
|
||||
IEnvironment,
|
||||
@ -32,21 +33,6 @@ export interface IProjectSettings {
|
||||
featureNamingDescription?: string;
|
||||
}
|
||||
|
||||
export interface IProjectSettingsRow {
|
||||
project_mode: ProjectMode;
|
||||
default_stickiness: string;
|
||||
}
|
||||
|
||||
export interface IProjectEnvironmenDefaultStrategyRow {
|
||||
environment: string;
|
||||
default_strategy: any;
|
||||
}
|
||||
|
||||
export interface IProjectArchived {
|
||||
id: string;
|
||||
archived: boolean;
|
||||
}
|
||||
|
||||
export interface IProjectHealthUpdate {
|
||||
id: string;
|
||||
health: number;
|
||||
@ -115,6 +101,7 @@ export interface IProjectStore extends Store<IProject, string> {
|
||||
projectId: string,
|
||||
environment: string,
|
||||
): Promise<CreateFeatureStrategySchema | null>;
|
||||
|
||||
updateDefaultStrategy(
|
||||
projectId: string,
|
||||
environment: string,
|
||||
@ -122,4 +109,6 @@ export interface IProjectStore extends Store<IProject, string> {
|
||||
): Promise<CreateFeatureStrategySchema>;
|
||||
|
||||
isFeatureLimitReached(id: string): Promise<boolean>;
|
||||
|
||||
getProjectModeCounts(): Promise<ProjectModeCount[]>;
|
||||
}
|
||||
|
5
src/test/fixtures/fake-project-store.ts
vendored
5
src/test/fixtures/fake-project-store.ts
vendored
@ -9,6 +9,7 @@ import NotFoundError from '../../lib/error/notfound-error';
|
||||
import {
|
||||
IEnvironmentProjectLink,
|
||||
IProjectMembersCount,
|
||||
ProjectModeCount,
|
||||
} from 'lib/db/project-store';
|
||||
import { CreateFeatureStrategySchema } from '../../lib/openapi';
|
||||
|
||||
@ -185,4 +186,8 @@ export default class FakeProjectStore implements IProjectStore {
|
||||
isFeatureLimitReached(id: string): Promise<boolean> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
getProjectModeCounts(): Promise<ProjectModeCount[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user