mirror of
https://github.com/Unleash/unleash.git
synced 2026-01-05 20:06:22 +01:00
feat: project context field adoption (#11166)
This commit is contained in:
parent
01ec0cc3aa
commit
97d393059f
@ -24,4 +24,5 @@ export interface IContextFieldStore extends Store<IContextField, string> {
|
||||
create(data: IContextFieldDto): Promise<IContextField>;
|
||||
update(data: IContextFieldDto): Promise<IContextField>;
|
||||
count(): Promise<number>;
|
||||
countProjectFields(): Promise<number>;
|
||||
}
|
||||
|
||||
@ -182,5 +182,12 @@ class ContextFieldStore implements IContextFieldStore {
|
||||
.count('*')
|
||||
.then((res) => Number(res[0].count));
|
||||
}
|
||||
|
||||
async countProjectFields(): Promise<number> {
|
||||
return this.db(T.contextFields)
|
||||
.whereNotNull('project')
|
||||
.count('*')
|
||||
.then((res) => Number(res[0].count));
|
||||
}
|
||||
}
|
||||
export default ContextFieldStore;
|
||||
|
||||
@ -7,7 +7,13 @@ import NotFoundError from '../../error/notfound-error.js';
|
||||
|
||||
export default class FakeContextFieldStore implements IContextFieldStore {
|
||||
count(): Promise<number> {
|
||||
return Promise.resolve(0);
|
||||
return Promise.resolve(this.contextFields.length);
|
||||
}
|
||||
|
||||
countProjectFields(): Promise<number> {
|
||||
return Promise.resolve(
|
||||
this.contextFields.filter((field) => field.project).length,
|
||||
);
|
||||
}
|
||||
|
||||
defaultContextFields: IContextField[] = [
|
||||
|
||||
@ -635,6 +635,14 @@ export class InstanceStatsService {
|
||||
);
|
||||
}
|
||||
|
||||
projectContextFieldCount(): Promise<number> {
|
||||
return this.memorize('projectContextFieldCount', () =>
|
||||
this.flagResolver.isEnabled('projectContextFields')
|
||||
? this.contextFieldStore.countProjectFields()
|
||||
: Promise.resolve(0),
|
||||
);
|
||||
}
|
||||
|
||||
strategiesCount(): Promise<number> {
|
||||
return this.memorize('strategiesCount', () =>
|
||||
this.strategyStore.count(),
|
||||
|
||||
@ -427,6 +427,13 @@ export function registerPrometheusMetrics(
|
||||
map: (result) => ({ value: result }),
|
||||
});
|
||||
|
||||
dbMetrics.registerGaugeDbMetric({
|
||||
name: 'project_context_total',
|
||||
help: 'Number of project context fields',
|
||||
query: () => instanceStatsService.projectContextFieldCount(),
|
||||
map: (result) => ({ value: result }),
|
||||
});
|
||||
|
||||
dbMetrics.registerGaugeDbMetric({
|
||||
name: 'strategies_total',
|
||||
help: 'Number of strategies',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user