Skip to content

Commit

Permalink
Enable limit name in prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Nov 7, 2023
1 parent e181d99 commit f6deccd
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/v1alpha1/limitador_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type LimitadorSpec struct {
// +optional
RateLimitHeaders *RateLimitHeadersType `json:"rateLimitHeaders,omitempty"`

// +optional
Telemetry *Telemetry `json:"telemetry,omitempty"`

// +optional
Limits []RateLimit `json:"limits,omitempty"`

Expand Down Expand Up @@ -149,6 +152,10 @@ type LimitadorList struct {
// +kubebuilder:validation:Enum=NONE;DRAFT_VERSION_03
type RateLimitHeadersType string

// RateLimitHeadersType defines the valid options for the --rate-limit-headers arg
// +kubebuilder:validation:Enum=basic;exhaustive
type Telemetry string

// Storage contains the options for Limitador counters database or in-memory data storage
type Storage struct {
// +optional
Expand Down
7 changes: 7 additions & 0 deletions bundle/manifests/limitador.kuadrant.io_limitadors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,13 @@ spec:
type: object
type: object
type: object
telemetry:
description: RateLimitHeadersType defines the valid options for the
--rate-limit-headers arg
enum:
- basic
- exhaustive
type: string
version:
type: string
type: object
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/limitador.kuadrant.io_limitadors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,13 @@ spec:
type: object
type: object
type: object
telemetry:
description: RateLimitHeadersType defines the valid options for the
--rate-limit-headers arg
enum:
- basic
- exhaustive
type: string
version:
type: string
type: object
Expand Down
64 changes: 63 additions & 1 deletion controllers/limitador_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ var _ = Describe("Limitador controller", func() {
})
})

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

BeforeEach(func() {
Expand Down Expand Up @@ -629,6 +629,68 @@ var _ = Describe("Limitador controller", func() {
})
})

Context("Reconciling command line args for telemetry", func() {
var limitadorObj *limitadorv1alpha1.Limitador

BeforeEach(func() {
limitadorObj = newLimitador()

Expect(k8sClient.Create(context.TODO(), limitadorObj)).Should(Succeed())
})

AfterEach(func() {
err := k8sClient.Delete(context.TODO(), limitadorObj, deletePropagationPolicy)
Expect(err == nil || errors.IsNotFound(err))
})

It("Should modify the limitador deployment command line args", func() {
updatedLimitador := limitadorv1alpha1.Limitador{}
Eventually(func() bool {
err := k8sClient.Get(
context.TODO(),
types.NamespacedName{
Namespace: LimitadorNamespace,
Name: limitadorObj.Name,
},
&updatedLimitador)

if err != nil {
return false
}

if updatedLimitador.Spec.Telemetry != nil {
return false
}
telemetry := limitadorv1alpha1.Telemetry("exhaustive")
updatedLimitador.Spec.Telemetry = &telemetry
return k8sClient.Update(context.TODO(), &updatedLimitador) == nil
}, timeout, interval).Should(BeTrue())

Eventually(func() bool {
updatedLimitadorDeployment := appsv1.Deployment{}
err := k8sClient.Get(
context.TODO(),
types.NamespacedName{
Namespace: LimitadorNamespace,
Name: limitadorObj.Name,
},
&updatedLimitadorDeployment)

if err != nil {
return false
}

return reflect.DeepEqual(updatedLimitadorDeployment.Spec.Template.Spec.Containers[0].Command,
[]string{
"limitador-server",
"--limit-name-in-labels",
"/home/limitador/etc/limitador-config.yaml",
"memory",
})
}, timeout, interval).Should(BeTrue())
})
})

Context("Modifying limitador deployment objects", func() {
var limitadorObj *limitadorv1alpha1.Limitador

Expand Down
4 changes: 4 additions & 0 deletions pkg/limitador/deployment_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func DeploymentCommand(limObj *limitadorv1alpha1.Limitador, storageOptions Deplo
command = append(command, "--rate-limit-headers", string(*limObj.Spec.RateLimitHeaders))
}

if limObj.Spec.Telemetry != nil && *limObj.Spec.Telemetry == "exhaustive" {
command = append(command, "--limit-name-in-labels")
}

command = append(command, filepath.Join(LimitadorCMMountPath, LimitadorConfigFileName))
command = append(command, storageOptions.Command...)

Expand Down

0 comments on commit f6deccd

Please sign in to comment.