Skip to content

Commit 43e1972

Browse files
authored
feat: Merge basic metric types (#9)
* Remove v1beta1.singlemetric * singlemetric cleanup * rename chart * update example spec * add projections to v1alpha1 metric type * initially replace v1beta1.CompoundMetric with v1alpha1.Metric * remove compound metric types * replace controllers and handlers * clean up * rename files * fix metrics with no projections * restore spec.target and swtich to gvk
1 parent 250b650 commit 43e1972

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+618
-2643
lines changed

Makefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ dev-local-all:
237237
$(MAKE) dev-secret
238238
$(MAKE) dev-basic-metric
239239
$(MAKE) dev-managed-metric
240-
$(MAKE) dev-v1beta1-singlemetric
241-
$(MAKE) dev-v1beta1-compmetric
242240

243241

244242

@@ -260,11 +258,6 @@ dev-basic-metric:
260258
dev-managed-metric:
261259
kubectl apply -f examples/managed_metric.yaml
262260

263-
264-
.PHONY: dev-v1beta1-singlemetric
265-
dev-v1beta1-singlemetric:
266-
kubectl apply -f examples/v1beta1/singlemetric.yaml
267-
268261
.PHONY: dev-v1beta1-compmetric
269262
dev-v1beta1-compmetric:
270263
kubectl apply -f examples/v1beta1/compmetric.yaml
@@ -311,7 +304,7 @@ helm-chart:
311304
.PHONY: helm-install-local
312305
helm-install-local: docker-build
313306
helm upgrade --install $(PROJECT_FULL_NAME) charts/$(PROJECT_FULL_NAME)/ --set image.repository=$(IMG_BASE) --set image.tag=$(IMG_VERSION) --set image.pullPolicy=Never
314-
$(KIND) load docker-image ${IMG} --name=$(PROJECT_NAME)-dev
307+
$(KIND) load docker-image ${IMG} --name=$(PROJECT_FULL_NAME)-dev
315308

316309

317310

PROJECT

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ resources:
3131
kind: RemoteClusterAccess
3232
path: github.com/SAP/metrics-operator/api/v1alpha1
3333
version: v1alpha1
34-
- api:
35-
crdVersion: v1
36-
namespaced: true
37-
controller: true
38-
domain: metrics.cloud.sap
39-
kind: SingleMetric
40-
path: github.com/SAP/metrics-operator/api/v1beta1
41-
version: v1beta1
4234
- api:
4335
crdVersion: v1
4436
namespaced: true

README.md

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,15 @@ Replace `<operator-namespace>`, `<artifactory-secret-name>`, and `<version>` wit
4747

4848
## Usage
4949

50+
### Metric
5051

51-
### Single Metric
52-
To create a basic metric, deploy a `SingleMetric` resource in your desired namespace. The Metrics Operator will pick up the resource and start monitoring it, periodically sending data points to the configured data sink.
53-
54-
Example `SingleMetric` resource:
55-
56-
```yaml
57-
apiVersion: metrics.cloud.sap/v1beta1
58-
kind: SingleMetric
59-
metadata:
60-
name: single-pod
61-
spec:
62-
name: single-metric-pods
63-
description: Pods
64-
target:
65-
kind: Pod
66-
group: ""
67-
version: v1
68-
frequency: 1 # in minutes
69-
---
70-
```
71-
72-
Apply the metric:
73-
74-
```bash
75-
kubectl apply -f singlemetric.yaml
76-
```
77-
78-
### Compound Metric
79-
80-
Compound metrics have additional capabilities, such as projections. Projections allow you to extract specific fields from the target resource and include them in the metric data.
52+
Metrics have additional capabilities, such as projections. Projections allow you to extract specific fields from the target resource and include them in the metric data.
8153
This can be useful for tracking additional dimensions of the resource, such as fields, labels or annotations. It uses the dot notation to access nested fields.
8254
The projections are then translated to dimensions in the metric.
8355

8456
```yaml
85-
apiVersion: metrics.cloud.sap/v1beta1
86-
kind: CompoundMetric
57+
apiVersion: metrics.cloud.sap/v1alpha
58+
kind: Metric
8759
metadata:
8860
name: comp-pod
8961
spec:
@@ -152,7 +124,7 @@ spec:
152124
### Cluster Access
153125
The Metrics Operator can monitor both the cluster it's deployed in and remote clusters. To monitor a remote cluster, define a `ClusterAccess` resource:
154126

155-
This cluster access resource can be used by `SingleMetric` and `CompoundMetric` resources to monitor resources in the remote cluster.
127+
This cluster access resource can be used by `CompoundMetric` resources to monitor resources in the remote cluster.
156128

157129
```yaml
158130
apiVersion: metrics.cloud.sap/v1beta1

api/v1alpha1/common_types.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package v1alpha1
2+
3+
import "k8s.io/apimachinery/pkg/runtime/schema"
4+
5+
// GroupVersionKind defines the group, version and kind of the object that should be instrumented
6+
type GroupVersionKind struct {
7+
// Define the kind of the object that should be instrumented
8+
Kind string `json:"kind,omitempty"`
9+
// Define the group of your object that should be instrumented
10+
Group string `json:"group,omitempty"`
11+
// Define version of the object you want to be instrumented
12+
Version string `json:"version,omitempty"`
13+
}
14+
15+
func (gvk *GroupVersionKind) GVK() schema.GroupVersionKind {
16+
return schema.GroupVersionKind{
17+
Group: gvk.Group,
18+
Kind: gvk.Kind,
19+
Version: gvk.Version,
20+
}
21+
}

api/v1alpha1/metric_types.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,20 @@ const (
3636
PhasePending PhaseType = "Pending"
3737
)
3838

39-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
40-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
39+
// Projection defines the projection of the metric
40+
type Projection struct {
41+
// Define the name of the field that should be extracted
42+
Name string `json:"name,omitempty"`
43+
44+
// Define the path to the field that should be extracted
45+
FieldPath string `json:"fieldPath,omitempty"`
46+
}
47+
48+
// Dimension defines the dimension of the metric
49+
type Dimension struct {
50+
Name string `json:"name,omitempty"`
51+
Value string `json:"value,omitempty"`
52+
}
4153

4254
// MetricSpec defines the desired state of Metric
4355
type MetricSpec struct {
@@ -46,12 +58,8 @@ type MetricSpec struct {
4658
// Sets the description that will be used to identify the metric in Dynatrace(or other providers)
4759
// +optional
4860
Description string `json:"description,omitempty"`
49-
// Decide which kind the metric should keep track of (needs to be plural version)
50-
Kind string `json:"kind,omitempty"`
51-
// Define the group of your object that should be instrumented (without version at the end)
52-
Group string `json:"group,omitempty"`
53-
// Define version of the object you want to intrsument
54-
Version string `json:"version,omitempty"`
61+
// +kubebuilder:validation:Required
62+
Target GroupVersionKind `json:"target,omitempty"`
5563
// Define labels of your object to adapt filters of the query
5664
// +optional
5765
LabelSelector string `json:"labelSelector,omitempty"`
@@ -63,6 +71,8 @@ type MetricSpec struct {
6371
CheckInterval metav1.Duration `json:"checkInterval,omitempty"`
6472

6573
RemoteClusterAccessFacade `json:",inline"`
74+
75+
Projections []Projection `json:"projections,omitempty"`
6676
}
6777

6878
// MetricObservation represents the latest available observation of an object's state
@@ -72,6 +82,8 @@ type MetricObservation struct {
7282

7383
// The latest value of the metric
7484
LatestValue string `json:"latestValue,omitempty"`
85+
86+
Dimensions []Dimension `json:"dimensions,omitempty"`
7587
}
7688

7789
// GetTimestamp returns the timestamp of the observation
@@ -117,13 +129,11 @@ func (r *Metric) SetConditions(conditions ...metav1.Condition) {
117129
meta.SetStatusCondition(&r.Status.Conditions, c)
118130
}
119131
}
120-
121-
// GvkToString returns the GVK of the metric as a string
122132
func (r *Metric) GvkToString() string {
123-
if r.Spec.Group == "" {
124-
return fmt.Sprintf("/%s, Kind=%s", r.Spec.Version, r.Spec.Kind)
133+
if r.Spec.Target.Group == "" {
134+
return fmt.Sprintf("/%s, Kind=%s", r.Spec.Target.Version, r.Spec.Target.Kind)
125135
}
126-
return fmt.Sprintf("%s/%s, Kind=%s", r.Spec.Group, r.Spec.Version, r.Spec.Kind)
136+
return fmt.Sprintf("%s/%s, Kind=%s", r.Spec.Target.Group, r.Spec.Target.Version, r.Spec.Target.Kind)
127137
}
128138

129139
//+kubebuilder:object:root=true

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)