mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-04 13:48:56 +02:00
feat: expose postgres version (#7041)
Adds a postgres_version gauge to allow us to see postgres_version in prometheus and to post it upstream when version checking. Depends on https://github.com/bricks-software/version-function/pull/20 to be merged first to ensure our version-function doesn't crash when given the postgres-version data.
This commit is contained in:
parent
dfc065500d
commit
8aa0616698
@ -14,6 +14,16 @@ export default class SettingStore implements ISettingStore {
|
|||||||
this.logger = getLogger('settings-store.ts');
|
this.logger = getLogger('settings-store.ts');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async postgresVersion(): Promise<string> {
|
||||||
|
try {
|
||||||
|
const showResult = await this.db.raw('SHOW server_version');
|
||||||
|
return showResult?.rows[0]?.server_version || '';
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.warn('Failed to fetch postgres version', e);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async updateRow(name: string, content: any): Promise<void> {
|
async updateRow(name: string, content: any): Promise<void> {
|
||||||
return this.db(TABLE)
|
return this.db(TABLE)
|
||||||
.where('name', name)
|
.where('name', name)
|
||||||
|
@ -21,7 +21,7 @@ import {
|
|||||||
PROJECT_ENVIRONMENT_REMOVED,
|
PROJECT_ENVIRONMENT_REMOVED,
|
||||||
} from './types/events';
|
} from './types/events';
|
||||||
import type { IUnleashConfig } from './types/option';
|
import type { IUnleashConfig } from './types/option';
|
||||||
import type { IUnleashStores } from './types/stores';
|
import type { ISettingStore, IUnleashStores } from './types/stores';
|
||||||
import { hoursToMilliseconds, minutesToMilliseconds } from 'date-fns';
|
import { hoursToMilliseconds, minutesToMilliseconds } from 'date-fns';
|
||||||
import type { InstanceStatsService } from './features/instance-stats/instance-stats-service';
|
import type { InstanceStatsService } from './features/instance-stats/instance-stats-service';
|
||||||
import type { ValidatedClientMetrics } from './features/metrics/shared/schema';
|
import type { ValidatedClientMetrics } from './features/metrics/shared/schema';
|
||||||
@ -651,7 +651,12 @@ export default class MetricsMonitor {
|
|||||||
projectEnvironmentsDisabled.increment({ project_id: project });
|
projectEnvironmentsDisabled.increment({ project_id: project });
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.configureDbMetrics(db, eventBus, schedulerService);
|
await this.configureDbMetrics(
|
||||||
|
db,
|
||||||
|
eventBus,
|
||||||
|
schedulerService,
|
||||||
|
stores.settingStore,
|
||||||
|
);
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@ -660,6 +665,7 @@ export default class MetricsMonitor {
|
|||||||
db: Knex,
|
db: Knex,
|
||||||
eventBus: EventEmitter,
|
eventBus: EventEmitter,
|
||||||
schedulerService: SchedulerService,
|
schedulerService: SchedulerService,
|
||||||
|
settingStore: ISettingStore,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (db?.client) {
|
if (db?.client) {
|
||||||
const dbPoolMin = createGauge({
|
const dbPoolMin = createGauge({
|
||||||
@ -707,6 +713,13 @@ export default class MetricsMonitor {
|
|||||||
'registerPoolMetrics',
|
'registerPoolMetrics',
|
||||||
0, // no jitter
|
0, // no jitter
|
||||||
);
|
);
|
||||||
|
const postgresVersion = await settingStore.postgresVersion();
|
||||||
|
const database_version = createGauge({
|
||||||
|
name: 'postgres_version',
|
||||||
|
help: 'Which version of postgres is running (SHOW server_version)',
|
||||||
|
labelNames: ['version'],
|
||||||
|
});
|
||||||
|
database_version.labels({ version: postgresVersion }).set(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ export interface IFeatureUsageInfo {
|
|||||||
productionChanges30: number;
|
productionChanges30: number;
|
||||||
productionChanges60: number;
|
productionChanges60: number;
|
||||||
productionChanges90: number;
|
productionChanges90: number;
|
||||||
|
postgresVersion: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class VersionService {
|
export default class VersionService {
|
||||||
@ -260,6 +261,7 @@ export default class VersionService {
|
|||||||
featureImports,
|
featureImports,
|
||||||
userActive,
|
userActive,
|
||||||
productionChanges,
|
productionChanges,
|
||||||
|
postgresVersion,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
this.featureToggleStore.count({
|
this.featureToggleStore.count({
|
||||||
archived: false,
|
archived: false,
|
||||||
@ -282,6 +284,7 @@ export default class VersionService {
|
|||||||
this.eventStore.filteredCount({ type: FEATURES_IMPORTED }),
|
this.eventStore.filteredCount({ type: FEATURES_IMPORTED }),
|
||||||
this.userStats(),
|
this.userStats(),
|
||||||
this.productionChanges(),
|
this.productionChanges(),
|
||||||
|
this.postgresVersion(),
|
||||||
]);
|
]);
|
||||||
const versionInfo = await this.getVersionInfo();
|
const versionInfo = await this.getVersionInfo();
|
||||||
const customStrategies =
|
const customStrategies =
|
||||||
@ -315,6 +318,7 @@ export default class VersionService {
|
|||||||
productionChanges30: productionChanges.last30,
|
productionChanges30: productionChanges.last30,
|
||||||
productionChanges60: productionChanges.last60,
|
productionChanges60: productionChanges.last60,
|
||||||
productionChanges90: productionChanges.last90,
|
productionChanges90: productionChanges.last90,
|
||||||
|
postgresVersion,
|
||||||
};
|
};
|
||||||
return featureInfo;
|
return featureInfo;
|
||||||
}
|
}
|
||||||
@ -336,6 +340,10 @@ export default class VersionService {
|
|||||||
return this.getProductionChanges();
|
return this.getProductionChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async postgresVersion(): Promise<string> {
|
||||||
|
return this.settingStore.postgresVersion();
|
||||||
|
}
|
||||||
|
|
||||||
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',
|
||||||
|
@ -8,5 +8,6 @@ export interface ISettingInsert {
|
|||||||
export interface ISettingStore extends Store<any, string> {
|
export interface ISettingStore extends Store<any, string> {
|
||||||
insert<T>(name: string, content: T): Promise<void>;
|
insert<T>(name: string, content: T): Promise<void>;
|
||||||
updateRow(name: string, content: any): Promise<void>;
|
updateRow(name: string, content: any): Promise<void>;
|
||||||
|
postgresVersion(): Promise<string>;
|
||||||
get<T>(name: string): Promise<T | undefined>;
|
get<T>(name: string): Promise<T | undefined>;
|
||||||
}
|
}
|
||||||
|
4
src/test/fixtures/fake-setting-store.ts
vendored
4
src/test/fixtures/fake-setting-store.ts
vendored
@ -38,4 +38,8 @@ export default class FakeSettingStore implements ISettingStore {
|
|||||||
async updateRow(name: string, content: any): Promise<void> {
|
async updateRow(name: string, content: any): Promise<void> {
|
||||||
this.settings.set(name, content);
|
this.settings.set(name, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async postgresVersion(): Promise<string> {
|
||||||
|
return Promise.resolve('fake-postgres-version');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user