mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
chore: Move rps endpoint to pro (#3054)
## About the changes Network view is part of our cloud offering.
This commit is contained in:
parent
0656fddbc4
commit
ad57ee84e6
@ -12,9 +12,6 @@ async function getSetup() {
|
||||
preRouterHook: perms.hook,
|
||||
});
|
||||
const services = createServices(stores, config);
|
||||
jest.spyOn(services.clientInstanceService, 'getRPS').mockImplementation(
|
||||
async () => {},
|
||||
);
|
||||
const app = await getApp(config, stores, services);
|
||||
|
||||
return {
|
||||
@ -32,14 +29,12 @@ async function getSetup() {
|
||||
let stores;
|
||||
let request;
|
||||
let destroy;
|
||||
let config;
|
||||
|
||||
beforeEach(async () => {
|
||||
const setup = await getSetup();
|
||||
stores = setup.stores;
|
||||
request = setup.request;
|
||||
destroy = setup.destroy;
|
||||
config = setup.config;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -118,20 +113,3 @@ test('should delete application', () => {
|
||||
.delete(`/api/admin/metrics/applications/${appName}`)
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
test('/api/admin/metrics/rps with flag disabled', () => {
|
||||
return request.get('/api/admin/metrics/rps').expect(404);
|
||||
});
|
||||
|
||||
test('/api/admin/metrics/rps should return data with flag enabled', () => {
|
||||
const mockedResponse = {};
|
||||
config.experimental.flags.networkView = true;
|
||||
expect(config.flagResolver.isEnabled('networkView')).toBeTruthy();
|
||||
return request
|
||||
.get('/api/admin/metrics/rps')
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
const metrics = res.body;
|
||||
expect(metrics).toStrictEqual(mockedResponse);
|
||||
});
|
||||
});
|
||||
|
@ -10,15 +10,10 @@ import { createResponseSchema } from '../../openapi/util/create-response-schema'
|
||||
import { ApplicationSchema } from '../../openapi/spec/application-schema';
|
||||
import { ApplicationsSchema } from '../../openapi/spec/applications-schema';
|
||||
import { emptyResponse } from '../../openapi/util/standard-responses';
|
||||
import { RequestsPerSecondSegmentedSchema } from 'lib/openapi/spec/requests-per-second-segmented-schema';
|
||||
import { IFlagResolver } from 'lib/types';
|
||||
|
||||
type RpsError = string;
|
||||
class MetricsController extends Controller {
|
||||
private logger: Logger;
|
||||
|
||||
private flagResolver: IFlagResolver;
|
||||
|
||||
private clientInstanceService: ClientInstanceService;
|
||||
|
||||
constructor(
|
||||
@ -30,7 +25,6 @@ class MetricsController extends Controller {
|
||||
) {
|
||||
super(config);
|
||||
this.logger = config.getLogger('/admin-api/metrics.ts');
|
||||
this.flagResolver = config.flagResolver;
|
||||
|
||||
this.clientInstanceService = clientInstanceService;
|
||||
|
||||
@ -102,24 +96,6 @@ class MetricsController extends Controller {
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
this.route({
|
||||
method: 'get',
|
||||
path: '/rps',
|
||||
handler: this.getRps,
|
||||
permission: NONE,
|
||||
middleware: [
|
||||
openApiService.validPath({
|
||||
tags: ['Metrics'],
|
||||
operationId: 'getRequestsPerSecond',
|
||||
responses: {
|
||||
200: createResponseSchema(
|
||||
'requestsPerSecondSegmentedSchema',
|
||||
),
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
async deprecated(req: Request, res: Response): Promise<void> {
|
||||
@ -176,23 +152,5 @@ class MetricsController extends Controller {
|
||||
);
|
||||
res.json(appDetails);
|
||||
}
|
||||
|
||||
async getRps(
|
||||
req: Request,
|
||||
res: Response<RequestsPerSecondSegmentedSchema | RpsError>,
|
||||
): Promise<void> {
|
||||
if (!this.flagResolver.isEnabled('networkView')) {
|
||||
res.status(404).send('Not enabled');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const hoursToQuery = 6;
|
||||
const rps = await this.clientInstanceService.getRPS(hoursToQuery);
|
||||
res.json(rps || {});
|
||||
} catch (err) {
|
||||
this.logger.error('Failed to fetch RPS metrics', err);
|
||||
res.status(500).send('Error fetching RPS metrics');
|
||||
}
|
||||
}
|
||||
}
|
||||
export default MetricsController;
|
||||
|
@ -5344,26 +5344,6 @@ If the provided project does not exist, the list of events will be empty.",
|
||||
],
|
||||
},
|
||||
},
|
||||
"/api/admin/metrics/rps": {
|
||||
"get": {
|
||||
"operationId": "getRequestsPerSecond",
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/requestsPerSecondSegmentedSchema",
|
||||
},
|
||||
},
|
||||
},
|
||||
"description": "requestsPerSecondSegmentedSchema",
|
||||
},
|
||||
},
|
||||
"tags": [
|
||||
"Metrics",
|
||||
],
|
||||
},
|
||||
},
|
||||
"/api/admin/playground": {
|
||||
"post": {
|
||||
"description": "Use the provided \`context\`, \`environment\`, and \`projects\` to evaluate toggles on this Unleash instance. Returns a list of all toggles that match the parameters and what they evaluate to. The response also contains the input parameters that were provided.",
|
||||
|
Loading…
Reference in New Issue
Block a user