Skip to content

Commit

Permalink
Merge pull request #2 from DocPlanner/feat/support-queue-regex
Browse files Browse the repository at this point in the history
Feat: Add support for regex on queue names
  • Loading branch information
achetronic authored May 16, 2023
2 parents 3660301 + cec5213 commit 20b9d8f
Show file tree
Hide file tree
Showing 6 changed files with 591 additions and 395 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ spec:
url: "https://your-server.rmq.cloudamqp.com"
vhost: "shared"
queue: "your-queue-here"
useRegex: true

# Setting credentials is optional.
# ATTENTION: If set, BOT are required
Expand Down Expand Up @@ -99,6 +100,49 @@ spec:
namespace: default
```
#### Queue names/regex
Let's start talking about how to look for queues inside your RabbitMQ. The first approach is just to define a static
name for the `queue` and `vhost`. This will perform the action over the workload when the condition is met, as simple
as follows:

```yaml
apiVersion: rabbit-stalker.docplanner.com/v1alpha1
kind: WorkloadAction
metadata:
name: workloadaction-sample
spec:
# ...
rabbitConnection:
url: "https://your-server.rmq.cloudamqp.com"
vhost: "shared"
queue: "your-queue-here"
useRegex: false
```

But what happens if you have some monolithic application that handle several queues at the same time? if several queues
are managed by the same application instance (or pod inside Kubernetes), it's possible that your queues' names are defined
following a pattern that can be represented by a REGEX expression. In that case, you can use the following feature:

```yaml
apiVersion: rabbit-stalker.docplanner.com/v1alpha1
kind: WorkloadAction
metadata:
name: workloadaction-sample
spec:
# ...
rabbitConnection:
url: "https://your-server.rmq.cloudamqp.com"
vhost: "shared"
queue: |-
^your_monolith_prefix.(cz|es|it|pl|tr|pt|de)_incoming_events$
useRegex: true
```

> ATTENTION! If the condition is met for some of them, the action will be immediately executed over the workload

#### Conditions

What can you do with the condition? As we said, it admits GJSON for dot notation, so basically, you can look for any
field inside the RabbitMQ response. As an example, take the following sample JSON

Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/workloadaction_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type RabbitConnectionSpec struct {
Url string `json:"url"`
Vhost string `json:"vhost"`
Queue string `json:"queue"`
UseRegex bool `json:"useRegex,omitempty"`
Credentials RabbitConnectionCredentialsSpec `json:"credentials,omitempty"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ spec:
type: string
url:
type: string
useRegex:
type: boolean
vhost:
type: string
required:
Expand Down
1 change: 1 addition & 0 deletions config/samples/rabbit-stalker_v1alpha1_workloadaction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spec:
url: "https://your-server.rmq.cloudamqp.com"
vhost: "shared"
queue: "your-queue-here"
useRegex: true

# (Optional) Credentials to authenticate against endpoint.
# If set, both are required
Expand Down
17 changes: 10 additions & 7 deletions controllers/workloadaction_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

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

//
// ConditionTypeWorkloadActionReady indicates that the WorkloadActione is ready to act or not
// ConditionTypeWorkloadActionReady indicates that the WorkloadAction is ready to act or not
ConditionTypeWorkloadActionReady = "WorkloadActionReady"

// Credentials not found
ConditionReasonCredentialsNotFound = "CredentialsNotFound"
ConditionReasonCredentialsNotFoundMessage = "Credentials secret or key not found"

// Credentials not valid
ConditionReasonCredentialsNotValid = "CredentialsNotValid"
ConditionReasonCredentialsNotValidMessage = "Credentials does not allow authenticate"
//ConditionReasonCredentialsNotValid = "CredentialsNotValid"
//ConditionReasonCredentialsNotValidMessage = "Credentials does not allow to authenticate"

// HTTPRequest execution failed
ConditionReasonHttpRequestExecutionFailed = "HttpRequestExecutionFailed"
ConditionReasonHttpRequestExecutionFailedMessage = "Http request failed on execution"
// HTTPRequest failed
ConditionReasonUrlParsingFailed = "UrlParsingFailed"
ConditionReasonUrlParsingFailedMessage = "Url parsing failed. Fix its syntax and try again"

// HTTPResponse not successful
ConditionReasonHttpResponseNotSuccessful = "HttpRequestNotSuccessful"
ConditionReasonHttpResponseNotSuccessfulMessage = "Http request returned status code: %d"

// HTTPResponse not valid
ConditionReasonHttpResponseNotValid = "HttpResponseNotValid"
Expand Down
Loading

0 comments on commit 20b9d8f

Please sign in to comment.