-
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
Changes from 1 commit
08b6a92
1163d1f
2efd672
5746492
a574727
ba52d99
5ffe666
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,43 +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 cannot 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.arrayOf(schema.string(), { | ||
minSize: 1, | ||
validate: (values) => { | ||
if (values.map((v) => v.trim()).some((v) => !v.length)) { | ||
return '[dataStreams] list cannot contain empty values'; | ||
} | ||
}, | ||
}), | ||
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: () => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ export const DataUsage = () => { | |
setUrlDateRangeFilter, | ||
} = useDataUsageMetricsUrlParams(); | ||
|
||
const [queryParams, setQueryParams] = useState<UsageMetricsRequestSchemaQueryParams>({ | ||
const [metricsFilters, setMetricsFilters] = useState<UsageMetricsRequestSchemaQueryParams>({ | ||
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. note: This file is renamed in my PR. you can leave it here as it is and I'll resolve conflicts in my PR. |
||
metricTypes: ['storage_retained', 'ingest_rate'], | ||
// TODO: Replace with data streams from /data_streams api | ||
dataStreams: [ | ||
|
@@ -54,28 +54,24 @@ export const DataUsage = () => { | |
|
||
useEffect(() => { | ||
if (!metricTypesFromUrl) { | ||
setUrlMetricTypesFilter( | ||
typeof queryParams.metricTypes !== 'string' | ||
? queryParams.metricTypes.join(',') | ||
: queryParams.metricTypes | ||
); | ||
setUrlMetricTypesFilter(metricsFilters.metricTypes.join(',')); | ||
} | ||
if (!startDateFromUrl || !endDateFromUrl) { | ||
setUrlDateRangeFilter({ startDate: queryParams.from, endDate: queryParams.to }); | ||
setUrlDateRangeFilter({ startDate: metricsFilters.from, endDate: metricsFilters.to }); | ||
} | ||
}, [ | ||
endDateFromUrl, | ||
metricTypesFromUrl, | ||
queryParams.from, | ||
queryParams.metricTypes, | ||
queryParams.to, | ||
metricsFilters.from, | ||
metricsFilters.metricTypes, | ||
metricsFilters.to, | ||
setUrlDateRangeFilter, | ||
setUrlMetricTypesFilter, | ||
startDateFromUrl, | ||
]); | ||
|
||
useEffect(() => { | ||
setQueryParams((prevState) => ({ | ||
setMetricsFilters((prevState) => ({ | ||
...prevState, | ||
metricTypes: metricTypesFromUrl?.length ? metricTypesFromUrl : prevState.metricTypes, | ||
dataStreams: dataStreamsFromUrl?.length ? dataStreamsFromUrl : prevState.dataStreams, | ||
|
@@ -92,7 +88,7 @@ export const DataUsage = () => { | |
refetch: refetchDataUsageMetrics, | ||
} = useGetDataUsageMetrics( | ||
{ | ||
...queryParams, | ||
...metricsFilters, | ||
from: dateRangePickerState.startDate, | ||
to: dateRangePickerState.endDate, | ||
}, | ||
|
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.