Skip to content

Commit 5645e70

Browse files
committed
Enable limit name in prometheus metrics
1 parent bb16f15 commit 5645e70

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

api/v1alpha1/limitador_types.go

+7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ type LimitadorSpec struct {
7676
// +optional
7777
RateLimitHeaders *RateLimitHeadersType `json:"rateLimitHeaders,omitempty"`
7878

79+
// +optional
80+
Telemetry *Telemetry `json:"telemetry,omitempty"`
81+
7982
// +optional
8083
Limits []RateLimit `json:"limits,omitempty"`
8184

@@ -149,6 +152,10 @@ type LimitadorList struct {
149152
// +kubebuilder:validation:Enum=NONE;DRAFT_VERSION_03
150153
type RateLimitHeadersType string
151154

155+
// Telemetry defines the level of metrics Limitador will expose to the user
156+
// +kubebuilder:validation:Enum=basic;exhaustive
157+
type Telemetry string
158+
152159
// Storage contains the options for Limitador counters database or in-memory data storage
153160
type Storage struct {
154161
// +optional

bundle/manifests/limitador-operator.clusterserviceversion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ metadata:
3737
capabilities: Basic Install
3838
categories: Integration & Delivery
3939
containerImage: quay.io/kuadrant/limitador-operator:latest
40-
createdAt: "2023-11-08T14:01:55Z"
40+
createdAt: "2023-11-08T14:12:13Z"
4141
operators.operatorframework.io/builder: operator-sdk-v1.28.1
4242
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
4343
repository: https://github.com/Kuadrant/limitador-operator

bundle/manifests/limitador.kuadrant.io_limitadors.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,13 @@ spec:
11781178
type: object
11791179
type: object
11801180
type: object
1181+
telemetry:
1182+
description: Telemetry defines the level of metrics Limitador will
1183+
expose to the user
1184+
enum:
1185+
- basic
1186+
- exhaustive
1187+
type: string
11811188
version:
11821189
type: string
11831190
type: object

config/crd/bases/limitador.kuadrant.io_limitadors.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,13 @@ spec:
11791179
type: object
11801180
type: object
11811181
type: object
1182+
telemetry:
1183+
description: Telemetry defines the level of metrics Limitador will
1184+
expose to the user
1185+
enum:
1186+
- basic
1187+
- exhaustive
1188+
type: string
11821189
version:
11831190
type: string
11841191
type: object

controllers/limitador_controller_test.go

+63-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ var _ = Describe("Limitador controller", func() {
567567
})
568568
})
569569

570-
Context("Reconciling command line args", func() {
570+
Context("Reconciling command line args for rate limit headers", func() {
571571
var limitadorObj *limitadorv1alpha1.Limitador
572572

573573
BeforeEach(func() {
@@ -629,6 +629,68 @@ var _ = Describe("Limitador controller", func() {
629629
})
630630
})
631631

632+
Context("Reconciling command line args for telemetry", func() {
633+
var limitadorObj *limitadorv1alpha1.Limitador
634+
635+
BeforeEach(func() {
636+
limitadorObj = newLimitador()
637+
638+
Expect(k8sClient.Create(context.TODO(), limitadorObj)).Should(Succeed())
639+
})
640+
641+
AfterEach(func() {
642+
err := k8sClient.Delete(context.TODO(), limitadorObj, deletePropagationPolicy)
643+
Expect(err == nil || errors.IsNotFound(err))
644+
})
645+
646+
It("Should modify the limitador deployment command line args", func() {
647+
updatedLimitador := limitadorv1alpha1.Limitador{}
648+
Eventually(func() bool {
649+
err := k8sClient.Get(
650+
context.TODO(),
651+
types.NamespacedName{
652+
Namespace: LimitadorNamespace,
653+
Name: limitadorObj.Name,
654+
},
655+
&updatedLimitador)
656+
657+
if err != nil {
658+
return false
659+
}
660+
661+
if updatedLimitador.Spec.Telemetry != nil {
662+
return false
663+
}
664+
telemetry := limitadorv1alpha1.Telemetry("exhaustive")
665+
updatedLimitador.Spec.Telemetry = &telemetry
666+
return k8sClient.Update(context.TODO(), &updatedLimitador) == nil
667+
}, timeout, interval).Should(BeTrue())
668+
669+
Eventually(func() bool {
670+
updatedLimitadorDeployment := appsv1.Deployment{}
671+
err := k8sClient.Get(
672+
context.TODO(),
673+
types.NamespacedName{
674+
Namespace: LimitadorNamespace,
675+
Name: limitadorObj.Name,
676+
},
677+
&updatedLimitadorDeployment)
678+
679+
if err != nil {
680+
return false
681+
}
682+
683+
return reflect.DeepEqual(updatedLimitadorDeployment.Spec.Template.Spec.Containers[0].Command,
684+
[]string{
685+
"limitador-server",
686+
"--limit-name-in-labels",
687+
"/home/limitador/etc/limitador-config.yaml",
688+
"memory",
689+
})
690+
}, timeout, interval).Should(BeTrue())
691+
})
692+
})
693+
632694
Context("Modifying limitador deployment objects", func() {
633695
var limitadorObj *limitadorv1alpha1.Limitador
634696

pkg/limitador/deployment_options.go

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func DeploymentCommand(limObj *limitadorv1alpha1.Limitador, storageOptions Deplo
3737
command = append(command, "--rate-limit-headers", string(*limObj.Spec.RateLimitHeaders))
3838
}
3939

40+
if limObj.Spec.Telemetry != nil && *limObj.Spec.Telemetry == "exhaustive" {
41+
command = append(command, "--limit-name-in-labels")
42+
}
43+
4044
command = append(command, filepath.Join(LimitadorCMMountPath, LimitadorConfigFileName))
4145
command = append(command, storageOptions.Command...)
4246

0 commit comments

Comments
 (0)