Skip to content

Commit

Permalink
feat: PC-11814 budget adjustment support for sloctl (#56)
Browse files Browse the repository at this point in the history
## Motivation

Add support for new`BudgetAdjustment` kind.

## Release Notes

New BudgetAdjustment kind which allows customers to schedule recurring
future events that should be excluded from the Error Budget calculations
in their SLOs. This PR introduces new commands such as `sloctl get
budgetadjustment`, `sloctl delete budgetadjustment`

---------

Co-authored-by: kubaceg <jakub.cegielka@nobl9.com>
Co-authored-by: Mateusz Hawrus <mateusz.hawrus@nobl9.com>
  • Loading branch information
3 people authored May 14, 2024
1 parent c3c8a96 commit fb4622d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
1 change: 1 addition & 0 deletions internal/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (r *RootCmd) NewDeleteCmd() *cobra.Command {
{kind: manifest.KindRoleBinding},
{kind: manifest.KindService, aliases: []string{"svc", "svcs"}},
{kind: manifest.KindSLO},
{kind: manifest.KindBudgetAdjustment},
} {
if len(def.plural) == 0 {
def.plural = def.kind.String() + "s"
Expand Down
3 changes: 2 additions & 1 deletion internal/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ To get more details in output use one of the available flags.`,
{Kind: manifest.KindService, Aliases: []string{"svc", "svcs"}},
{Kind: manifest.KindSLO},
{Kind: manifest.KindUserGroup},
{Kind: manifest.KindBudgetAdjustment},
} {
plural := subCmd.Kind.String() + "s"
if len(subCmd.Plural) > 0 {
Expand Down Expand Up @@ -369,7 +370,7 @@ func (g *GetCmd) getObjects(ctx context.Context, args []string, kind manifest.Ki
}
if len(objects) == 0 {
switch kind {
case manifest.KindProject, manifest.KindUserGroup:
case manifest.KindProject, manifest.KindUserGroup, manifest.KindBudgetAdjustment:
fmt.Printf("No resources found.\n")
default:
fmt.Printf("No resources found in '%s' project.\n", g.client.Config.Project)
Expand Down
4 changes: 4 additions & 0 deletions test/delete-by-name.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ setup() {
test_delete_by_name "Project" "${TEST_INPUTS}/project.yaml"
}

@test "budget adjustment" {
test_delete_by_name "BudgetAdjustment" "${TEST_INPUTS}/budgetadjustment.yaml"
}

# Currently we cannot apply user groups and DataExport has very strict
# org limits making it impossible to test with applied objects.
#
Expand Down
9 changes: 7 additions & 2 deletions test/get.bats
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ setup() {
test_get "SLO" "$aliases" "${TEST_INPUTS}/slos.yaml" "$output"
}

@test "budget adjustments" {
aliases="budgetadjustment budgetadjustments"
test_get "BudgetAdjustment" "$aliases" "${TEST_INPUTS}/budgetadjustments.yaml" "$output"
}

@test "agent" {
aliases="agent agents"
test_get "Agent" "$aliases" "${TEST_INPUTS}/agent.yaml" "$output"
Expand Down Expand Up @@ -182,7 +187,7 @@ test_get() {
continue
fi

if [[ "$kind" == "Project" ]]; then
if [[ "$kind" == "Project" ]] || [[ "$kind" == "BudgetAdjustment" ]]; then
# shellcheck disable=2046
run_sloctl get "$alias" $(yq -r .[].metadata.name "$input")
verify_get_success "$output" "$(read_files "$input")"
Expand All @@ -208,7 +213,7 @@ test_get() {
done

for alias in "${aliases[@]}"; do
if [[ "$kind" == "Project" ]] || [[ "$kind" == "UserGroup" ]]; then
if [[ "$kind" == "Project" ]] || [[ "$kind" == "UserGroup" ]] || [[ "$kind" == "BudgetAdjustment" ]]; then
run_sloctl get "$alias" "fake-name-123-321"
assert_success
assert_output "No resources found."
Expand Down
14 changes: 14 additions & 0 deletions test/inputs/delete-by-name/budgetadjustment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: n9/v1alpha
kind: BudgetAdjustment
metadata:
name: newrelic
displayName: NewRelic budget adjustment
spec:
description: Example budget adjustment
firstEventStart: 2024-03-05T05:00:00Z
duration: 2h0m0s
rrule: FREQ=DAILY;INTERVAL=7
filters:
slos:
- name: newrelic-rolling-timeslices-threshold
project: death-star
28 changes: 28 additions & 0 deletions test/inputs/get/budgetadjustments.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- apiVersion: n9/v1alpha
kind: BudgetAdjustment
metadata:
name: tokyo-server
displayName: Tokyo server budget adjustment
spec:
description: Example budget adjustment
firstEventStart: 2024-02-05T05:00:00Z
duration: 1h0m0s
rrule: FREQ=WEEKLY;INTERVAL=1
filters:
slos:
- name: tokyo-server-6-latency
project: death-star
- apiVersion: n9/v1alpha
kind: BudgetAdjustment
metadata:
name: newrelic
displayName: NewRelic budget adjustment
spec:
description: Example budget adjustment
firstEventStart: 2024-03-05T05:00:00Z
duration: 2h0m0s
rrule: FREQ=DAILY;INTERVAL=7
filters:
slos:
- name: newrelic-rolling-timeslices-threshold
project: death-star

0 comments on commit fb4622d

Please sign in to comment.