Skip to content

Commit d723f4d

Browse files
authored
Merge pull request #1202 from pyrra-dev/float-rounding
Round target to 5 decimal points
2 parents 5da66df + ab68193 commit d723f4d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

kubernetes/api/v1alpha1/servicelevelobjective_types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ func (in *ServiceLevelObjective) Internal() (slo.Objective, error) {
352352
if err != nil {
353353
return slo.Objective{}, fmt.Errorf("failed to parse objective target: %w", err)
354354
}
355+
// round to 5 decimal places before diving by 100
356+
target = (target * 10000) / 1000000
355357

356358
window, err := model.ParseDuration(in.Spec.Window)
357359
if err != nil {
@@ -554,7 +556,7 @@ func (in *ServiceLevelObjective) Internal() (slo.Objective, error) {
554556
Labels: ls,
555557
Annotations: in.Annotations,
556558
Description: in.Spec.Description,
557-
Target: target / 100,
559+
Target: target,
558560
Window: window,
559561
Config: string(config),
560562
Alerting: alerting,

kubernetes/api/v1alpha1/servicelevelobjective_types_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ metadata:
8888
prometheus: k8s
8989
role: alert-rules
9090
spec:
91-
target: 99.9
91+
target: 99.999
9292
window: 1w
9393
indicator:
9494
ratio:
@@ -103,7 +103,7 @@ spec:
103103
"namespace", "monitoring",
104104
),
105105
Description: "",
106-
Target: 0.9990000000000001, // TODO fix this? maybe not /100?
106+
Target: 0.99999,
107107
Window: model.Duration(7 * 24 * time.Hour),
108108
Alerting: slo.Alerting{
109109
Burnrates: true,

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ func (s *objectiveServer) GraphDuration(ctx context.Context, req *connect.Reques
15671567

15681568
timeseries = append(timeseries,
15691569
&objectivesv1alpha1.Timeseries{
1570-
Labels: []string{fmt.Sprintf(`{quantile="p%.f"}`, 100*percentile)}, // TODO: Nicer format float
1570+
Labels: []string{fmt.Sprintf(`{quantile="p%g"}`, 100*percentile)}, // TODO: Nicer format float
15711571
Query: query,
15721572
Series: series,
15731573
},

0 commit comments

Comments
 (0)