Skip to content

Commit cf93712

Browse files
committed
Merge branch 'develop' into release/v0.16.0
2 parents ad163c2 + a906f94 commit cf93712

File tree

8 files changed

+72
-29
lines changed

8 files changed

+72
-29
lines changed

frontend/src/container/CreateAlertRule/defaults.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import {
66
defaultMatchType,
77
} from 'types/api/alerts/def';
88

9+
const defaultAlertDescription =
10+
'This alert is fired when the defined metric (current value: {{$value}}) crosses the threshold ({{$threshold}})';
11+
const defaultAlertSummary =
12+
'The rule threshold is set to {{$threshold}}, and the observed metric value is {{$value}}';
13+
14+
const defaultAnnotations = {
15+
description: defaultAlertDescription,
16+
summary: defaultAlertSummary,
17+
};
18+
919
export const alertDefaults: AlertDef = {
1020
alertType: AlertTypes.METRICS_BASED_ALERT,
1121
condition: {
@@ -38,9 +48,7 @@ export const alertDefaults: AlertDef = {
3848
labels: {
3949
severity: 'warning',
4050
},
41-
annotations: {
42-
description: 'A new alert',
43-
},
51+
annotations: defaultAnnotations,
4452
evalWindow: defaultEvalWindow,
4553
};
4654

@@ -85,9 +93,7 @@ export const logAlertDefaults: AlertDef = {
8593
severity: 'warning',
8694
details: `${window.location.protocol}//${window.location.host}/logs`,
8795
},
88-
annotations: {
89-
description: 'A new log-based alert',
90-
},
96+
annotations: defaultAnnotations,
9197
evalWindow: defaultEvalWindow,
9298
};
9399

@@ -132,9 +138,7 @@ export const traceAlertDefaults: AlertDef = {
132138
severity: 'warning',
133139
details: `${window.location.protocol}//${window.location.host}/traces`,
134140
},
135-
annotations: {
136-
description: 'A new trace-based alert',
137-
},
141+
annotations: defaultAnnotations,
138142
evalWindow: defaultEvalWindow,
139143
};
140144

@@ -179,8 +183,6 @@ export const exceptionAlertDefaults: AlertDef = {
179183
severity: 'warning',
180184
details: `${window.location.protocol}//${window.location.host}/exceptions`,
181185
},
182-
annotations: {
183-
description: 'A new exceptions-based alert',
184-
},
186+
annotations: defaultAnnotations,
185187
evalWindow: defaultEvalWindow,
186188
};

frontend/src/container/LogsSearchFilter/useSearchParser.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { getMinMax } from 'container/TopNav/AutoRefresh/config';
2+
import useUrlQuery from 'hooks/useUrlQuery';
23
import history from 'lib/history';
34
import { parseQuery, reverseParser } from 'lib/logql';
45
import { ILogQLParsedQueryItem } from 'lib/logql/types';
56
import isEqual from 'lodash-es/isEqual';
6-
import { useCallback, useEffect } from 'react';
7+
import { useCallback, useEffect, useMemo } from 'react';
78
import { useDispatch, useSelector } from 'react-redux';
89
import { Dispatch } from 'redux';
910
import { AppState } from 'store/reducers';
@@ -27,6 +28,10 @@ export function useSearchParser(): {
2728
const {
2829
searchFilter: { parsedQuery, queryString },
2930
} = useSelector<AppState, ILogsReducer>((store) => store.logs);
31+
32+
const urlQuery = useUrlQuery();
33+
const parsedFilters = useMemo(() => urlQuery.get('q'), [urlQuery]);
34+
3035
const { minTime, maxTime, selectedTime } = useSelector<
3136
AppState,
3237
GlobalReducer
@@ -63,8 +68,12 @@ export function useSearchParser(): {
6368
);
6469

6570
useEffect(() => {
66-
updateQueryString(queryString);
67-
}, [queryString, updateQueryString]);
71+
if (!queryString && parsedFilters) {
72+
updateQueryString(parsedFilters);
73+
} else if (queryString) {
74+
updateQueryString(queryString);
75+
}
76+
}, [queryString, updateQueryString, parsedFilters]);
6877

