Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prepared logs to the logging test #583

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ All notable changes to this project will be documented in this file.

- Support enabling decision logs ([#555]).

### Fixed

- Processing of corrupted log events fixed; If errors occur, the error
messages are added to the log event ([#583]).

[#555]: https://github.com/stackabletech/opa-operator/pull/555
[#583]: https://github.com/stackabletech/opa-operator/pull/583

## [24.3.0] - 2024-03-20

Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
snafu = "0.8"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.69.2" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.69.3" }
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1.37", features = ["full"] }
tracing = "0.1"
Expand Down
4 changes: 2 additions & 2 deletions crate-hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions tests/templates/kuttl/logging/03-assert.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions tests/templates/kuttl/logging/03-copy-prepared-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
opa_pod=$(kubectl get pods \
--namespace=$NAMESPACE \
--selector=app.kubernetes.io/instance=test-opa \
--output=jsonpath='{.items[0].metadata.name}')

kubectl cp ./prepared-opa-logs.json \
$NAMESPACE/$opa_pod:/stackable/log/opa/test \
--container vector

kubectl cp ./prepared-bundle-builder-logs.txt \
$NAMESPACE/$opa_pod:/stackable/log/bundle-builder/test \
--container vector
16 changes: 9 additions & 7 deletions tests/templates/kuttl/logging/04-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: >-
kubectl exec --namespace=$NAMESPACE opa-test-runner-0 --
python /tmp/test_log_aggregation.py -n $NAMESPACE
- script: >-
kubectl exec --namespace=$NAMESPACE opa-test-runner-0 --
sh /tmp/test_log_aggregation.sh
timeout: 300
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: opa-test-runner
status:
readyReplicas: 1
replicas: 1
10 changes: 10 additions & 0 deletions tests/templates/kuttl/logging/05-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: >-
kubectl exec --namespace=$NAMESPACE opa-test-runner-0 --
python /tmp/test_log_aggregation.py -n $NAMESPACE
- script: >-
kubectl exec --namespace=$NAMESPACE opa-test-runner-0 --
sh /tmp/test_log_aggregation.sh
21 changes: 13 additions & 8 deletions tests/templates/kuttl/logging/opa-vector-aggregator-values.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,39 @@ customConfig:
type: vector
version: "2"
transforms:
filteredAutomaticLogConfigServerOpaDecision:
validEvents:
type: filter
inputs: [vector]
condition: is_null(.errors)
filteredAutomaticLogConfigServerOpaDecision:
type: filter
inputs: [validEvents]
condition: >-
starts_with(string!(.pod), "test-opa-server-automatic-log-config") &&
.container == "opa" &&
.logger == "decision"
filteredAutomaticLogConfigServerOpa:
type: filter
inputs: [vector]
inputs: [validEvents]
condition: >-
starts_with(string!(.pod), "test-opa-server-automatic-log-config") &&
.container == "opa" &&
.logger != "decision"
filteredAutomaticLogConfigServerBundleBuilder:
type: filter
inputs: [vector]
inputs: [validEvents]
condition: >-
starts_with(string!(.pod), "test-opa-server-automatic-log-config") &&
.container == "bundle-builder"
filteredAutomaticLogConfigServerVector:
type: filter
inputs: [vector]
inputs: [validEvents]
condition: >-
starts_with(string!(.pod), "test-opa-server-automatic-log-config") &&
.container == "vector"
filteredAutomaticLogConfigServerPrepare:
type: filter
inputs: [vector]
inputs: [validEvents]
condition: >-
starts_with(string!(.pod), "test-opa-server-automatic-log-config") &&
.container == "prepare"
Expand All @@ -61,15 +65,16 @@ customConfig:
is_null(.logger) ||
is_null(.message)
sinks:
out:
test:
inputs: [filtered*]
type: blackhole
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
aggregator:
inputs: [vector]
type: vector
address: {{ lookup('env', 'VECTOR_AGGREGATOR') }}
buffer:
# Avoid back pressure from VECTOR_AGGREGATOR. The test should
# not fail if the aggregator is not available.
when_full: drop_newest
{% else %}
type: blackhole
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2024-01-01T00:00:00.000000Z  INFO bundle: Valid log event
2024-01-01T00:00:00Z  INFO bundle: Invalid log event with an unparsable timestamp
2024-01-01T00:00:00.000000Z  CRITICAL bundle: Invalid log event with an unknown level
2024-01-01T00:00:00.000000Z  INFO bundle:
Unparsable log event
10 changes: 10 additions & 0 deletions tests/templates/kuttl/logging/prepared-opa-logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"level":"info","msg":"Valid server log event","name":"stackable","plugin":"bundle","time":"2024-01-01T00:00:00Z","logger":"server"}
{"bundles":{"stackable":{}},"decision_id":"5b887ec2-80a0-4b44-9009-2e0cae3507c2","labels":{"id":"992b9dd5-f29e-47a7-aa3a-4408218c3825","version":"0.61.0"},"level":"info","metrics":{"counter_server_query_cache_hit":0,"timer_rego_input_parse_ns":5500,"timer_rego_query_compile_ns":143369,"timer_rego_query_eval_ns":41107,"timer_rego_query_parse_ns":95750,"timer_server_handler_ns":422100},"msg":"Valid decision log event","path":"test","req_id":3,"requested_by":"10.244.0.138:33268","time":"2024-01-01T00:00:00Z","timestamp":"2024-01-01T00:00:00.000000000Z","type":"openpolicyagent.org/decision_logs","logger":"decision"}
{"level":"info","msg":"Invalid log event without a timestamp","name":"stackable","plugin":"bundle","logger":"server"}
{"level":"info","msg":"Invalid log event with an unparsable timestamp","name":"stackable","plugin":"bundle","time":"unparsable timestamp","logger":"server"}
{"level":"info","msg":"Invalid log event without a logger","name":"stackable","plugin":"bundle","time":"2024-01-01T00:00:00Z"}
{"level":"critical","msg":"Invalid log event with an unknown level","name":"stackable","plugin":"bundle","time":"2024-01-01T00:00:00Z","logger":"server"}
{"msg":"Invalid log event without a level","name":"stackable","plugin":"bundle","time":"2024-01-01T00:00:00Z","logger":"server"}
{"level":"info","name":"stackable","plugin":"bundle","time":"2024-01-01T00:00:00Z","logger":"server"}
{"level":"info","msg":"Unparsable log event",...
"true"
Loading