-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* idk * changelog * test resources for sqs * idk * patch operator to use localstack * test can use localstack * send messages, expect output * verifications * fixes * provide credentials for sqs client * words * resources for manual testing * fix broken configs * prints * implement echo queue verification * don't verify queue deletion, remove done TODOs * passing locally * refactoring and docs * waits and sleeps * trim localstack host * remove commented out verification * fmt * fix docs * thanks clippy * use image after CR - with release build * used released test image * increase test timeout * fix image name
- Loading branch information
Showing
20 changed files
with
1,695 additions
and
39 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
E2E tests for SQS splitting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"operator": true, | ||
"feature": { | ||
"split_queues": { | ||
"e2e-test-queue1": { | ||
"queue_type": "SQS", | ||
"message_filter": { | ||
"client": "^a$" | ||
} | ||
}, | ||
"e2e-test-queue2": { | ||
"queue_type": "SQS", | ||
"message_filter": { | ||
"client": "^a$" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"operator": true, | ||
"feature": { | ||
"split_queues": { | ||
"e2e-test-queue1": { | ||
"queue_type": "SQS", | ||
"message_filter": { | ||
"client": "^b$" | ||
} | ||
}, | ||
"e2e-test-queue2": { | ||
"queue_type": "SQS", | ||
"message_filter": { | ||
"client": "^b$" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "rust-sqs-printer" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
aws-config = { version = "1.5", features = ["behavior-version-latest"] } | ||
aws-sdk-sqs = { version = "1.39" } | ||
tokio = { version = "1.39", features = ["rt", "rt-multi-thread", "macros"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Using the agent's build image, that has rustup targets, zigbuild etc. | ||
FROM --platform=$BUILDPLATFORM ghcr.io/metalbear-co/ci-agent-build:latest AS build-env | ||
ARG TARGETARCH | ||
|
||
WORKDIR /build | ||
COPY . . | ||
|
||
# Translate docker's platform to cargo's target. | ||
RUN /build/platform.sh | ||
|
||
|
||
# Build binary. | ||
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true | ||
RUN cargo zigbuild -Z bindeps --target $(cat /.platform) | ||
RUN cp /build/target/$(cat /.platform)/debug/rust-sqs-printer /rust-sqs-printer | ||
|
||
# Slim final layer with only the binary. | ||
FROM debian:stable-slim | ||
# TODO: optimize this? | ||
RUN apt-get update | ||
RUN apt-get install -y --no-install-recommends ca-certificates | ||
RUN update-ca-certificates | ||
|
||
WORKDIR /app | ||
COPY --from=build-env /rust-sqs-printer . | ||
|
||
CMD ["./rust-sqs-printer"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# rust-sqs-printer | ||
|
||
Test application used by the SQS E2E tests. | ||
|
||
The `Dockerfile` and k8s manifest sqs-printer.yaml are for manual testing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"operator": true, | ||
"target": "deployment/sqs-printer", | ||
"feature": { | ||
"split_queues": { | ||
"manual-queue": { | ||
"queue_type": "SQS", | ||
"message_filter": { | ||
"local": "1" | ||
} | ||
}, | ||
"fifo-queue": { | ||
"queue_type": "SQS", | ||
"message_filter": { | ||
"local": "1" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
# Used in Docker build to set platform dependent variables | ||
|
||
case $TARGETARCH in | ||
|
||
"amd64") | ||
echo "x86_64-unknown-linux-gnu" > /.platform | ||
echo "" > /.compiler | ||
;; | ||
"arm64") | ||
echo "aarch64-unknown-linux-gnu" > /.platform | ||
echo "gcc-aarch64-linux-gnu" > /.compiler | ||
;; | ||
"arm") | ||
echo "armv7-unknown-linux-gnueabihf" > /.platform | ||
echo "gcc-arm-linux-gnueabihf" > /.compiler | ||
;; | ||
esac | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: sqs-printer | ||
labels: | ||
app: sqs-printer | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: sqs-printer | ||
template: | ||
metadata: | ||
labels: | ||
app: sqs-printer | ||
spec: | ||
serviceAccountName: sqs-reader-account | ||
containers: | ||
- name: sqs-printer | ||
image: docker.io/t4lz/sqs-printer:latest | ||
env: | ||
- name: RUST_BACKTRACE | ||
value: "1" | ||
- name: SQS_TEST_Q_NAME1 | ||
value: ManualTesting1 | ||
- name: SQS_TEST_Q_NAME2 | ||
value: TestQueue.fifo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use aws_sdk_sqs::{operation::receive_message::ReceiveMessageOutput, types::Message, Client}; | ||
use tokio::time::{sleep, Duration}; | ||
|
||
/// Name of the environment variable that holds the name of the first SQS queue to read from. | ||
const QUEUE_NAME_ENV_VAR1: &str = "SQS_TEST_Q_NAME1"; | ||
|
||
/// Name of the environment variable that holds the name of the second SQS queue to read from. | ||
const QUEUE_NAME_ENV_VAR2: &str = "SQS_TEST_Q_NAME2"; | ||
|
||
/// Reads from queue and prints the contents of each message in a new line. | ||
async fn read_from_queue(read_q_name: String, client: Client, queue_num: u8) { | ||
let read_q_url = client | ||
.get_queue_url() | ||
.queue_name(read_q_name) | ||
.send() | ||
.await | ||
.unwrap() | ||
.queue_url | ||
.unwrap(); | ||
let receive_message_request = client | ||
.receive_message() | ||
.message_attribute_names(".*") | ||
// Without this the wait time would be 0 and responses would return immediately also when | ||
// there are no messages (and potentially even sometimes return empty immediately when | ||
// there are actually messages). | ||
// By setting a time != 0 (20 is the maximum), we perform "long polling" which means we | ||
// won't get "false empties" and also less empty responses, because SQS will wait for that | ||
// time before returning an empty response. | ||
.wait_time_seconds(5) | ||
.queue_url(&read_q_url); | ||
loop { | ||
let res = match receive_message_request.clone().send().await { | ||
Ok(res) => res, | ||
Err(err) => { | ||
println!("ERROR: {err:?}"); | ||
sleep(Duration::from_secs(3)).await; | ||
continue; | ||
} | ||
}; | ||
if let ReceiveMessageOutput { | ||
messages: Some(messages), | ||
.. | ||
} = res | ||
{ | ||
for Message { | ||
body, | ||
receipt_handle, | ||
.. | ||
} in messages | ||
{ | ||
println!( | ||
"{queue_num}:{}", | ||
body.expect("Got message without body. Expected content.") | ||
); | ||
if let Some(handle) = receipt_handle { | ||
client | ||
.delete_message() | ||
.queue_url(&read_q_url) | ||
.receipt_handle(handle) | ||
.send() | ||
.await | ||
.unwrap(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let sdk_config = aws_config::load_from_env().await; | ||
let client = Client::new(&sdk_config); | ||
let read_q_name = std::env::var(QUEUE_NAME_ENV_VAR1).unwrap(); | ||
let q_task_handle = tokio::spawn(read_from_queue(read_q_name.clone(), client.clone(), 1)); | ||
let read_q_name = std::env::var(QUEUE_NAME_ENV_VAR2).unwrap(); | ||
let fifo_q_task_handle = tokio::spawn(read_from_queue(read_q_name.clone(), client.clone(), 2)); | ||
let (q_res, fifo_res) = tokio::join!(q_task_handle, fifo_q_task_handle); | ||
q_res.unwrap(); | ||
fifo_res.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
mod concurrent_steal; | ||
mod policies; | ||
mod queue_splitting; | ||
mod sanity; | ||
mod setup; |
Oops, something went wrong.