Skip to content

Commit

Permalink
feat(app): add sentry to git clone (#963)
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Grubenmann <ralf.grubenmann@gmail.com>
  • Loading branch information
olevski and Ralf Grubenmann authored Mar 22, 2022
1 parent 3d79d45 commit 7d73cad
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 17 deletions.
23 changes: 19 additions & 4 deletions git_services/git_services/cli/sentry.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
from typing import TYPE_CHECKING
from dataclasses import dataclass
from typing import Union, Optional


if TYPE_CHECKING:
from git_services.sidecar.config import Sentry
@dataclass
class SentryConfig:
enabled: Union[str, bool] = False
dsn: Optional[str] = None
environment: Optional[str] = None
sample_rate: float = 0.0

def __post_init__(self):
if type(self.enabled) is str:
# NOTE: Required because bool("False") == True and environment vars are always strings
self.enabled = (self.enabled.lower() == "true")
# INFO: Convert empty strings to None
for attr_name in ["dsn", "environment"]:
attr_val = getattr(self, attr_name)
if type(attr_val) is str and len(attr_val) == 0:
setattr(self, attr_name, None)

def setup_sentry(sentry_config: "Sentry"):

def setup_sentry(sentry_config: SentryConfig):
if sentry_config.enabled:
import sentry_sdk

Expand Down
2 changes: 2 additions & 0 deletions git_services/git_services/init/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from git_services.init import errors
from git_services.init.cloner import GitCloner
from git_services.init.config import config_from_env
from git_services.cli.sentry import setup_sentry

# NOTE: register exception handler
sys.excepthook = errors.handle_exception

if __name__ == "__main__":
config = config_from_env()
setup_sentry(config.sentry)
git_cloner = GitCloner(
config.git_url,
config.repository_url,
Expand Down
3 changes: 3 additions & 0 deletions git_services/git_services/init/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import dataconf
from typing import Optional

from git_services.cli.sentry import SentryConfig


@dataclass
class User:
Expand All @@ -20,6 +22,7 @@ class Config:
branch: str
git_url: str
user: User
sentry: SentryConfig
git_autosave: str = "0"
lfs_auto_fetch: str = "0"
mount_path: str = "/work"
Expand Down
11 changes: 2 additions & 9 deletions git_services/git_services/sidecar/config.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
from dataclasses import dataclass
from typing import Optional
import dataconf


@dataclass
class Sentry:
enabled: Optional[bool] = False
dsn: Optional[str] = ""
environment: Optional[str] = ""
sample_rate: Optional[float] = 0.0
from git_services.cli.sentry import SentryConfig


@dataclass
class Config:
sentry: Sentry
sentry: SentryConfig


def config_from_env() -> Config:
Expand Down
16 changes: 16 additions & 0 deletions helm-chart/renku-notebooks/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ spec:
value: {{ .Values.sentry.sampleRate | quote }}
- name: SENTRY_RELEASE
value: {{ .Chart.Version | quote }}
- name: GIT_CLONE_SENTRY_ENABLED
value: {{ .Values.sessionSentry.gitClone.enabled | quote }}
- name: GIT_CLONE_SENTRY_DSN
value: {{ .Values.sessionSentry.gitClone.dsn | quote }}
- name: GIT_CLONE_SENTRY_ENV
value: {{ .Values.sessionSentry.gitClone.environment | quote }}
- name: GIT_CLONE_SENTRY_SAMPLE_RATE
value: {{ .Values.sessionSentry.gitClone.sampleRate | quote }}
- name: SIDECAR_SENTRY_ENABLED
value: {{ .Values.sessionSentry.sidecar.enabled | quote }}
- name: SIDECAR_SENTRY_DSN
value: {{ .Values.sessionSentry.sidecar.dsn | quote }}
- name: SIDECAR_SENTRY_ENV
value: {{ .Values.sessionSentry.sidecar.environment | quote }}
- name: SIDECAR_SENTRY_SAMPLE_RATE
value: {{ .Values.sessionSentry.sidecar.sampleRate | quote }}
- name: CERTIFICATES_IMAGE
value: "{{ .Values.global.certificates.image.repository }}:{{ .Values.global.certificates.image.tag }}"
- name: CUSTOM_CA_CERTS_SECRETS
Expand Down
14 changes: 14 additions & 0 deletions helm-chart/renku-notebooks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ sentry:
environment:
## Sample rate is used for performance monitoring in sentry
sampleRate: 0.2

sessionSentry:
gitClone:
enabled: false
dsn:
environment:
## Sample rate is used for performance monitoring in sentry
sampleRate: 0.2
sidecar:
enabled: false
dsn:
environment:
## Sample rate is used for performance monitoring in sentry
sampleRate: 0.2

replicaCount: 2

Expand Down
12 changes: 8 additions & 4 deletions renku_notebooks/api/amalthea_patches/git_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ def main(server):
},
{
"name": "GIT_RPC_SENTRY__ENABLED",
"value": os.environ.get("SENTRY_ENABLED"),
"value": os.environ.get("SIDECAR_SENTRY_ENABLED"),
},
{
"name": "GIT_RPC_SENTRY__DSN",
"value": os.environ.get("SENTRY_DSN"),
"value": os.environ.get("SIDECAR_SENTRY_DSN"),
},
{
"name": "GIT_RPC_SENTRY__ENVIRONMENT",
"value": os.environ.get("SENTRY_ENV"),
"value": os.environ.get("SIDECAR_SENTRY_ENV"),
},
{
"name": "GIT_RPC_SENTRY__SAMPLE_RATE",
"value": os.environ.get("SENTRY_SAMPLE_RATE"),
"value": os.environ.get("SIDECAR_SENTRY_SAMPLE_RATE"),
},
{
"name": "SENTRY_RELEASE",
"value": os.environ.get("SENTRY_RELEASE"),
},
{
"name": "CI_COMMIT_SHA",
Expand Down
21 changes: 21 additions & 0 deletions renku_notebooks/api/amalthea_patches/init_containers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import current_app
from kubernetes import client
import os

from ..classes.user import RegisteredUser
from .utils import get_certificates_volume_mounts
Expand Down Expand Up @@ -43,6 +44,26 @@ def git_clone(server):
"name": "GIT_CLONE_USER__OAUTH_TOKEN",
"value": server._user.git_token,
},
{
"name": "GIT_CLONE_SENTRY__ENABLED",
"value": os.environ.get("GIT_CLONE_SENTRY_ENABLED"),
},
{
"name": "GIT_CLONE_SENTRY__DSN",
"value": os.environ.get("GIT_CLONE_SENTRY_DSN"),
},
{
"name": "GIT_CLONE_SENTRY__ENVIRONMENT",
"value": os.environ.get("GIT_CLONE_SENTRY_ENV"),
},
{
"name": "GIT_CLONE_SENTRY__SAMPLE_RATE",
"value": os.environ.get("GIT_CLONE_SENTRY_SAMPLE_RATE"),
},
{
"name": "SENTRY_RELEASE",
"value": os.environ.get("SENTRY_RELEASE"),
},
]
if type(server._user) is RegisteredUser:
env += [
Expand Down

0 comments on commit 7d73cad

Please sign in to comment.