Skip to content

Commit

Permalink
feat(mimir): add MimirRule type
Browse files Browse the repository at this point in the history
- 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)

Signed-off-by: Hy3n4 <hy3nk4@gmail.com>
  • Loading branch information
Hy3n4 committed Nov 28, 2023
1 parent d2e5aa2 commit ae1cc49
Show file tree
Hide file tree
Showing 11 changed files with 453 additions and 335 deletions.
2 changes: 1 addition & 1 deletion api/openslo/v1/slo_types.go
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
31 changes: 19 additions & 12 deletions api/osko/v1alpha1/mimirrule_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

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

Expand All @@ -15,28 +16,34 @@ type MimirRuleSpec struct {

// MimirRuleStatus defines the observed state of MimirRule
type MimirRuleStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []metav1.Condition `json:"conditions,omitempty"`
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"`
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 string `json:"for,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
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"

// MimirRule is the Schema for the mimirrules API
type MimirRule struct {
Expand Down
7 changes: 7 additions & 0 deletions api/osko/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion config/crd/bases/openslo.com_slos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
- additionalPrinterColumns:
- description: The reason for the current status of the SLO resource
jsonPath: .status.ready
name: Status
name: Ready
type: string
- description: The time window for the SLO resource
jsonPath: .spec.timeWindow[0].duration
Expand Down
45 changes: 40 additions & 5 deletions config/crd/bases/osko.dev_mimirrules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ spec:
singular: mimirrule
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: The reason for the current status of the MimirRule resource
jsonPath: .status.ready
name: Ready
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: MimirRule is the Schema for the mimirrules API
Expand All @@ -39,6 +44,22 @@ spec:
to remove/update
items:
properties:
align_evaluation_time_on_interval:
type: boolean
evaluation_delay:
description: Duration wraps time.Duration. It is used to parse
the custom duration format from YAML. This type should not
propagate beyond the scope of input/output processing.
format: int64
type: integer
interval:
description: Duration wraps time.Duration. It is used to parse
the custom duration format from YAML. This type should not
propagate beyond the scope of input/output processing.
format: int64
type: integer
limit:
type: integer
name:
type: string
rules:
Expand All @@ -53,7 +74,19 @@ spec:
expr:
type: string
for:
type: string
description: Duration wraps time.Duration. It is used
to parse the custom duration format from YAML. This
type should not propagate beyond the scope of input/output
processing.
format: int64
type: integer
keep_firing_for:
description: Duration wraps time.Duration. It is used
to parse the custom duration format from YAML. This
type should not propagate beyond the scope of input/output
processing.
format: int64
type: integer
labels:
additionalProperties:
type: string
Expand All @@ -80,9 +113,6 @@ spec:
description: MimirRuleStatus defines the observed state of MimirRule
properties:
conditions:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file'
items:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
Expand Down Expand Up @@ -150,6 +180,11 @@ spec:
- type
type: object
type: array
lastEvaluationTime:
format: date-time
type: string
ready:
type: string
type: object
type: object
served: true
Expand Down
12 changes: 12 additions & 0 deletions config/samples/osko_v1alpha1_mimirrule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: osko.openslo/v1alpha1
kind: MimirRule
metadata:
labels:
app.kubernetes.io/name: mimirrule
app.kubernetes.io/instance: mimirrule-sample
app.kubernetes.io/part-of: osko
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: osko
name: mimirrule-sample
spec:
# TODO(user): Add fields here
Loading

0 comments on commit ae1cc49

Please sign in to comment.