-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Data Usage] updates to metrics api #195640
Merged
neptunian
merged 7 commits into
elastic:main
from
neptunian:data-usage-process-data-autoops
Oct 10, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
08b6a92
process autoops mock data
neptunian 1163d1f
make data_streams required for metrics api
neptunian 2efd672
fix tests
neptunian 5746492
remove object
neptunian a574727
change metrics endpoint from GET to POST and update tests
neptunian ba52d99
Merge branch 'main' into data-usage-process-data-autoops
neptunian 5ffe666
Merge branch 'main' into data-usage-process-data-autoops
neptunian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,51 +37,31 @@ const metricTypesSchema = schema.oneOf( | |
// @ts-expect-error TS2769: No overload matches this call | ||
METRIC_TYPE_VALUES.map((metricType) => schema.literal(metricType)) // Create a oneOf schema for the keys | ||
); | ||
export const UsageMetricsRequestSchema = { | ||
query: schema.object({ | ||
from: DateSchema, | ||
to: DateSchema, | ||
metricTypes: schema.oneOf([ | ||
schema.arrayOf(schema.string(), { | ||
minSize: 1, | ||
validate: (values) => { | ||
if (values.map((v) => v.trim()).some((v) => !v.length)) { | ||
return '[metricTypes] list can not contain empty values'; | ||
} else if (values.map((v) => v.trim()).some((v) => !isValidMetricType(v))) { | ||
return `[metricTypes] must be one of ${METRIC_TYPE_VALUES.join(', ')}`; | ||
} | ||
}, | ||
}), | ||
schema.string({ | ||
validate: (v) => { | ||
if (!v.trim().length) { | ||
return '[metricTypes] must have at least one value'; | ||
} else if (!isValidMetricType(v)) { | ||
return `[metricTypes] must be one of ${METRIC_TYPE_VALUES.join(', ')}`; | ||
} | ||
}, | ||
}), | ||
]), | ||
dataStreams: schema.maybe( | ||
schema.oneOf([ | ||
schema.arrayOf(schema.string(), { | ||
minSize: 1, | ||
validate: (values) => { | ||
if (values.map((v) => v.trim()).some((v) => !v.length)) { | ||
return '[dataStreams] list can not contain empty values'; | ||
} | ||
}, | ||
}), | ||
schema.string({ | ||
validate: (v) => | ||
v.trim().length ? undefined : '[dataStreams] must have at least one value', | ||
}), | ||
]) | ||
), | ||
export const UsageMetricsRequestSchema = schema.object({ | ||
from: DateSchema, | ||
to: DateSchema, | ||
metricTypes: schema.arrayOf(schema.string(), { | ||
minSize: 1, | ||
validate: (values) => { | ||
const trimmedValues = values.map((v) => v.trim()); | ||
if (trimmedValues.some((v) => !v.length)) { | ||
return '[metricTypes] list cannot contain empty values'; | ||
} else if (trimmedValues.some((v) => !isValidMetricType(v))) { | ||
return `[metricTypes] must be one of ${METRIC_TYPE_VALUES.join(', ')}`; | ||
} | ||
}, | ||
}), | ||
}; | ||
dataStreams: schema.arrayOf(schema.string(), { | ||
minSize: 1, | ||
validate: (values) => { | ||
if (values.map((v) => v.trim()).some((v) => !v.length)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same validation here for a string intput instead of array |
||
return '[dataStreams] list cannot contain empty values'; | ||
} | ||
}, | ||
}), | ||
}); | ||
|
||
export type UsageMetricsRequestSchemaQueryParams = TypeOf<typeof UsageMetricsRequestSchema.query>; | ||
export type UsageMetricsRequestSchemaQueryParams = TypeOf<typeof UsageMetricsRequestSchema>; | ||
|
||
export const UsageMetricsResponseSchema = { | ||
body: () => | ||
|
@@ -92,11 +72,40 @@ export const UsageMetricsResponseSchema = { | |
schema.object({ | ||
name: schema.string(), | ||
data: schema.arrayOf( | ||
schema.arrayOf(schema.number(), { minSize: 2, maxSize: 2 }) // Each data point is an array of 2 numbers | ||
schema.object({ | ||
x: schema.number(), | ||
y: schema.number(), | ||
}) | ||
), | ||
}) | ||
) | ||
), | ||
}), | ||
}; | ||
export type UsageMetricsResponseSchemaBody = TypeOf<typeof UsageMetricsResponseSchema.body>; | ||
export type UsageMetricsResponseSchemaBody = Omit< | ||
TypeOf<typeof UsageMetricsResponseSchema.body>, | ||
'metrics' | ||
> & { | ||
metrics: Partial<Record<MetricTypes, MetricSeries[]>>; | ||
}; | ||
export type MetricSeries = TypeOf< | ||
typeof UsageMetricsResponseSchema.body | ||
>['metrics'][MetricTypes][number]; | ||
|
||
export const UsageMetricsAutoOpsResponseSchema = { | ||
body: () => | ||
schema.object({ | ||
metrics: schema.recordOf( | ||
metricTypesSchema, | ||
schema.arrayOf( | ||
schema.object({ | ||
name: schema.string(), | ||
data: schema.arrayOf(schema.arrayOf(schema.number(), { minSize: 2, maxSize: 2 })), | ||
}) | ||
) | ||
), | ||
}), | ||
}; | ||
export type UsageMetricsAutoOpsResponseSchemaBody = TypeOf< | ||
typeof UsageMetricsAutoOpsResponseSchema.body | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also validate a string input instead of an array then the error should say that it expects and array and not a string.
could not parse array value from json input
is not valuable info to fix the request input, IMO.