Skip to content

Commit 911e98c

Browse files
committed
Fix rebasing boolGauge
1 parent 0750b52 commit 911e98c

File tree

5 files changed

+71
-32
lines changed

5 files changed

+71
-32
lines changed

kubernetes/api/v1alpha1/servicelevelobjective_types.go

+39
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ type ServiceLevelIndicator struct {
9696
// LatencyNative is the indicator that measures a certain percentage to be faster than the expected latency.
9797
// This uses the new native histograms in Prometheus.
9898
LatencyNative *NativeLatencyIndicator `json:"latencyNative,omitempty"`
99+
100+
// +optional
101+
// BoolGauge is the indicator that measures wheter a boolean gauge is
102+
// successul.
103+
BoolGauge *BoolGaugeIndicator `json:"bool_gauge,omitempty"`
99104
}
100105

101106
type Alerting struct {
@@ -140,6 +145,12 @@ type NativeLatencyIndicator struct {
140145
Grouping []string `json:"grouping"`
141146
}
142147

148+
type BoolGaugeIndicator struct {
149+
Query `json:",inline"`
150+
// Total is the metric that returns how many requests there are in total.
151+
Grouping []string `json:"grouping"`
152+
}
153+
143154
// Query contains a PromQL metric.
144155
type Query struct {
145156
Metric string `json:"metric"`
@@ -293,6 +304,33 @@ func (in ServiceLevelObjective) Internal() (slo.Objective, error) {
293304
}
294305
}
295306

307+
var boolGauge *slo.BoolGaugeIndicator
308+
if in.Spec.ServiceLevelIndicator.BoolGauge != nil {
309+
expr, err := parser.ParseExpr(in.Spec.ServiceLevelIndicator.BoolGauge.Metric)
310+
if err != nil {
311+
return slo.Objective{}, err
312+
}
313+
314+
vec, ok := expr.(*parser.VectorSelector)
315+
if !ok {
316+
return slo.Objective{}, fmt.Errorf("bool gauge metric is not a VectorSelector")
317+
}
318+
319+
// Copy the matchers to get rid of the re field for unit testing...
320+
matchers := make([]*labels.Matcher, len(vec.LabelMatchers))
321+
for i, matcher := range vec.LabelMatchers {
322+
matchers[i] = &labels.Matcher{Type: matcher.Type, Name: matcher.Name, Value: matcher.Value}
323+
}
324+
325+
boolGauge = &slo.BoolGaugeIndicator{
326+
Metric: slo.Metric{
327+
Name: vec.Name,
328+
LabelMatchers: matchers,
329+
},
330+
Grouping: in.Spec.ServiceLevelIndicator.BoolGauge.Grouping,
331+
}
332+
}
333+
296334
inCopy := in.DeepCopy()
297335
inCopy.ManagedFields = nil
298336
delete(inCopy.Annotations, "kubectl.kubernetes.io/last-applied-configuration")
@@ -328,6 +366,7 @@ func (in ServiceLevelObjective) Internal() (slo.Objective, error) {
328366
Ratio: ratio,
329367
Latency: latency,
330368
LatencyNative: latencyNative,
369+
BoolGauge: boolGauge,
331370
},
332371
}, nil
333372
}

proto/objectives/v1alpha1/objectives.pb.go

+22-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/objectives/v1alpha1/objectives.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ message Indicator {
4545
oneof options {
4646
Ratio ratio = 1;
4747
Latency latency = 2;
48-
LatencyNative latency_native = 3;
49-
BoolGauge boolGauge = 4;
48+
BoolGauge boolGauge = 3;
49+
LatencyNative latency_native = 4;
5050
}
5151
}
5252

ui/src/proto/objectives/v1alpha1/objectives_pb.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ export declare class Indicator extends Message<Indicator> {
134134
case: "latency";
135135
} | {
136136
/**
137-
* @generated from field: objectives.v1alpha1.LatencyNative latency_native = 3;
137+
* @generated from field: objectives.v1alpha1.BoolGauge boolGauge = 3;
138138
*/
139-
value: LatencyNative;
140-
case: "latencyNative";
139+
value: BoolGauge;
140+
case: "boolGauge";
141141
} | {
142142
/**
143-
* @generated from field: objectives.v1alpha1.BoolGauge boolGauge = 4;
143+
* @generated from field: objectives.v1alpha1.LatencyNative latency_native = 4;
144144
*/
145-
value: BoolGauge;
146-
case: "boolGauge";
145+
value: LatencyNative;
146+
case: "latencyNative";
147147
} | { case: undefined; value?: undefined };
148148

149149
constructor(data?: PartialMessage<Indicator>);

ui/src/proto/objectives/v1alpha1/objectives_pb.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export const Indicator = proto3.makeMessageType(
5050
() => [
5151
{ no: 1, name: "ratio", kind: "message", T: Ratio, oneof: "options" },
5252
{ no: 2, name: "latency", kind: "message", T: Latency, oneof: "options" },
53-
{ no: 3, name: "latency_native", kind: "message", T: LatencyNative, oneof: "options" },
54-
{ no: 4, name: "boolGauge", kind: "message", T: BoolGauge, oneof: "options" },
53+
{ no: 3, name: "boolGauge", kind: "message", T: BoolGauge, oneof: "options" },
54+
{ no: 4, name: "latency_native", kind: "message", T: LatencyNative, oneof: "options" },
5555
],
5656
);
5757

0 commit comments

Comments
 (0)