Skip to content

Commit

Permalink
add sentry sample rate config
Browse files Browse the repository at this point in the history
  • Loading branch information
kelkawi-a committed Feb 28, 2024
1 parent da04d68 commit 5aaa90a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ options:
default: false
type: boolean

sentry-sample-rate:
description: |
A value between 0 (0% of errors) and 1 (100% of errors) to indicate the proportion of errors
to be captured by Sentry.
default: 1.0
type: float

workflows-file-name:
description: Name of the wheel file resource attached to the charm.
default: ""
Expand Down
4 changes: 4 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ def _validate(self, event): # noqa: C901
elif self.config["auth-provider"] == "google":
self._check_required_config(REQUIRED_OIDC_CONFIG)

sample_rate = self.config["sentry-sample-rate"]
if self.config["sentry-dsn"] and (sample_rate < 0 or sample_rate > 1):
raise ValueError("Invalid config: sentry-sample-rate must be between 0 and 1")

def _update(self, event):
"""Update the Temporal worker configuration and replan its execution.
Expand Down
1 change: 1 addition & 0 deletions src/resources/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ async def run_worker(unpacked_file_name, module_name):
release=os.getenv("TWC_SENTRY_RELEASE").strip() or None,
environment=os.getenv("TWC_SENTRY_ENVIRONMENT").strip() or None,
redact_params=os.getenv("TWC_SENTRY_REDACT_PARAMS"),
sample_rate=os.getenv("TWC_SENTRY_SAMPLE_RATE"),
)

worker_opt = WorkerOptions(sentry=sentry)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@pytest_asyncio.fixture(name="deploy", scope="module")
async def deploy(ops_test: OpsTest):
"""Verify the app is up and running."""
await ops_test.model.set_config({"update-status-hook-interval": "1m"})
await setup_temporal_ecosystem(ops_test)

charm = await ops_test.build_charm(".")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ async def setup_temporal_ecosystem(ops_test: OpsTest):
ops_test: PyTest object.
"""
await asyncio.gather(
ops_test.model.deploy(APP_NAME_SERVER, channel="edge"),
ops_test.model.deploy(APP_NAME_SERVER, channel="edge", config={"num-history-shards": 1}),
ops_test.model.deploy(APP_NAME_ADMIN, channel="edge"),
ops_test.model.deploy(APP_NAME_UI, channel="edge"),
ops_test.model.deploy("postgresql-k8s", channel="14", trust=True),
ops_test.model.deploy("postgresql-k8s", channel="14/stable", trust=True),
)

async with ops_test.fast_forward():
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def test_ready(self, _process_wheel_file, _setup_container):
"TWC_SENTRY_DSN": "",
"TWC_SENTRY_ENVIRONMENT": "",
"TWC_SENTRY_RELEASE": "",
"TWC_SENTRY_SAMPLE_RATE": 1.0,
"TWC_SENTRY_REDACT_PARAMS": False,
"TWC_SUPPORTED_ACTIVITIES": "all",
"TWC_SUPPORTED_WORKFLOWS": "all",
Expand All @@ -149,6 +150,14 @@ def test_ready(self, _process_wheel_file, _setup_container):
"on-check-failure": {"up": "ignore"},
}
},
"checks": {
"up": {
"override": "replace",
"level": "alive",
"period": "10s",
"exec": {"command": "python check_status.py"},
}
},
}
got_plan = harness.get_container_pebble_plan("temporal-worker").to_dict()
self.assertEqual(got_plan, want_plan)
Expand Down

0 comments on commit 5aaa90a

Please sign in to comment.