mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
fix: return 400 on incorrect client metrics input (#4193)
<!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> Wraps the whole `registerClientMetrics` function with try/catch to return 400 on error ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # [1-1037](https://linear.app/unleash/issue/1-1037/return-4xx-error-for-incorrect-metrics-input) <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? -->  --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
4007ebfffb
commit
6601ef19c2
@ -65,11 +65,14 @@ export default class ClientMetricsController extends Controller {
|
||||
}
|
||||
|
||||
async registerMetrics(req: IAuthRequest, res: Response): Promise<void> {
|
||||
const { body: data, ip: clientIp, user } = req;
|
||||
data.environment = this.metricsV2.resolveMetricsEnvironment(user, data);
|
||||
await this.clientInstanceService.registerInstance(data, clientIp);
|
||||
|
||||
try {
|
||||
const { body: data, ip: clientIp, user } = req;
|
||||
data.environment = this.metricsV2.resolveMetricsEnvironment(
|
||||
user,
|
||||
data,
|
||||
);
|
||||
await this.clientInstanceService.registerInstance(data, clientIp);
|
||||
|
||||
await this.metricsV2.registerClientMetrics(data, clientIp);
|
||||
res.status(202).end();
|
||||
} catch (e) {
|
||||
|
@ -20,6 +20,8 @@ import { collapseHourlyMetrics } from '../../util/collapseHourlyMetrics';
|
||||
import { LastSeenService } from './last-seen-service';
|
||||
import { generateHourBuckets } from '../../util/time-utils';
|
||||
import { ClientMetricsSchema } from 'lib/openapi';
|
||||
import { nameSchema } from '../../schema/feature-schema';
|
||||
import { BadDataError } from '../../error';
|
||||
|
||||
export default class ClientMetricsServiceV2 {
|
||||
private config: IUnleashConfig;
|
||||
@ -81,6 +83,14 @@ export default class ClientMetricsServiceV2 {
|
||||
),
|
||||
);
|
||||
|
||||
for (const toggle of toggleNames) {
|
||||
if (!(await nameSchema.validateAsync({ name: toggle }))) {
|
||||
throw new BadDataError(
|
||||
`Invalid feature toggle name "${toggle}"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug(`got metrics from ${clientIp}`);
|
||||
|
||||
const clientMetrics: IClientMetricsEnv[] = toggleNames.map((name) => ({
|
||||
|
Loading…
Reference in New Issue
Block a user