1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +02:00

Network view not experimental (#3124)

## About the changes
Promoted experimental networkView flag into a configuration that relies
on prometheusApi being configured.

Also, a follow-up on https://github.com/Unleash/unleash/pull/3054 moving
this code to enterprise because it doesn't make sense to maintain this
code in OSS where it's not being used.
This commit is contained in:
Gastón Fournier 2023-02-15 16:24:57 +01:00 committed by GitHub
parent 58f2f834ad
commit f8d30850e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 56 deletions

View File

@ -15,7 +15,7 @@ function AdminMenu() {
const { uiConfig, isEnterprise } = useUiConfig();
const { pathname } = useLocation();
const { isBilling } = useInstanceStatus();
const { flags } = uiConfig;
const { flags, networkViewEnabled } = uiConfig;
const activeTab = pathname.split('/')[2];
@ -99,7 +99,7 @@ function AdminMenu() {
</CenteredNavLink>
}
/>
{flags.networkView && (
{networkViewEnabled && (
<Tab
value="network"
label={

View File

@ -474,7 +474,7 @@ export const adminMenuRoutes: INavigationMenuItem[] = [
path: '/admin/network/*',
title: 'Network',
menu: { adminSettings: true },
flag: 'networkView',
configFlag: 'networkViewEnabled',
},
{
path: '/admin/maintenance',

View File

@ -28,4 +28,5 @@ export const defaultValue: IUiConfig = {
title: 'Source code on GitHub',
},
],
networkViewEnabled: false,
};

View File

@ -13,6 +13,7 @@ export interface IUiConfig {
links: ILinks[];
disablePasswordAuth?: boolean;
emailEnabled?: boolean;
networkViewEnabled: boolean;
maintenanceMode?: boolean;
toast?: IProclamationToast;
@ -38,7 +39,6 @@ export interface IFlags {
UG?: boolean;
ENABLE_DARK_MODE_SUPPORT?: boolean;
embedProxyFrontend?: boolean;
networkView?: boolean;
maintenance?: boolean;
maintenanceMode?: boolean;
messageBanner?: boolean;

View File

@ -77,7 +77,6 @@ exports[`should create default config 1`] = `
"maintenance": false,
"maintenanceMode": false,
"messageBanner": false,
"networkView": false,
"newProjectOverview": false,
"projectStatusApi": false,
"proxyReturnAllToggles": false,
@ -98,7 +97,6 @@ exports[`should create default config 1`] = `
"maintenance": false,
"maintenanceMode": false,
"messageBanner": false,
"networkView": false,
"newProjectOverview": false,
"projectStatusApi": false,
"proxyReturnAllToggles": false,

View File

@ -40,6 +40,9 @@ export const uiConfigSchema = {
strategySegmentsLimit: {
type: 'number',
},
networkViewEnabled: {
type: 'boolean',
},
frontendApiOrigins: {
type: 'array',
items: {

View File

@ -133,6 +133,7 @@ class ConfigController extends Controller {
strategySegmentsLimit: this.config.strategySegmentsLimit,
frontendApiOrigins: frontendSettings.frontendApiOrigins,
versionInfo: this.versionService.getVersionInfo(),
networkViewEnabled: this.config.prometheusApi !== undefined,
disablePasswordAuth,
maintenanceMode,
};

View File

@ -2,7 +2,7 @@ import { applicationSchema } from './schema';
import { APPLICATION_CREATED, CLIENT_REGISTER } from '../../types/events';
import { IApplication } from './models';
import { IUnleashStores } from '../../types/stores';
import { IServerOption, IUnleashConfig } from '../../types/option';
import { IUnleashConfig } from '../../types/option';
import { IEventStore } from '../../types/stores/event-store';
import {
IClientApplication,
@ -19,7 +19,6 @@ import { minutesToMilliseconds, secondsToMilliseconds } from 'date-fns';
import { IClientMetricsStoreV2 } from '../../types/stores/client-metrics-store-v2';
import { clientMetricsSchema } from './schema';
import { PartialSome } from '../../types/partial';
import fetch from 'make-fetch-happen';
export default class ClientInstanceService {
apps = {};
@ -46,10 +45,6 @@ export default class ClientInstanceService {
private announcementInterval: number;
private serverOption: IServerOption;
readonly prometheusApi;
constructor(
{
clientMetricsStoreV2,
@ -67,11 +62,7 @@ export default class ClientInstanceService {
| 'clientInstanceStore'
| 'eventStore'
>,
{
getLogger,
prometheusApi,
server,
}: Pick<IUnleashConfig, 'getLogger' | 'prometheusApi' | 'server'>,
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
bulkInterval = secondsToMilliseconds(5),
announcementInterval = minutesToMilliseconds(5),
) {
@ -81,8 +72,6 @@ export default class ClientInstanceService {
this.clientApplicationsStore = clientApplicationsStore;
this.clientInstanceStore = clientInstanceStore;
this.eventStore = eventStore;
this.prometheusApi = prometheusApi;
this.serverOption = server;
this.logger = getLogger(
'/services/client-metrics/client-instance-service.ts',
);
@ -220,39 +209,6 @@ export default class ClientInstanceService {
await this.clientApplicationsStore.upsert(applicationData);
}
private toEpoch(d: Date) {
return (d.getTime() - d.getMilliseconds()) / 1000;
}
async getRPS(hoursToQuery: number, limit = 10): Promise<any> {
if (!this.prometheusApi) {
this.logger.warn('Prometheus not configured');
return;
}
const timeoutSeconds = 5;
const basePath = this.serverOption.baseUriPath.replace(/\/$/, '');
const pathQuery = `${basePath}/api/.*`;
const step = '5m';
const rpsQuery = `topk(${limit}, irate (http_request_duration_milliseconds_count{path=~"${pathQuery}"} [${step}]))`;
const query = `sum by(appName, endpoint) (label_replace(${rpsQuery}, "endpoint", "$1", "path", "${basePath}(/api/(?:client/)?[^/\*]*).*"))`;
const end = new Date();
const start = new Date();
start.setHours(end.getHours() - hoursToQuery);
const params = `timeout=${timeoutSeconds}s&start=${this.toEpoch(
start,
)}&end=${this.toEpoch(end)}&step=${step}&query=${encodeURI(query)}`;
const url = `${this.prometheusApi}/api/v1/query_range?${params}`;
let metrics;
const response = await fetch(url);
if (response.ok) {
metrics = await response.json();
} else {
throw new Error(response.statusText);
}
return metrics;
}
async removeInstancesOlderThanTwoDays(): Promise<void> {
return this.clientInstanceStore.removeInstancesOlderThanTwoDays();
}

View File

@ -30,10 +30,6 @@ const flags = {
process.env.UNLEASH_EXPERIMENTAL_PROXY_RETURN_ALL_TOGGLES,
false,
),
networkView: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_NETWORK_VIEW,
false,
),
maintenance: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_MAINTENANCE,
false,

View File

@ -3705,6 +3705,9 @@ Stats are divided into current and previous **windows**.
"name": {
"type": "string",
},
"networkViewEnabled": {
"type": "boolean",
},
"segmentValuesLimit": {
"type": "number",
},