Skip to content

Commit

Permalink
feat(metrics-operator): add Analysis CRD (#1839)
Browse files Browse the repository at this point in the history
Signed-off-by: realanna <anna.reale@dynatrace.com>
  • Loading branch information
RealAnna committed Aug 9, 2023
1 parent adf4621 commit 9521a16
Show file tree
Hide file tree
Showing 16 changed files with 568 additions and 0 deletions.
68 changes: 68 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 @@ -13,15 +13,35 @@ description: Reference information for metrics.keptn.sh/v1alpha3
Package v1alpha3 contains API Schema definitions for the metrics v1alpha3 API group

### Resource Types
- [Analysis](#analysis)
- [AnalysisDefinition](#analysisdefinition)
- [AnalysisDefinitionList](#analysisdefinitionlist)
- [AnalysisList](#analysislist)
- [KeptnMetric](#keptnmetric)
- [KeptnMetricList](#keptnmetriclist)
- [KeptnMetricsProvider](#keptnmetricsprovider)
- [KeptnMetricsProviderList](#keptnmetricsproviderlist)



#### Analysis



Analysis is the Schema for the analyses API

_Appears in:_
- [AnalysisList](#analysislist)

| Field | Description |
| --- | --- |
| `apiVersion` _string_ | `metrics.keptn.sh/v1alpha3`
| `kind` _string_ | `Analysis`
| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. |
| `spec` _[AnalysisSpec](#analysisspec)_ | |
| `status` _string_ | |


#### AnalysisDefinition


Expand Down Expand Up @@ -71,6 +91,38 @@ _Appears in:_
| `totalScore` _[TotalScore](#totalscore)_ | TotalScore defines the required score for an analysis to be successful |


#### AnalysisList



AnalysisList contains a list of Analysis



| Field | Description |
| --- | --- |
| `apiVersion` _string_ | `metrics.keptn.sh/v1alpha3`
| `kind` _string_ | `AnalysisList`
| `metadata` _[ListMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#listmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. |
| `items` _[Analysis](#analysis) array_ | |


#### AnalysisSpec



AnalysisSpec defines the desired state of Analysis

_Appears in:_
- [Analysis](#analysis)

| Field | Description |
| --- | --- |
| `timeframe` _[Timeframe](#timeframe)_ | Timeframe specifies the range for the corresponding query in the AnalysisValueTemplate |
| `args` _object (keys:string, values:string)_ | Args corresponds to a map of key/value pairs that can be used to substitute placeholders in the AnalysisValueTemplate query. The placeholder must be the capitalized version of the key; i.e. for args foo:bar the query could be "query:percentile(95)?scope=tag(my_foo_label:{{.Foo}})". |
| `analysisDefinition` _[ObjectReference](#objectreference)_ | AnalysisDefinition refers to the AnalysisDefinition, a CRD that stores the AnalysisValuesTemplates |


#### KeptnMetric


Expand Down Expand Up @@ -196,6 +248,7 @@ _Appears in:_


_Appears in:_
- [AnalysisSpec](#analysisspec)
- [Objective](#objective)

| Field | Description |
Expand Down Expand Up @@ -298,6 +351,21 @@ _Appears in:_
| `warning` _[Operator](#operator)_ | Warning defines limits where the result does not pass or fail |


#### Timeframe





_Appears in:_
- [AnalysisSpec](#analysisspec)

| Field | Description |
| --- | --- |
| `from` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | From is the time of start for the query, this field follows RFC3339 time format |
| `to` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | To is the time of end for the query, this field follows RFC3339 time format |


#### TotalScore


Expand Down
93 changes: 93 additions & 0 deletions helm/chart/templates/analysis-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: analyses.metrics.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.12.1
labels:
app.kubernetes.io/part-of: keptn-lifecycle-toolkit
crdGroup: metrics.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "chart.labels" . | nindent 4 }}
spec:
group: metrics.keptn.sh
names:
kind: Analysis
listKind: AnalysisList
plural: analyses
singular: analysis
scope: Namespaced
versions:
- name: v1alpha3
schema:
openAPIV3Schema:
description: Analysis is the Schema for the analyses API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: AnalysisSpec defines the desired state of Analysis
properties:
analysisDefinition:
description: AnalysisDefinition refers to the AnalysisDefinition, a
CRD that stores the AnalysisValuesTemplates
properties:
name:
description: Name of the AnalysisDefinition
type: string
required:
- name
type: object
args:
additionalProperties:
type: string
description: Args corresponds to a map of key/value pairs that can be
used to substitute placeholders in the AnalysisValueTemplate query.
The placeholder must be the capitalized version of the key; i.e. for
args foo:bar the query could be "query:percentile(95)?scope=tag(my_foo_label:{{.Foo}})".
type: object
timeframe:
description: Timeframe specifies the range for the corresponding query
in the AnalysisValueTemplate
properties:
from:
description: From is the time of start for the query, this field
follows RFC3339 time format
format: date-time
type: string
to:
description: To is the time of end for the query, this field follows
RFC3339 time format
format: date-time
type: string
required:
- from
- to
type: object
required:
- analysisDefinition
- timeframe
type: object
status:
type: string
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var (
PhaseCancelled = KeptnPhaseType{LongName: "Cancelled", ShortName: "Cancelled"}
)

// PhaseTraceID is a map storing TraceIDs of OpenTelemetry spans in lifecycle phases
type PhaseTraceID map[string]propagation.MapCarrier

func (pid PhaseTraceID) SetPhaseTraceID(phase string, carrier propagation.MapCarrier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ spec:
description: MapCarrier is a TextMapCarrier that uses a map held
in memory as a storage medium for propagated key-value pairs.
type: object
description: PhaseTraceID is a map storing TraceIDs of OpenTelemetry
spans in lifecycle phases
type: object
postDeploymentEvaluationStatus:
default: Pending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ spec:
description: MapCarrier is a TextMapCarrier that uses a map held
in memory as a storage medium for propagated key-value pairs.
type: object
description: PhaseTraceID is a map storing TraceIDs of OpenTelemetry
spans in lifecycle phases
type: object
postDeploymentEvaluationStatus:
default: Pending
Expand Down
8 changes: 8 additions & 0 deletions metrics-operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ resources:
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: keptn.sh
group: metrics
kind: Analysis
path: github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha3
version: v1alpha3
version: "3"
64 changes: 64 additions & 0 deletions metrics-operator/api/v1alpha3/analysis_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2023.
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 v1alpha3

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// AnalysisSpec defines the desired state of Analysis
type AnalysisSpec struct {
//Timeframe specifies the range for the corresponding query in the AnalysisValueTemplate
Timeframe `json:"timeframe"`
// Args corresponds to a map of key/value pairs that can be used to substitute placeholders in the AnalysisValueTemplate query. The placeholder must be the capitalized version of the key; i.e. for args foo:bar the query could be "query:percentile(95)?scope=tag(my_foo_label:{{.Foo}})".
Args map[string]string `json:"args,omitempty"`
// AnalysisDefinition refers to the AnalysisDefinition, a CRD that stores the AnalysisValuesTemplates
AnalysisDefinition ObjectReference `json:"analysisDefinition"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="AnalysisDefinition",type=string,JSONPath=.spec.analysisDefinition.name

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

Spec AnalysisSpec `json:"spec,omitempty"`
Status string `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

type Timeframe struct {
// From is the time of start for the query, this field follows RFC3339 time format
From metav1.Time `json:"from"`
// To is the time of end for the query, this field follows RFC3339 time format
To metav1.Time `json:"to"`
}

func init() {
SchemeBuilder.Register(&Analysis{}, &AnalysisList{})
}

0 comments on commit 9521a16

Please sign in to comment.