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

feat: initial alerting support #1420

Merged
merged 26 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
71828d2
feat: initial alerting support
theSuess Feb 13, 2024
ff8aa9e
fix: correctly set timeout parameter for generated client
theSuess Feb 16, 2024
3e7846c
chore: fix linting issues
theSuess Feb 16, 2024
9d09093
match makefile with golangci-lint
NissesSenap Feb 18, 2024
bef3346
ignore lint errors
NissesSenap Feb 18, 2024
d668c98
gofumpt
NissesSenap Feb 18, 2024
82fe550
add correct matchLabel example
NissesSenap Feb 19, 2024
5a106ff
fix: ignore status updates on alertrulegroups
theSuess Feb 20, 2024
e3e12d7
feat: add folderSelector to grafanaalertrulegroup
theSuess Feb 21, 2024
b44d7c7
fix: ignore finalization when folder no longer exists
theSuess Feb 21, 2024
ab8f4ff
test: add e2e test for alertrulegroups
theSuess Feb 21, 2024
bc64dc1
fix: add linting exception for insecure tls
theSuess Feb 21, 2024
3fc7edc
fix: use constructor for instrumented roundtripper
theSuess Feb 21, 2024
4076eb8
fix: check if folder exists before creation
theSuess Feb 21, 2024
4bcee25
feat: use validation rules to enforce exclusivity
theSuess Feb 23, 2024
e5aef4b
docs: add docs for alert rule groups
theSuess Feb 27, 2024
991fede
docs: add section on finalizers
theSuess Feb 27, 2024
8744119
refactor: use folderRef instead of folderSelector
theSuess Feb 28, 2024
20c4de2
feat: add AllowCrossNamespace parameter
theSuess Feb 28, 2024
4287d88
fix: use folderRef in examples
theSuess Feb 29, 2024
c67b1cb
fix: add generated deepcopy
theSuess Feb 29, 2024
e0deca0
make consistent with other rbac
NissesSenap Mar 5, 2024
35aa1b6
run make bundle/redhat to have less changes
NissesSenap Mar 5, 2024
b00b1be
remove the last labels
NissesSenap Mar 5, 2024
4869fb3
refactor: remove obsolete function
theSuess Mar 11, 2024
40e32cb
feat: remove finalizer when no instances match
theSuess Mar 11, 2024
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/pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v4.0.0
with:
version: "v1.55.2"
version: "v1.56.2"

test:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ golangci:
ifeq (, $(shell which golangci-lint))
@{ \
set -e ;\
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 ;\
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2 ;\
}
GOLANGCI=$(GOBIN)/golangci-lint
else
Expand All @@ -283,7 +283,7 @@ gofumpt:
ifeq (, $(shell which gofumpt))
@{ \
set -e ;\
go install mvdan.cc/gofumpt@v0.4.0 ;\
go install mvdan.cc/gofumpt@v0.6.0 ;\
}
GOFUMPT=$(GOBIN)/gofumpt
else
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ resources:
kind: GrafanaFolder
path: github.com/grafana/grafana-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: integreatly.org
group: grafana
kind: GrafanaAlertRuleGroup
path: github.com/grafana/grafana-operator/api/v1beta1
version: v1beta1
version: "3"
137 changes: 137 additions & 0 deletions api/v1beta1/grafanaalertrulegroup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
Copyright 2022.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
"github.com/grafana/grafana-openapi-client-go/models"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GrafanaAlertRuleGroupSpec defines the desired state of GrafanaAlertRuleGroup
// +kubebuilder:validation:XValidation:rule="(has(self.folderUID) && !(has(self.folderRef))) || (has(self.folderRef) && !(has(self.folderUID)))", message="Only one of FolderUID or FolderRef can be set"
type GrafanaAlertRuleGroupSpec struct {
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
// +kubebuilder:default="10m"
ResyncPeriod metav1.Duration `json:"resyncPeriod,omitempty"`

// selects Grafanas for import
InstanceSelector *metav1.LabelSelector `json:"instanceSelector"`

// UID of the folder containing this rule group
// Overrides the FolderSelector
FolderUID string `json:"folderUID,omitempty"`

// Match GrafanaFolders CRs to infer the uid
FolderRef string `json:"folderRef,omitempty"`

Rules []AlertRule `json:"rules"`

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
// +kubebuilder:validation:Required
Interval metav1.Duration `json:"interval"`

// +optional
AllowCrossNamespaceImport *bool `json:"allowCrossNamespaceImport,omitempty"`
}

// AlertRule defines a specific rule to be evaluated. It is based on the upstream model with some k8s specific type mappings
type AlertRule struct {
Annotations map[string]string `json:"annotations,omitempty"`

Condition string `json:"condition"`

// +kubebuilder:validation:Required
Data []*AlertQuery `json:"data"`

// +kubebuilder:validation:Enum=OK;Alerting;Error
ExecErrState string `json:"execErrState"`

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
// +kubebuilder:validation:Required
For *metav1.Duration `json:"for"`

IsPaused bool `json:"isPaused,omitempty"`

Labels map[string]string `json:"labels,omitempty"`

// +kubebuilder:validation:Enum=Alerting;NoData;OK
NoDataState *string `json:"noDataState"`

// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=190
// +kubebuilder:example="Always firing"
Title string `json:"title"`

// +kubebuilder:validation:Pattern="^[a-zA-Z0-9-_]+$"
UID string `json:"uid"`
}

type AlertQuery struct {
// Grafana data source unique identifier; it should be '__expr__' for a Server Side Expression operation.
DatasourceUID string `json:"datasourceUid,omitempty"`

// JSON is the raw JSON query and includes the above properties as well as custom properties.
Model *apiextensions.JSON `json:"model,omitempty"`

// QueryType is an optional identifier for the type of query.
// It can be used to distinguish different types of queries.
QueryType string `json:"queryType,omitempty"`

// RefID is the unique identifier of the query, set by the frontend call.
RefID string `json:"refId,omitempty"`

// relative time range
RelativeTimeRange *models.RelativeTimeRange `json:"relativeTimeRange,omitempty"`
}

// GrafanaAlertRuleGroupStatus defines the observed state of GrafanaAlertRuleGroup
type GrafanaAlertRuleGroupStatus struct {
Conditions []metav1.Condition `json:"conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// GrafanaAlertRuleGroup is the Schema for the grafanaalertrulegroups API
type GrafanaAlertRuleGroup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GrafanaAlertRuleGroupSpec `json:"spec,omitempty"`
Status GrafanaAlertRuleGroupStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// GrafanaAlertRuleGroupList contains a list of GrafanaAlertRuleGroup
type GrafanaAlertRuleGroupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GrafanaAlertRuleGroup `json:"items"`
}

func init() {
SchemeBuilder.Register(&GrafanaAlertRuleGroup{}, &GrafanaAlertRuleGroupList{})
}
192 changes: 192 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.

Loading