Skip to content

Commit

Permalink
cherry-pick: PENG-2592 adjust default values for sentry's sample rate…
Browse files Browse the repository at this point in the history
…s. (#686)

This commit modifies the default values for the following configurations:

* SENTRY_TRACES_SAMPLE_RATE
* SENTRY_SAMPLE_RATE
* SENTRY_PROFILING_SAMPLE_RATE

The values were adjusted acording to the task's acceptance criteria.

Original Commit: b2e8592
  • Loading branch information
matheushent authored Jan 16, 2025
1 parent 9e2226a commit 19d7daa
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions jobbergate-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file keeps track of all notable changes to jobbergate-agent

## Unreleased

- Added custom settings for configuring Sentry's sample rates [[PENG-2592](https://sharing.clickup.com/t/h/c/18022949/PENG-2592/QQUQ1ABLAP6QSYX)]

## 5.4.0 -- 2024-11-18

- Changed auto-update task to reuse current scheduler instead of creating a new one
Expand Down
7 changes: 5 additions & 2 deletions jobbergate-agent/jobbergate_agent/settings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
from pathlib import Path
from typing import Optional
from typing import Annotated, Optional

import buzz
from pydantic import AnyHttpUrl, Field, ValidationError, model_validator
from pydantic import AnyHttpUrl, confloat, Field, ValidationError, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing_extensions import Self

Expand Down Expand Up @@ -36,6 +36,9 @@ class Settings(BaseSettings):
# Sentry
SENTRY_DSN: Optional[AnyHttpUrl] = None
SENTRY_ENV: str = "local"
SENTRY_TRACES_SAMPLE_RATE: Annotated[float, confloat(gt=0, le=1.0)] = 0.01
SENTRY_SAMPLE_RATE: Annotated[float, confloat(gt=0.0, le=1.0)] = 0.25
SENTRY_PROFILING_SAMPLE_RATE: Annotated[float, confloat(gt=0.0, le=1.0)] = 0.01

# OIDC config for machine-to-machine security
OIDC_DOMAIN: str
Expand Down
4 changes: 3 additions & 1 deletion jobbergate-agent/jobbergate_agent/utils/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def init_sentry():
sentry_sdk.init(
dsn=SETTINGS.SENTRY_DSN,
integrations=[sentry_logging],
traces_sample_rate=1.0,
sample_rate=SETTINGS.SENTRY_SAMPLE_RATE,
profiles_sample_rate=SETTINGS.SENTRY_PROFILING_SAMPLE_RATE,
traces_sample_rate=SETTINGS.SENTRY_TRACES_SAMPLE_RATE,
environment=SETTINGS.SENTRY_ENV,
propagate_traces=False, # Do not propagate traces to child processes (e.g. sbatch subprocesses)
)
Expand Down
2 changes: 2 additions & 0 deletions jobbergate-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
This file keeps track of all notable changes to jobbergate-api

## Unreleased

- Fixed issue on the Job Template rendering process by running it inside a Jinja Sandbox Environment
- Adjusted the default values for the Sentry's sample rates [[PENG-2592](https://sharing.clickup.com/t/h/c/18022949/PENG-2592/QQUQ1ABLAP6QSYX)]

## 5.4.0 -- 2024-11-18

Expand Down
10 changes: 5 additions & 5 deletions jobbergate-api/jobbergate_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""

from enum import Enum
from typing import Optional
from typing import Annotated, Optional

from buzz import require_condition
from loguru import logger
from pydantic import Field, HttpUrl, model_validator
from pydantic import confloat, Field, HttpUrl, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict


Expand Down Expand Up @@ -89,9 +89,9 @@ class Settings(BaseSettings):

# Sentry configuration
SENTRY_DSN: Optional[HttpUrl] = None
SENTRY_SAMPLE_RATE: float = Field(1.0, gt=0.0, le=1.0)
SENTRY_PROFILING_SAMPLE_RATE: float = Field(1.0, gt=0.0, le=1.0)
SENTRY_TRACING_SAMPLE_RATE: float = Field(1.0, gt=0.0, le=1.0)
SENTRY_TRACES_SAMPLE_RATE: Annotated[float, confloat(gt=0, le=1.0)] = 0.01
SENTRY_SAMPLE_RATE: Annotated[float, confloat(gt=0.0, le=1.0)] = 0.25
SENTRY_PROFILING_SAMPLE_RATE: Annotated[float, confloat(gt=0.0, le=1.0)] = 0.01

# Maximum number of bytes allowed for file uploads
MAX_UPLOAD_FILE_SIZE: int = 5 * 1024 * 1024 # 100 MB
Expand Down
2 changes: 1 addition & 1 deletion jobbergate-api/jobbergate_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
sample_rate=settings.SENTRY_SAMPLE_RATE,
environment=settings.DEPLOY_ENV,
profiles_sample_rate=settings.SENTRY_PROFILING_SAMPLE_RATE,
traces_sample_rate=settings.SENTRY_TRACING_SAMPLE_RATE,
traces_sample_rate=settings.SENTRY_TRACES_SAMPLE_RATE,
)
subapp.add_middleware(SentryAsgiMiddleware)
else:
Expand Down
2 changes: 2 additions & 0 deletions jobbergate-cli/tests/subapps/job_scripts/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def test_render_template__fail_when_unable_to_render(tmp_path):
with pytest.raises(Abort, match="Unable to render"):
render_template(template_path, parameters)


def test_render_template__fail_sandbox_violation(tmp_path):
template_path = tmp_path / "dummy.j2"
template_path.write_text("{{ foo.__str__() }}")
Expand All @@ -191,6 +192,7 @@ def test_render_template__fail_sandbox_violation(tmp_path):
with pytest.raises(Abort, match="Security errors raised when rendering"):
render_template(template_path, parameters)


def test_render_template__fails_if_template_does_not_exist(tmp_path):
non_exist = tmp_path / "does/not/exist"
with pytest.raises(Abort, match=f"Template file {non_exist} does not exist"):
Expand Down

0 comments on commit 19d7daa

Please sign in to comment.