diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index c8ab49b390..bba0761992 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -2937,7 +2937,7 @@ spec: description: Name of the provider type: string required: - - name + - name type: object query: description: Query represents the query to be run @@ -2951,13 +2951,13 @@ spec: to be applied on the data. Accepted values: p90, p95, p99, max, min, avg, median' enum: - - p90 - - p95 - - p99 - - max - - min - - avg - - median + - p90 + - p95 + - p99 + - max + - min + - avg + - median type: string interval: default: 5m @@ -2968,11 +2968,16 @@ spec: description: Step represents the query resolution step width for the data query type: string + storedResults: + description: StoredResults indicates the upper limit of how many + past results should be stored in the status of a KeptnMetric + maximum: 255 + type: integer type: object required: - - fetchIntervalSeconds - - provider - - query + - fetchIntervalSeconds + - provider + - query type: object status: description: KeptnMetricStatus defines the observed state of KeptnMetric @@ -2981,6 +2986,61 @@ spec: description: ErrMsg represents the error details when the query could not be evaluated type: string + intervalResults: + description: IntervalResults contain a slice of all the interval results + items: + properties: + errMsg: + description: ErrMsg represents the error details when the query + could not be evaluated + type: string + lastUpdated: + description: LastUpdated represents the time when the status + data was last updated + format: date-time + type: string + range: + description: Range represents the time range for which this + data was queried + properties: + aggregation: + description: 'Aggregation defines the type of aggregation + function to be applied on the data. Accepted values: p90, + p95, p99, max, min, avg, median' + enum: + - p90 + - p95 + - p99 + - max + - min + - avg + - median + type: string + interval: + default: 5m + description: Interval specifies the duration of the time + interval for the data query + type: string + step: + description: Step represents the query resolution step width + for the data query + type: string + storedResults: + description: StoredResults indicates the upper limit of + how many past results should be stored in the status of + a KeptnMetric + maximum: 255 + type: integer + type: object + value: + description: Value represents the resulting value + type: string + required: + - lastUpdated + - range + - value + type: object + type: array lastUpdated: description: LastUpdated represents the time when the status data was last updated @@ -2993,10 +3053,6 @@ spec: value: description: Value represents the resulting value type: string - required: - - lastUpdated - - rawValue - - value type: object type: object served: true diff --git a/docs/content/en/docs/crd-ref/metrics/v1alpha3/_index.md b/docs/content/en/docs/crd-ref/metrics/v1alpha3/_index.md index 00c3eb5956..1ba59dd26b 100644 --- a/docs/content/en/docs/crd-ref/metrics/v1alpha3/_index.md +++ b/docs/content/en/docs/crd-ref/metrics/v1alpha3/_index.md @@ -203,6 +203,23 @@ _Appears in:_ | `query` _string_ | Query represents the query to be run. It can include placeholders that are defined using the go template syntax. More info on go templating - https://pkg.go.dev/text/template | +#### IntervalResult + + + + + +_Appears in:_ +- [KeptnMetricStatus](#keptnmetricstatus) + +| Field | Description | +| --- | --- | +| `value` _string_ | Value represents the resulting value | +| `range` _[RangeSpec](#rangespec)_ | Range represents the time range for which this data was queried | +| `lastUpdated` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | LastUpdated represents the time when the status data was last updated | +| `errMsg` _string_ | ErrMsg represents the error details when the query could not be evaluated | + + #### KeptnMetric @@ -269,6 +286,7 @@ _Appears in:_ | `rawValue` _integer array_ | RawValue represents the resulting value in raw format | | `lastUpdated` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | LastUpdated represents the time when the status data was last updated | | `errMsg` _string_ | ErrMsg represents the error details when the query could not be evaluated | +| `intervalResults` _[IntervalResult](#intervalresult) array_ | IntervalResults contain a slice of all the interval results | #### KeptnMetricsProvider @@ -427,6 +445,7 @@ _Appears in:_ RangeSpec defines the time range for which data is to be queried _Appears in:_ +- [IntervalResult](#intervalresult) - [KeptnMetricSpec](#keptnmetricspec) | Field | Description | @@ -434,6 +453,7 @@ _Appears in:_ | `interval` _string_ | Interval specifies the duration of the time interval for the data query | | `step` _string_ | Step represents the query resolution step width for the data query | | `aggregation` _string_ | Aggregation defines the type of aggregation function to be applied on the data. Accepted values: p90, p95, p99, max, min, avg, median | +| `storedResults` _integer_ | StoredResults indicates the upper limit of how many past results should be stored in the status of a KeptnMetric | #### RangeValue diff --git a/helm/chart/templates/keptnmetric-crd.yaml b/helm/chart/templates/keptnmetric-crd.yaml index fe39b8d0c5..f0a52bdea0 100644 --- a/helm/chart/templates/keptnmetric-crd.yaml +++ b/helm/chart/templates/keptnmetric-crd.yaml @@ -225,7 +225,7 @@ spec: description: Name of the provider type: string required: - - name + - name type: object query: description: Query represents the query to be run @@ -239,13 +239,13 @@ spec: to be applied on the data. Accepted values: p90, p95, p99, max, min, avg, median' enum: - - p90 - - p95 - - p99 - - max - - min - - avg - - median + - p90 + - p95 + - p99 + - max + - min + - avg + - median type: string interval: default: 5m @@ -256,11 +256,16 @@ spec: description: Step represents the query resolution step width for the data query type: string + storedResults: + description: StoredResults indicates the upper limit of how many + past results should be stored in the status of a KeptnMetric + maximum: 255 + type: integer type: object required: - - fetchIntervalSeconds - - provider - - query + - fetchIntervalSeconds + - provider + - query type: object status: description: KeptnMetricStatus defines the observed state of KeptnMetric @@ -269,6 +274,61 @@ spec: description: ErrMsg represents the error details when the query could not be evaluated type: string + intervalResults: + description: IntervalResults contain a slice of all the interval results + items: + properties: + errMsg: + description: ErrMsg represents the error details when the query + could not be evaluated + type: string + lastUpdated: + description: LastUpdated represents the time when the status + data was last updated + format: date-time + type: string + range: + description: Range represents the time range for which this + data was queried + properties: + aggregation: + description: 'Aggregation defines the type of aggregation + function to be applied on the data. Accepted values: p90, + p95, p99, max, min, avg, median' + enum: + - p90 + - p95 + - p99 + - max + - min + - avg + - median + type: string + interval: + default: 5m + description: Interval specifies the duration of the time + interval for the data query + type: string + step: + description: Step represents the query resolution step width + for the data query + type: string + storedResults: + description: StoredResults indicates the upper limit of + how many past results should be stored in the status of + a KeptnMetric + maximum: 255 + type: integer + type: object + value: + description: Value represents the resulting value + type: string + required: + - lastUpdated + - range + - value + type: object + type: array lastUpdated: description: LastUpdated represents the time when the status data was last updated @@ -281,10 +341,6 @@ spec: value: description: Value represents the resulting value type: string - required: - - lastUpdated - - rawValue - - value type: object type: object served: true diff --git a/metrics-operator/api/v1alpha3/keptnmetric_types.go b/metrics-operator/api/v1alpha3/keptnmetric_types.go index 5d65858a11..e454a832ea 100644 --- a/metrics-operator/api/v1alpha3/keptnmetric_types.go +++ b/metrics-operator/api/v1alpha3/keptnmetric_types.go @@ -38,13 +38,15 @@ type KeptnMetricSpec struct { // KeptnMetricStatus defines the observed state of KeptnMetric type KeptnMetricStatus struct { // Value represents the resulting value - Value string `json:"value"` + Value string `json:"value,omitempty"` // RawValue represents the resulting value in raw format - RawValue []byte `json:"rawValue"` + RawValue []byte `json:"rawValue,omitempty"` // LastUpdated represents the time when the status data was last updated - LastUpdated metav1.Time `json:"lastUpdated"` + LastUpdated metav1.Time `json:"lastUpdated,omitempty"` // ErrMsg represents the error details when the query could not be evaluated ErrMsg string `json:"errMsg,omitempty"` + // IntervalResults contain a slice of all the interval results + IntervalResults []IntervalResult `json:"intervalResults,omitempty"` } // ProviderRef represents the provider object @@ -63,6 +65,20 @@ type RangeSpec struct { // Aggregation defines the type of aggregation function to be applied on the data. Accepted values: p90, p95, p99, max, min, avg, median // +kubebuilder:validation:Enum:=p90;p95;p99;max;min;avg;median Aggregation string `json:"aggregation,omitempty"` + // StoredResults indicates the upper limit of how many past results should be stored in the status of a KeptnMetric + // +kubebuilder:validation:Maximum:=255 + StoredResults uint `json:"storedResults,omitempty"` +} + +type IntervalResult struct { + // Value represents the resulting value + Value string `json:"value"` + // Range represents the time range for which this data was queried + Range *RangeSpec `json:"range"` + // LastUpdated represents the time when the status data was last updated + LastUpdated metav1.Time `json:"lastUpdated"` + // ErrMsg represents the error details when the query could not be evaluated + ErrMsg string `json:"errMsg,omitempty"` } // +kubebuilder:object:root=true diff --git a/metrics-operator/api/v1alpha3/zz_generated.deepcopy.go b/metrics-operator/api/v1alpha3/zz_generated.deepcopy.go index 0fbae59399..455e123a21 100644 --- a/metrics-operator/api/v1alpha3/zz_generated.deepcopy.go +++ b/metrics-operator/api/v1alpha3/zz_generated.deepcopy.go @@ -284,6 +284,27 @@ func (in *AnalysisValueTemplateSpec) DeepCopy() *AnalysisValueTemplateSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IntervalResult) DeepCopyInto(out *IntervalResult) { + *out = *in + if in.Range != nil { + in, out := &in.Range, &out.Range + *out = new(RangeSpec) + **out = **in + } + in.LastUpdated.DeepCopyInto(&out.LastUpdated) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IntervalResult. +func (in *IntervalResult) DeepCopy() *IntervalResult { + if in == nil { + return nil + } + out := new(IntervalResult) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KeptnMetric) DeepCopyInto(out *KeptnMetric) { *out = *in @@ -373,6 +394,13 @@ func (in *KeptnMetricStatus) DeepCopyInto(out *KeptnMetricStatus) { copy(*out, *in) } in.LastUpdated.DeepCopyInto(&out.LastUpdated) + if in.IntervalResults != nil { + in, out := &in.IntervalResults, &out.IntervalResults + *out = make([]IntervalResult, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnMetricStatus. diff --git a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetrics.yaml b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetrics.yaml index e6941937ef..2a19ffb68a 100644 --- a/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetrics.yaml +++ b/metrics-operator/config/crd/bases/metrics.keptn.sh_keptnmetrics.yaml @@ -241,6 +241,11 @@ spec: description: Step represents the query resolution step width for the data query type: string + storedResults: + description: StoredResults indicates the upper limit of how many + past results should be stored in the status of a KeptnMetric + maximum: 255 + type: integer type: object required: - fetchIntervalSeconds @@ -254,6 +259,61 @@ spec: description: ErrMsg represents the error details when the query could not be evaluated type: string + intervalResults: + description: IntervalResults contain a slice of all the interval results + items: + properties: + errMsg: + description: ErrMsg represents the error details when the query + could not be evaluated + type: string + lastUpdated: + description: LastUpdated represents the time when the status + data was last updated + format: date-time + type: string + range: + description: Range represents the time range for which this + data was queried + properties: + aggregation: + description: 'Aggregation defines the type of aggregation + function to be applied on the data. Accepted values: p90, + p95, p99, max, min, avg, median' + enum: + - p90 + - p95 + - p99 + - max + - min + - avg + - median + type: string + interval: + default: 5m + description: Interval specifies the duration of the time + interval for the data query + type: string + step: + description: Step represents the query resolution step width + for the data query + type: string + storedResults: + description: StoredResults indicates the upper limit of + how many past results should be stored in the status of + a KeptnMetric + maximum: 255 + type: integer + type: object + value: + description: Value represents the resulting value + type: string + required: + - lastUpdated + - range + - value + type: object + type: array lastUpdated: description: LastUpdated represents the time when the status data was last updated @@ -266,10 +326,6 @@ spec: value: description: Value represents the resulting value type: string - required: - - lastUpdated - - rawValue - - value type: object type: object served: true diff --git a/metrics-operator/controllers/metrics/controller_test.go b/metrics-operator/controllers/metrics/controller_test.go index 33718a9835..80d5799d88 100644 --- a/metrics-operator/controllers/metrics/controller_test.go +++ b/metrics-operator/controllers/metrics/controller_test.go @@ -223,7 +223,7 @@ func TestKeptnMetricReconciler_Reconcile(t *testing.T) { Status: metricsapi.KeptnMetricStatus{ ErrMsg: "client_error: client error: 404", Value: "", - RawValue: []byte{}, + RawValue: []byte(nil), }, }, }, @@ -281,7 +281,7 @@ func TestKeptnMetricReconciler_Reconcile(t *testing.T) { Status: metricsapi.KeptnMetricStatus{ ErrMsg: "client_error: client error: 404", Value: "", - RawValue: []byte{}, + RawValue: []byte(nil), }, }, },