Skip to content

Commit

Permalink
feat(disruption): custom reporting (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
luphaz authored Nov 3, 2022
1 parent 6916800 commit 4063d4f
Show file tree
Hide file tree
Showing 11 changed files with 449 additions and 80 deletions.
30 changes: 28 additions & 2 deletions api/v1beta1/disruption_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"math/rand"
"os"
"path/filepath"
"reflect"
"time"

chaosapi "github.com/DataDog/chaos-controller/api"
eventtypes "github.com/DataDog/chaos-controller/eventnotifier/types"
chaostypes "github.com/DataDog/chaos-controller/types"
"github.com/DataDog/chaos-controller/utils"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -66,6 +67,31 @@ type DisruptionSpec struct {
DNS DNSDisruptionSpec `json:"dns,omitempty"`
// +nullable
GRPC *GRPCDisruptionSpec `json:"grpc,omitempty"`
// +nullable
Reporting *Reporting `json:"reporting,omitempty"`
}

// Reporting provides additional reporting options in order to send a message to a custom slack channel
// it expect the main controller to have slack notifier enabled
// it expect slack bot to be added to the defined slack channel
type Reporting struct {
// SlackChannel is the destination slack channel to send reporting informations to.
// It's expected to follow slack naming conventions https://api.slack.com/methods/conversations.create#naming or slack channel ID format
// +kubebuilder:validation:MaxLength=80
// +kubebuilder:validation:Pattern=(^[a-z0-9-_]+$)|(^C[A-Z0-9]+$)
// +kubebuilder:validation:Required
// +ddmark:validation:Required=true
SlackChannel string `json:"slackChannel,omitempty"`
// Purpose determines contextual informations about the disruption
// a brief context to determines disruption goal
// +kubebuilder:validation:MinLength=10
// +kubebuilder:validation:Required
// +ddmark:validation:Required=true
Purpose string `json:"purpose,omitempty"`
// MinNotificationType is the minimal notification type we want to receive informations for
// In order of importance it's Info, Success, Warning, Error
// Default level is considered Success, meaning all info will be ignored
MinNotificationType eventtypes.NotificationType `json:"minNotificationType,omitempty"`
}

// EmbeddedChaosAPI includes the library so it can be statically exported to chaosli
Expand Down Expand Up @@ -334,7 +360,7 @@ func ReadUnmarshal(path string) (*Disruption, error) {
return nil, fmt.Errorf("could not open yaml file at %s: %v", fullPath, err)
}

yamlBytes, err := ioutil.ReadAll(yaml)
yamlBytes, err := io.ReadAll(yaml)
if err != nil {
return nil, fmt.Errorf("could not read yaml file: %v ", err)
}
Expand Down
20 changes: 20 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions chart/templates/crds/chaos.datadoghq.com_disruptions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,38 @@ spec:
- activeDuration
- dormantDuration
type: object
reporting:
description: Reporting provides additional reporting options in order
to send a message to a custom slack channel it expect the main controller
to have slack notifier enabled it expect slack bot to be added to
the defined slack channel
nullable: true
properties:
minNotificationType:
description: MinNotificationType is the minimal notification type
we want to receive informations for In order of importance it's
Info, Success, Warning, Error Default level is considered Success,
meaning all info will be ignored
enum:
- Info
- Success
- Warning
- Error
type: string
purpose:
description: Purpose determines contextual informations about
the disruption a brief context to determines disruption goal
minLength: 10
type: string
slackChannel:
description: SlackChannel is the destination slack channel to
send reporting informations to. It's expected to follow slack
naming conventions https://api.slack.com/methods/conversations.create#naming
or slack channel ID format
maxLength: 80
pattern: (^[a-z0-9-_]+$)|(^C[A-Z0-9]+$)
type: string
type: object
selector:
additionalProperties:
type: string
Expand Down
2 changes: 2 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spec:
metadata:
labels:
app: chaos-controller
annotations:
kubectl.kubernetes.io/default-container: manager
spec:
serviceAccount: chaos-controller
containers:
Expand Down
Loading

0 comments on commit 4063d4f

Please sign in to comment.