Skip to content

Commit

Permalink
feat: update KeptnMetric to store multiple metrics in status (#1900)
Browse files Browse the repository at this point in the history
Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com>
Signed-off-by: Rakshit Gondwal <98955085+rakshitgondwal@users.noreply.github.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Co-authored-by: Florian Bacher <florian.bacher@dynatrace.com>
  • Loading branch information
rakshitgondwal and bacherfl committed Sep 21, 2023
1 parent f9fc7c4 commit 2252b2d
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 39 deletions.
86 changes: 71 additions & 15 deletions .github/scripts/.helm-tests/default/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -2993,10 +3053,6 @@ spec:
value:
description: Value represents the resulting value
type: string
required:
- lastUpdated
- rawValue
- value
type: object
type: object
served: true
Expand Down
20 changes: 20 additions & 0 deletions docs/content/en/docs/crd-ref/metrics/v1alpha3/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -427,13 +445,15 @@ _Appears in:_
RangeSpec defines the time range for which data is to be queried

_Appears in:_
- [IntervalResult](#intervalresult)
- [KeptnMetricSpec](#keptnmetricspec)

| Field | Description |
| --- | --- |
| `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
Expand Down
86 changes: 71 additions & 15 deletions helm/chart/templates/keptnmetric-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -281,10 +341,6 @@ spec:
value:
description: Value represents the resulting value
type: string
required:
- lastUpdated
- rawValue
- value
type: object
type: object
served: true
Expand Down
22 changes: 19 additions & 3 deletions metrics-operator/api/v1alpha3/keptnmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions metrics-operator/api/v1alpha3/zz_generated.deepcopy.go

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

Loading

0 comments on commit 2252b2d

Please sign in to comment.