Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crd/api/v1alpha1/metricsconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type MetricsContextOptions struct {
// +optional
// +listType=set
AdditionalLabels []string `json:"additionalLabels,omitempty"`
// TTL represents the time-to-live of the metrics collected
// Metrics which have not been updated within the TTL will be removed from export
// +optional
TTL string `json:"ttl,omitempty"`
}

// MetricsNamespaces indicates the namespaces to include or exclude in metric collection
Expand Down
15 changes: 14 additions & 1 deletion crd/api/v1alpha1/validations/validate_metricconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package validations

import (
"fmt"
"time"

"github.com/microsoft/retina/crd/api/v1alpha1"
"github.com/microsoft/retina/pkg/utils"
Expand Down Expand Up @@ -40,6 +41,15 @@ func MetricsSpec(metricsSpec v1alpha1.MetricsSpec) error {
if !utils.IsAdvancedMetric(contextOption.MetricName) {
return fmt.Errorf("%s is not a valid metric", contextOption.MetricName)
}
if contextOption.TTL != "" {
ttl, err := time.ParseDuration(contextOption.TTL)
if err != nil {
return fmt.Errorf("invalid TTL format for metric %s: %v", contextOption.MetricName, err)
}
if ttl < 0 {
return fmt.Errorf("TTL cannot be negative for metric %s", contextOption.MetricName)
}
}
}

err := MetricsNamespaces(metricsSpec.Namespaces)
Expand Down Expand Up @@ -152,10 +162,13 @@ func MetricsContextOptionsCompare(old, new []v1alpha1.MetricsContextOptions) boo
return false
}

if !utils.CompareStringSlice(oldContextOption.AdditionalLabels, newContextOption.AdditionalLabels) {
if oldContextOption.TTL != newContextOption.TTL {
return false
}

if !utils.CompareStringSlice(oldContextOption.AdditionalLabels, newContextOption.AdditionalLabels) {
return false
}
}

return true
Expand Down
159 changes: 159 additions & 0 deletions crd/api/v1alpha1/validations/validate_metricconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,46 @@ func TestMetricsConfiguration(t *testing.T) {
},
wantErr: false,
},
{
name: "valid metrics crd with TTL",
obj: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
TTL: "24h",
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Exclude: []string{"kube-system"},
},
},
},
wantErr: false,
},
{
name: "invalid metrics crd with TTL",
obj: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
TTL: "24",
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Exclude: []string{"kube-system"},
},
},
},
wantErr: true,
},
{
name: "invalid metrics crd with random metric name",
obj: &v1alpha1.MetricsConfiguration{
Expand Down Expand Up @@ -348,6 +388,125 @@ func TestCompare(t *testing.T) {
},
equal: true,
},
{
name: "valid test 6",
old: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
SourceLabels: []string{"ns", "ip", "port"},
TTL: "24h",
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Include: []string{"default", "test"},
Exclude: []string{"kube-system"},
},
},
},
new: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
SourceLabels: []string{"ip", "port", "ns"},
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Include: []string{"default", "test"},
Exclude: []string{"kube-system"},
},
},
},
equal: false,
},
{
name: "valid test 7",
old: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
SourceLabels: []string{"ns", "ip", "port"},
TTL: "24h",
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Include: []string{"default", "test"},
Exclude: []string{"kube-system"},
},
},
},
new: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
SourceLabels: []string{"ip", "port", "ns"},
TTL: "24h",
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Include: []string{"default", "test"},
Exclude: []string{"kube-system"},
},
},
},
equal: true,
},
{
name: "valid test 8",
old: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
SourceLabels: []string{"ns", "ip", "port"},
TTL: "24h",
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Include: []string{"default", "test"},
Exclude: []string{"kube-system"},
},
},
},
new: &v1alpha1.MetricsConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "metricsconfig",
},
Spec: v1alpha1.MetricsSpec{
ContextOptions: []v1alpha1.MetricsContextOptions{
{
MetricName: "drop_count",
SourceLabels: []string{"ip", "port", "ns"},
TTL: "12h",
},
},
Namespaces: v1alpha1.MetricsNamespaces{
Include: []string{"default", "test"},
Exclude: []string{"kube-system"},
},
},
},
equal: false,
},
}

