Skip to content

Commit

Permalink
Validate if metric name in aggregations is unique. (Graylog2#16097)
Browse files Browse the repository at this point in the history
* Validate if metric name in aggregations is unique.

* Adding changelog.

* Fixing problem when name is empty
  • Loading branch information
linuspahl authored Aug 8, 2023
1 parent 8181238 commit 0a8be6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/issue-11592.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type = "fixed"
message = "Validate in aggregation builder if metric name is unique."

issues = ["11592"]
pulls = ["16097"]

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type MetricError = {
function?: string,
field?: string,
percentile?: string,
name?: string,
};

const hasErrors = <T extends {}> (errors: Array<T>): boolean => errors.filter((error) => Object.keys(error).length > 0).length > 0;
Expand Down Expand Up @@ -56,6 +57,10 @@ const validateMetrics = (values: WidgetConfigFormValues) => {
metricError.percentile = 'Percentile is required.';
}

if (metric.name && values.metrics.filter(({ name }) => name === metric.name).length > 1) {
metricError.name = 'Name must be unique.';
}

return metricError;
});

Expand Down

0 comments on commit 0a8be6c

Please sign in to comment.