Skip to content

Commit

Permalink
feat(osko) Too many changes to summarize (#33)
Browse files Browse the repository at this point in the history
* feat(ds): multiple changes in datasource controller
- add EventRecorder
- new function for datasource connection validation

* feat(mimirtool): functional PoC for mimir rules
- PrometheusRule controller is able to reconcile and create rules in
  Mimir

* chore(ratio): ratio rule function optimizations
- minimize code repetition
- use constants for strings that appear more than once
- early return of an error

* feat(osko): So many changes, not able to summarize
- move apis from `apis` folder to the `api` folder, since it is more
  kubebuilder compliant
- add MimirRule type and controller
- create helpers package
- move fuctions responsible for creating the mimir rules and some
  Prometheus rules into helpers package
- add somehow updated high level dependency graph to DESIGN document
- remove obsolete and unused crds

* fix(ci): change apis to api in Dockerfile

* feat(mimir): add MimirRule type
- some other changes in rule creation flow
- fix missing tags in osko_slo_target record rule
- other changes and fixes (hard to track the mess)

* feat(osko): Another batch of undescribeable changes
- remove mimirtool package and moved all function into mimirtool helper
- add debug and pretty output run to Makefile
- changes in MimirRule types
- fix error_budget_rule logic

Signed-off-by: Hy3n4 <hy3nk4@gmail.com>
  • Loading branch information
Hy3n4 authored Dec 1, 2023
1 parent ffacf2e commit dbad6f6
Show file tree
Hide file tree
Showing 48 changed files with 1,693 additions and 931 deletions.
54 changes: 54 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,57 @@ If the target system is unable to reconcile the created [`PrometheusRule`](https
- We should look into how to implement [Multiwindow, Multi-Burn-Rate Alerts](https://sre.google/workbook/alerting-on-slos/#6-multiwindow-multi-burn-rate-alerts) based on the OpenSLO spec
<!-- TODO(fourstepper): a little bookmark here for now, move somewhere else later -->
- [Objectives](https://github.com/OpenSLO/OpenSLO#objectives) are cool

## Design

```mermaid
---
Title: OSKO Dependency Graph
---
flowchart LR;
subgraph userspace
sloObject(SLO)
sliObject(SLI)
dataSourceObject(DataSource)
end
subgraph controllerspace
prometheusRuleObject(PrometheusRule)
end
sloController(SLO Controller)
mimirRuleController(Mimir Rule Controller)
sliController(SLI Controller)
dataSourceController(DataSource Controller)
subgraph external
mimir[Mimir]
cortex[Cortex]
end
cortexRuleController(Optional: Cortex Rule Controller)
cortexRuleController --> |Watch| prometheusRuleObject
cortexRuleController --> |Updates| cortex
mimirRuleController --> |Watch| prometheusRuleObject
mimirRuleController --> |Updates| mimir
sloController --> |Own| sloObject
sloController --> |Watch| sliObject
sloController --> |Watch| dataSourceObject
sloController --> |Own| prometheusRuleObject
sliController --> |Own| sliObject
sliController --> |Watch| dataSourceObject
dataSourceController --> |Own| dataSourceObject
sloObject --> |Reference| sliObject
sliObject --> |Reference| dataSourceObject
%% reference slo -> datasource asi netreba, to bereme na zaklade SLIs ne? Dela to pak
%% hnusnej graf :D, kdyztak zkus odkomentovat
%% sloObject --> |Reference| dataSourceObject
%% prometheusRuleObject --> |Reference| dataSourceObject
```
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY apis/ apis/
COPY api/ api/
COPY internal/ internal/

# Build
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ build: manifests generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go

.PHONY: run-pretty-debug
run-pretty-debug: manifests generate fmt vet ## Run a controller from your host with pretty debug output.
go run ./cmd/main.go --zap-log-level=debug 2>&1 | zap-pretty

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
Expand Down
23 changes: 16 additions & 7 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resources:
domain: openslo
group: openslo
kind: Datasource
path: github.com/oskoperator/osko/apis/openslo/v1
path: github.com/oskoperator/osko/api/openslo/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -25,7 +25,7 @@ resources:
domain: openslo
group: openslo
kind: SLO
path: github.com/oskoperator/osko/apis/openslo/v1
path: github.com/oskoperator/osko/api/openslo/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -34,7 +34,7 @@ resources:
domain: openslo
group: openslo
kind: SLI
path: github.com/oskoperator/osko/apis/openslo/v1
path: github.com/oskoperator/osko/api/openslo/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -43,7 +43,7 @@ resources:
domain: openslo
group: openslo
kind: AlertPolicy
path: github.com/oskoperator/osko/apis/openslo/v1
path: github.com/oskoperator/osko/api/openslo/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -52,7 +52,7 @@ resources:
domain: openslo
group: openslo
kind: AlertCondition
path: github.com/oskoperator/osko/apis/openslo/v1
path: github.com/oskoperator/osko/api/openslo/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -61,15 +61,15 @@ resources:
domain: openslo
group: openslo
kind: AlertNotificationTarget
path: github.com/oskoperator/osko/apis/openslo/v1
path: github.com/oskoperator/osko/api/openslo/v1
version: v1
- api:
crdVersion: v1
namespaced: true
domain: openslo
group: openslo
kind: Service
path: github.com/oskoperator/osko/apis/openslo/v1
path: github.com/oskoperator/osko/api/openslo/v1
version: v1
- controller: true
domain: openslo
Expand All @@ -81,4 +81,13 @@ resources:
group: monitoring.coreos.com
kind: PrometheusRule
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openslo
group: osko
kind: MimirRule
path: github.com/oskoperator/osko/api/osko/v1alpha1
version: v1alpha1
version: "3"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1

import (
osko "github.com/oskoperator/osko/apis/osko/v1alpha1"
osko "github.com/oskoperator/osko/api/osko/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type SLOStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=.status.ready,description="The reason for the current status of the SLO resource"
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=.status.ready,description="The reason for the current status of the SLO resource"
//+kubebuilder:printcolumn:name="Window",type=string,JSONPath=.spec.timeWindow[0].duration,description="The time window for the SLO resource"
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=.metadata.creationTimestamp,description="The time when the SLO resource was created"

Expand Down

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

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package v1alpha1 contains API Schema definitions for the slo-kubernetes-operator v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=slo-kubernetes-operator.openslo
// +groupName=osko.dev
package v1alpha1

import (
Expand All @@ -10,7 +10,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "slo-kubernetes-operator.openslo", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{Group: "osko.dev", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
File renamed without changes.
69 changes: 69 additions & 0 deletions api/osko/v1alpha1/mimirrule_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package v1alpha1

import (
"github.com/prometheus/common/model"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// MimirRuleSpec defines the desired state of MimirRule
type MimirRuleSpec struct {
// Groups is an example field of MimirRule. Edit mimirrule_types.go to remove/update
Groups []RuleGroup `json:"groups"`
}

// MimirRuleStatus defines the observed state of MimirRule
type MimirRuleStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
LastEvaluationTime metav1.Time `json:"lastEvaluationTime,omitempty"`
Ready string `json:"ready,omitempty"`
}

type RuleGroup struct {
Name string `json:"name"`
SourceTenants []string `json:"source_tenants,omitempty"`
Rules []Rule `json:"rules"`
Interval model.Duration `json:"interval,omitempty"`
EvaluationDelay *model.Duration `json:"evaluation_delay,omitempty"`
Limit int `json:"limit,omitempty"`
AlignEvaluationTimeOnInterval bool `json:"align_evaluation_time_on_interval,omitempty"`
}

type Rule struct {
Record string `json:"record,omitempty"`
Alert string `json:"alert,omitempty"`
Expr string `json:"expr"`
For model.Duration `json:"for,omitempty"`
KeepFiringFor model.Duration `json:"keep_firing_for,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=.status.ready,description="The reason for the current status of the MimirRule resource"
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

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

Spec MimirRuleSpec `json:"spec,omitempty"`
Status MimirRuleStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&MimirRule{}, &MimirRuleList{})
}
Loading

0 comments on commit dbad6f6

Please sign in to comment.