for _, tt := range tests {
Expand Down
5 changes: 5 additions & 0 deletions crd/api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.5
name: captures.retina.sh
spec:
group: retina.sh
Expand Down Expand Up @@ -53,6 +53,14 @@ spec:
should continue for.
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
type: string
interfaces:
description: |-
Interfaces specifies the network interfaces on which to capture packets.
If specified, captures only on the listed interfaces.
If empty, captures on all interfaces by default.
items:
type: string
type: array
maxCaptureSize:
default: 100
description: MaxCaptureSize limits the capture file to MB
Expand Down Expand Up @@ -290,10 +298,14 @@ spec:
description: SecretName is the name of secret which stores
S3 compliant storage access key and secret key.
type: string
required:
- bucket
- secretName
type: object
type: object
required:
- captureConfiguration
- outputConfiguration
type: object
status:
description: CaptureStatus describes the status of the capture.
Expand All @@ -310,16 +322,8 @@ spec:
type: string
conditions:
items:
description: "Condition contains details for one aspect of the current
state of this API Resource.\n---\nThis struct is intended for
direct use as an array at the field path .status.conditions. For
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
observations of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: |-
Expand Down Expand Up @@ -360,12 +364,7 @@ spec:
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.5
name: metricsconfigurations.retina.sh
spec:
group: retina.sh
Expand Down Expand Up @@ -75,6 +75,11 @@ spec:
type: string
type: array
x-kubernetes-list-type: set
ttl:
description: |-
TTL represents the time-to-live of the metrics collected
Metrics which have not been updated within the TTL will be removed from export
type: string
required:
- metricName
type: object
Expand Down Expand Up @@ -136,6 +141,11 @@ spec:
type: string
type: array
x-kubernetes-list-type: set
ttl:
description: |-
TTL represents the time-to-live of the metrics collected
Metrics which have not been updated within the TTL will be removed from export
type: string
required:
- metricName
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.5
name: retinaendpoints.retina.sh
spec:
group: retina.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
controller-gen.kubebuilder.io/version: v0.16.5
name: tracesconfigurations.retina.sh
spec:
group: retina.sh
Expand Down
3 changes: 2 additions & 1 deletion docs/03-Metrics/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ You can enable/disable metrics by including/omitting their Plugin from `enabledP
Via [MetricsConfiguration CRD](../05-Concepts/CRDs/MetricsConfiguration.md), you can further customize the following for your enabled plugins:

- Which metrics to include
- Which metadata to include for a metric.
- Which metadata to include for a metric
- Time-to-live for a metric

**Note**: If you enable [Annotations](./annotations.md), you cannot use the `MetricsConfiguration` CRD to specify which Pods to observe.
2 changes: 2 additions & 0 deletions docs/05-Concepts/CRDs/MetricsConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The `MetricsConfiguration` CRD is defined with the following specifications:
- `destinationLabels`: Represents the destination context labels, such as IP, Pod, port, workload (deployment/replicaset/statefulset/daemonset).
- `metricName`: Indicates the name of the metric.
- `sourceLabels`: Represents the source context labels, such as IP, Pod, port.
- `ttl`: Represents the time-to-live for the metric. If there are no metric updates for a particular set of context labels for this duration the metric will be removed from export. The value of `ttl` must be a valid Golang `time.Duration` string and non-negative. A zero `ttl` (the default) means that metrics are never removed from export.

- **spec.namespaces:** Specifies the namespaces to include or exclude in metric collection. It includes the following properties:
- `exclude`: Specifies namespaces to be excluded from metric collection.
Expand Down Expand Up @@ -51,6 +52,7 @@ spec:
- port
additionalLabels:
- direction
ttl: 24h
- metricName: forward_count
sourceLabels:
- ip
Expand Down
Loading