Skip to content

Commit

Permalink
Merge pull request #113 from Kuadrant/rlp-named-2
Browse files Browse the repository at this point in the history
Enable per limit metrics
  • Loading branch information
alexsnaps authored Nov 14, 2023
2 parents bb16f15 + 5645e70 commit 5c9f159
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
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

// Telemetry defines the level of metrics Limitador will expose to the user
// +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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metadata:
capabilities: Basic Install
categories: Integration & Delivery
containerImage: quay.io/kuadrant/limitador-operator:latest
createdAt: "2023-11-08T14:01:55Z"
createdAt: "2023-11-08T14:12:13Z"
operators.operatorframework.io/builder: operator-sdk-v1.28.1
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/Kuadrant/limitador-operator
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 @@ -1178,6 +1178,13 @@ spec:
type: object
type: object
type: object
telemetry:
description: Telemetry defines the level of metrics Limitador will
expose to the user
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 @@ -1179,6 +1179,13 @@ spec:
type: object
type: object
type: object
telemetry:
description: Telemetry defines the level of metrics Limitador will
expose to the user
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 5c9f159

Please sign in to comment.