Skip to content

Commit 5377c91

Browse files
committed
Convert iife to getter
1 parent 727ce49 commit 5377c91

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_alert_type.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ const getCurrentValueFromAggregations = (aggregations: Aggregation) => {
4242
return value;
4343
};
4444

45+
const getParsedFilterQuery: (filterQuery: string) => Record<string, any> = filterQuery => {
46+
if (!filterQuery) return {};
47+
try {
48+
return JSON.parse(filterQuery).bool;
49+
} catch (e) {
50+
return {
51+
query_string: {
52+
query: filterQuery,
53+
analyze_wildcard: true,
54+
},
55+
};
56+
}
57+
};
58+
4559
const getMetric: (
4660
services: AlertServices,
4761
params: MetricExpressionParams,
@@ -97,20 +111,7 @@ const getMetric: (
97111
}
98112
: baseAggs;
99113

100-
const parsedFilterQuery = filterQuery
101-
? (() => {
102-
try {
103-
return JSON.parse(filterQuery).bool;
104-
} catch (e) {
105-
return {
106-
query_string: {
107-
query: filterQuery,
108-
analyze_wildcard: true,
109-
},
110-
};
111-
}
112-
})()
113-
: {};
114+
const parsedFilterQuery = getParsedFilterQuery(filterQuery);
114115

115116
const searchBody = {
116117
query: {

0 commit comments

Comments
 (0)