Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] alert reconciler #102

Merged
merged 4 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
- name: Install Go
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8
with:
go-version: 1.20.x
go-version: 1.22.x
- name: Run build
run: make build
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8
with:
go-version: 1.20.x
go-version: 1.22.x
- name: Generate docs
run: make generate-api-docs
- name: Check for changes
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8
with:
go-version: 1.20.x
go-version: 1.22.x
- name: Running operator and Tests
env:
CORALOGIX_REGION: ${{ secrets.CORALOGIX_REGION }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.20 as builder
FROM golang:1.22 as builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ CRDOC ?= $(LOCALBIN)/crdoc

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.9.2
CONTROLLER_TOOLS_VERSION ?= v0.15.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
46 changes: 22 additions & 24 deletions apis/coralogix/v1alpha1/alert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,26 @@ type AlertSpec struct {
AlertType AlertType `json:"alertType"`
}

func (in *AlertSpec) ExtractCreateAlertRequest(ctx context.Context) (*alerts.CreateAlertRequest, error) {
enabled := wrapperspb.Bool(in.Active)
name := wrapperspb.String(in.Name)
description := wrapperspb.String(in.Description)
severity := AlertSchemaSeverityToProtoSeverity[in.Severity]
metaLabels := expandMetaLabels(in.Labels)
expirationDate := expandExpirationDate(in.ExpirationDate)
showInInsight := expandShowInInsight(in.ShowInInsight)
notificationGroups, err := expandNotificationGroups(ctx, in.NotificationGroups)
func (a *Alert) ExtractCreateAlertRequest(ctx context.Context) (*alerts.CreateAlertRequest, error) {
notificationGroups, err := expandNotificationGroups(ctx, a.Spec.NotificationGroups)
if err != nil {
return nil, err
}
payloadFilters := utils.StringSliceToWrappedStringSlice(in.PayloadFilters)
activeWhen := expandActiveWhen(in.Scheduling)
alertTypeParams := expandAlertType(in.AlertType)

return &alerts.CreateAlertRequest{
Name: name,
Description: description,
IsActive: enabled,
Severity: severity,
MetaLabels: metaLabels,
Expiration: expirationDate,
ShowInInsight: showInInsight,
IsActive: wrapperspb.Bool(a.Spec.Active),
Name: wrapperspb.String(a.Spec.Name),
Description: wrapperspb.String(a.Spec.Description),
Severity: AlertSchemaSeverityToProtoSeverity[a.Spec.Severity],
MetaLabels: expandMetaLabels(a.Spec.Labels),
Expiration: expandExpirationDate(a.Spec.ExpirationDate),
ShowInInsight: expandShowInInsight(a.Spec.ShowInInsight),
NotificationGroups: notificationGroups,
NotificationPayloadFilters: payloadFilters,
ActiveWhen: activeWhen,
Filters: alertTypeParams.filters,
Condition: alertTypeParams.condition,
TracingAlert: alertTypeParams.tracingAlert,
NotificationPayloadFilters: utils.StringSliceToWrappedStringSlice(a.Spec.PayloadFilters),
ActiveWhen: expandActiveWhen(a.Spec.Scheduling),
Filters: expandAlertType(a.Spec.AlertType).filters,
Condition: expandAlertType(a.Spec.AlertType).condition,
TracingAlert: expandAlertType(a.Spec.AlertType).tracingAlert,
}, nil
}

Expand Down Expand Up @@ -3117,6 +3107,14 @@ type Alert struct {
Status AlertStatus `json:"status,omitempty"`
}

func NewAlert() *Alert {
return &Alert{
Spec: AlertSpec{
Labels: make(map[string]string),
},
}
}

//+kubebuilder:object:root=true

// AlertList contains a list of Alert
Expand Down
Loading
Loading