Skip to content

Commit

Permalink
Merge pull request #1202 from pyrra-dev/float-rounding
Browse files Browse the repository at this point in the history
Round target to 5 decimal points
  • Loading branch information
metalmatze authored Jun 29, 2024
2 parents 5da66df + ab68193 commit d723f4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion kubernetes/api/v1alpha1/servicelevelobjective_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ func (in *ServiceLevelObjective) Internal() (slo.Objective, error) {
if err != nil {
return slo.Objective{}, fmt.Errorf("failed to parse objective target: %w", err)
}
// round to 5 decimal places before diving by 100
target = (target * 10000) / 1000000

window, err := model.ParseDuration(in.Spec.Window)
if err != nil {
Expand Down Expand Up @@ -554,7 +556,7 @@ func (in *ServiceLevelObjective) Internal() (slo.Objective, error) {
Labels: ls,
Annotations: in.Annotations,
Description: in.Spec.Description,
Target: target / 100,
Target: target,
Window: window,
Config: string(config),
Alerting: alerting,
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/api/v1alpha1/servicelevelobjective_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ metadata:
prometheus: k8s
role: alert-rules
spec:
target: 99.9
target: 99.999
window: 1w
indicator:
ratio:
Expand All @@ -103,7 +103,7 @@ spec:
"namespace", "monitoring",
),
Description: "",
Target: 0.9990000000000001, // TODO fix this? maybe not /100?
Target: 0.99999,
Window: model.Duration(7 * 24 * time.Hour),
Alerting: slo.Alerting{
Burnrates: true,
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ func (s *objectiveServer) GraphDuration(ctx context.Context, req *connect.Reques

timeseries = append(timeseries,
&objectivesv1alpha1.Timeseries{
Labels: []string{fmt.Sprintf(`{quantile="p%.f"}`, 100*percentile)}, // TODO: Nicer format float
Labels: []string{fmt.Sprintf(`{quantile="p%g"}`, 100*percentile)}, // TODO: Nicer format float
Query: query,
Series: series,
},
Expand Down

0 comments on commit d723f4d

Please sign in to comment.