6978
const updateParsedQuery = useCallback(
7079
(updatedParsedPayload: ILogQLParsedQueryItem[]) => {

pkg/query-service/rules/apiParams.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func testTemplateParsing(rl *PostableRule) (errs []error) {
197197
}
198198

199199
// Trying to parse templates.
200-
tmplData := AlertTemplateData(make(map[string]string), 0)
201-
defs := "{{$labels := .Labels}}{{$value := .Value}}"
200+
tmplData := AlertTemplateData(make(map[string]string), 0, 0)
201+
defs := "{{$labels := .Labels}}{{$value := .Value}}{{$threshold := .Threshold}}"
202202
parseTest := func(text string) error {
203203
tmpl := NewTemplateExpander(
204204
context.TODO(),

pkg/query-service/rules/promRule.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ func (r *PromRule) Condition() *RuleCondition {
108108
return r.ruleCondition
109109
}
110110

111+
func (r *PromRule) targetVal() float64 {
112+
if r.ruleCondition == nil || r.ruleCondition.Target == nil {
113+
return 0
114+
}
115+
116+
return *r.ruleCondition.Target
117+
}
118+
111119
func (r *PromRule) Type() RuleType {
112120
return RuleTypeProm
113121
}
@@ -327,10 +335,10 @@ func (r *PromRule) Eval(ctx context.Context, ts time.Time, queriers *Queriers) (
327335
l[lbl.Name] = lbl.Value
328336
}
329337

330-
tmplData := AlertTemplateData(l, smpl.V)
338+
tmplData := AlertTemplateData(l, smpl.V, r.targetVal())
331339
// Inject some convenience variables that are easier to remember for users
332340
// who are not used to Go's templating system.
333-
defs := "{{$labels := .Labels}}{{$value := .Value}}"
341+
defs := "{{$labels := .Labels}}{{$value := .Value}}{{$threshold := .Threshold}}"
334342

335343
expand := func(text string) string {
336344

pkg/query-service/rules/templates.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
// related to go templating in rule labels and annotations
2222

2323
type tmplQueryRecord struct {
24-
Labels map[string]string
25-
Value float64
24+
Labels map[string]string
25+
Value float64
26+
Threshold float64
2627
}
2728
type tmplQueryResults []*tmplQueryRecord
2829

@@ -200,13 +201,15 @@ func NewTemplateExpander(
200201
}
201202

202203
// AlertTemplateData returns the interface to be used in expanding the template.
203-
func AlertTemplateData(labels map[string]string, value float64) interface{} {
204+
func AlertTemplateData(labels map[string]string, value float64, threshold float64) interface{} {
204205
return struct {
205-
Labels map[string]string
206-
Value float64
206+
Labels map[string]string
207+
Value float64
208+
Threshold float64
207209
}{
208-
Labels: labels,
209-
Value: value,
210+
Labels: labels,
211+
Value: value,
212+
Threshold: threshold,
210213
}
211214
}
212215

pkg/query-service/rules/thresholdRule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,10 @@ func (r *ThresholdRule) Eval(ctx context.Context, ts time.Time, queriers *Querie
673673
l[lbl.Name] = lbl.Value
674674
}
675675

676-
tmplData := AlertTemplateData(l, smpl.V)
676+
tmplData := AlertTemplateData(l, smpl.V, r.targetVal())
677677
// Inject some convenience variables that are easier to remember for users
678678
// who are not used to Go's templating system.
679-
defs := "{{$labels := .Labels}}{{$value := .Value}}"
679+
defs := "{{$labels := .Labels}}{{$value := .Value}}{{$threshold := .Threshold}}"
680680

681681
// utility function to apply go template on labels and annots
682682
expand := func(text string) string {

pkg/query-service/telemetry/ignoredPaths.go renamed to pkg/query-service/telemetry/ignored.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,18 @@ func IgnoredPaths() map[string]struct{} {
1111

1212
return ignoredPaths
1313
}
14+
15+
func ignoreEvents(event string, attributes map[string]interface{}) bool {
16+
17+
if event == TELEMETRY_EVENT_ACTIVE_USER || event == TELEMETRY_EVENT_ACTIVE_USER_PH {
18+
for attr_key, attr_val := range attributes {
19+
20+
if attr_key == "any" && attr_val.(int8) == 0 {
21+
return true
22+
}
23+
24+
}
25+
}
26+
27+
return false
28+
}

pkg/query-service/telemetry/telemetry.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ const IP_NOT_FOUND_PLACEHOLDER = "NA"
4646
const DEFAULT_NUMBER_OF_SERVICES = 6
4747

4848
const HEART_BEAT_DURATION = 6 * time.Hour
49+
4950
const ACTIVE_USER_DURATION = 30 * time.Minute
5051

5152
// const HEART_BEAT_DURATION = 30 * time.Second
5253
// const ACTIVE_USER_DURATION = 30 * time.Second
5354

5455
const RATE_LIMIT_CHECK_DURATION = 1 * time.Minute
55-
const RATE_LIMIT_VALUE = 2
56+
const RATE_LIMIT_VALUE = 1
5657

5758
// const RATE_LIMIT_CHECK_DURATION = 20 * time.Second
5859
// const RATE_LIMIT_VALUE = 5
@@ -301,6 +302,11 @@ func (a *Telemetry) SendEvent(event string, data map[string]interface{}, opts ..
301302
return
302303
}
303304

305+
// drop events with properties matching
306+
if ignoreEvents(event, data) {
307+
return
308+
}
309+
304310
if rateLimitFlag {
305311
if a.rateLimits[event] < RATE_LIMIT_VALUE {
306312
a.rateLimits[event] += 1

0 commit comments

Comments
 (0)