Skip to content

Commit

Permalink
Add option INCLUDE_PUBSUB_METRICS to manage verbose metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
andriusm committed Feb 10, 2025
1 parent e6690be commit 0e14016
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app-tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -e
set -x

export OPAL_AUTH_PUBLIC_KEY
export OPAL_AUTH_PRIVATE_KEY
Expand All @@ -15,7 +16,7 @@ function generate_opal_keys {
ssh-keygen -q -t rsa -b 4096 -m pem -f opal_crypto_key -N "$OPAL_AUTH_PRIVATE_KEY_PASSPHRASE"
OPAL_AUTH_PUBLIC_KEY="$(cat opal_crypto_key.pub)"
OPAL_AUTH_PRIVATE_KEY="$(tr '\n' '_' < opal_crypto_key)"
rm opal_crypto_key.pub opal_crypto_key
# rm opal_crypto_key.pub opal_crypto_key

OPAL_AUTH_MASTER_TOKEN="$(openssl rand -hex 16)"
OPAL_AUTH_JWT_AUDIENCE=https://api.opal.ac/v1/ OPAL_AUTH_JWT_ISSUER=https://opal.ac/ OPAL_REPO_WATCHER_ENABLED=0 \
Expand All @@ -37,13 +38,15 @@ function generate_opal_keys {
echo "OPAL_CLIENT_TOKEN=\"$OPAL_CLIENT_TOKEN\"";
echo "OPAL_AUTH_PRIVATE_KEY_PASSPHRASE=\"$OPAL_AUTH_PRIVATE_KEY_PASSPHRASE\""
) > .env
echo "DEBUG ENV FILE"
cat .env
}

function prepare_policy_repo {
echo "- Clone tests policy repo to create test's branch"
export OPAL_POLICY_REPO_URL
export POLICY_REPO_BRANCH
OPAL_POLICY_REPO_URL=${OPAL_POLICY_REPO_URL:-git@github.com:permitio/opal-tests-policy-repo.git}
OPAL_POLICY_REPO_URL=${OPAL_POLICY_REPO_URL:-git@github.com:permitio/opal-example-policy-repo.git}
POLICY_REPO_BRANCH=test-$RANDOM$RANDOM
rm -rf ./opal-tests-policy-repo
git clone "$OPAL_POLICY_REPO_URL"
Expand Down
3 changes: 3 additions & 0 deletions documentation/docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ Please use this table as a reference.
| OPAL_POLICY_REPO_CLONE_PATH | Where (i.e: base target path) to clone the repo in your docker filesystem (not important unless you mount a docker volume). | |
| OPAL_POLICY_REPO_MAIN_BRANCH | Name of the git branch to track for policy files (default: `master`). | |
| OPAL_BUNDLE_IGNORE | Paths to omit from policy bundle. List of glob style paths, or paths without wildcards but ending with "/\*\*" indicating a parent path (ignoring all under it). | `bundle_ignore: Optional[List[str]]` |
| INCLUDE_PUBSUB_METRICS | Set if OPAL should include pubsub info in OpenTelemetry metrics | |



## OPAL Client Configuration Variables

Expand Down
6 changes: 6 additions & 0 deletions packages/opal-server/opal_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ class OpalServerConfig(Confi):
description="Policy polling refresh interval",
)

INCLUDE_PUBSUB_METRICS = confi.bool(
"INCLUDE_PUBSUB_METRICS",
True,
description="Set if OPAL should include pubsub info in OpenTelemetry metrics",
)

def on_load(self):
if self.SERVER_PORT is not None and self.SERVER_PORT.isdigit():
# Backward compatibility - if SERVER_PORT is set with a valid value, use it as SERVER_BIND_PORT
Expand Down
4 changes: 4 additions & 0 deletions packages/opal-server/opal_server/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def get_active_clients_counter():
if _active_clients_counter is None:
if not opal_common_config.ENABLE_OPENTELEMETRY_METRICS:
return None
if not opal_server_config.INCLUDE_PUBSUB_METRICS:
return None
meter = get_meter()
_active_clients_counter = meter.create_counter(
name="opal_server_active_clients",
Expand All @@ -58,6 +60,8 @@ def get_client_data_subscriptions_counter():
if _client_data_subscriptions_counter is None:
if not opal_common_config.ENABLE_OPENTELEMETRY_METRICS:
return None
if not opal_server_config.INCLUDE_PUBSUB_METRICS:
return None
meter = get_meter()
_client_data_subscriptions_counter = meter.create_up_down_counter(
name="opal_client_data_subscriptions",
Expand Down

0 comments on commit 0e14016

Please # to comment.