Skip to content
This repository was archived by the owner on Feb 9, 2025. It is now read-only.

Commit 20b9d8f

Browse files
authored
Merge pull request #2 from DocPlanner/feat/support-queue-regex
Feat: Add support for regex on queue names
2 parents 3660301 + cec5213 commit 20b9d8f

File tree

6 files changed

+591
-395
lines changed

6 files changed

+591
-395
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ spec:
6060
url: "https://your-server.rmq.cloudamqp.com"
6161
vhost: "shared"
6262
queue: "your-queue-here"
63+
useRegex: true
6364

6465
# Setting credentials is optional.
6566
# ATTENTION: If set, BOT are required
@@ -99,6 +100,49 @@ spec:
99100
namespace: default
100101
```
101102
103+
#### Queue names/regex
104+
105+
Let's start talking about how to look for queues inside your RabbitMQ. The first approach is just to define a static
106+
name for the `queue` and `vhost`. This will perform the action over the workload when the condition is met, as simple
107+
as follows:
108+
109+
```yaml
110+
apiVersion: rabbit-stalker.docplanner.com/v1alpha1
111+
kind: WorkloadAction
112+
metadata:
113+
name: workloadaction-sample
114+
spec:
115+
# ...
116+
rabbitConnection:
117+
url: "https://your-server.rmq.cloudamqp.com"
118+
vhost: "shared"
119+
queue: "your-queue-here"
120+
useRegex: false
121+
```
122+
123+
But what happens if you have some monolithic application that handle several queues at the same time? if several queues
124+
are managed by the same application instance (or pod inside Kubernetes), it's possible that your queues' names are defined
125+
following a pattern that can be represented by a REGEX expression. In that case, you can use the following feature:
126+
127+
```yaml
128+
apiVersion: rabbit-stalker.docplanner.com/v1alpha1
129+
kind: WorkloadAction
130+
metadata:
131+
name: workloadaction-sample
132+
spec:
133+
# ...
134+
rabbitConnection:
135+
url: "https://your-server.rmq.cloudamqp.com"
136+
vhost: "shared"
137+
queue: |-
138+
^your_monolith_prefix.(cz|es|it|pl|tr|pt|de)_incoming_events$
139+
useRegex: true
140+
```
141+
142+
> ATTENTION! If the condition is met for some of them, the action will be immediately executed over the workload
143+
144+
#### Conditions
145+
102146
What can you do with the condition? As we said, it admits GJSON for dot notation, so basically, you can look for any
103147
field inside the RabbitMQ response. As an example, take the following sample JSON
104148

api/v1alpha1/workloadaction_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type RabbitConnectionSpec struct {
5151
Url string `json:"url"`
5252
Vhost string `json:"vhost"`
5353
Queue string `json:"queue"`
54+
UseRegex bool `json:"useRegex,omitempty"`
5455
Credentials RabbitConnectionCredentialsSpec `json:"credentials,omitempty"`
5556
}
5657

config/crd/bases/rabbit-stalker.docplanner.com_workloadactions.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ spec:
194194
type: string
195195
url:
196196
type: string
197+
useRegex:
198+
type: boolean
197199
vhost:
198200
type: string
199201
required:

config/samples/rabbit-stalker_v1alpha1_workloadaction.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ spec:
1717
url: "https://your-server.rmq.cloudamqp.com"
1818
vhost: "shared"
1919
queue: "your-queue-here"
20+
useRegex: true
2021

2122
# (Optional) Credentials to authenticate against endpoint.
2223
# If set, both are required

controllers/workloadaction_status.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ import (
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
66
)
77

8-
// https://github.com/external-secrets/external-secrets/blob/80545f4f183795ef193747fc959558c761b51c99/apis/externalsecrets/v1alpha1/externalsecret_types.go#L168
98
const (
109

1110
//
12-
// ConditionTypeWorkloadActionReady indicates that the WorkloadActione is ready to act or not
11+
// ConditionTypeWorkloadActionReady indicates that the WorkloadAction is ready to act or not
1312
ConditionTypeWorkloadActionReady = "WorkloadActionReady"
1413

1514
// Credentials not found
1615
ConditionReasonCredentialsNotFound = "CredentialsNotFound"
1716
ConditionReasonCredentialsNotFoundMessage = "Credentials secret or key not found"
1817

1918
// Credentials not valid
20-
ConditionReasonCredentialsNotValid = "CredentialsNotValid"
21-
ConditionReasonCredentialsNotValidMessage = "Credentials does not allow authenticate"
19+
//ConditionReasonCredentialsNotValid = "CredentialsNotValid"
20+
//ConditionReasonCredentialsNotValidMessage = "Credentials does not allow to authenticate"
2221

23-
// HTTPRequest execution failed
24-
ConditionReasonHttpRequestExecutionFailed = "HttpRequestExecutionFailed"
25-
ConditionReasonHttpRequestExecutionFailedMessage = "Http request failed on execution"
22+
// HTTPRequest failed
23+
ConditionReasonUrlParsingFailed = "UrlParsingFailed"
24+
ConditionReasonUrlParsingFailedMessage = "Url parsing failed. Fix its syntax and try again"
25+
26+
// HTTPResponse not successful
27+
ConditionReasonHttpResponseNotSuccessful = "HttpRequestNotSuccessful"
28+
ConditionReasonHttpResponseNotSuccessfulMessage = "Http request returned status code: %d"
2629

2730
// HTTPResponse not valid
2831
ConditionReasonHttpResponseNotValid = "HttpResponseNotValid"

0 commit comments

Comments
 (0)