Skip to content

Commit a34d593

Browse files
authored
upgrade neuro-logging to 24.4.0 (#888)
1 parent 581e2b0 commit a34d593

File tree

6 files changed

+11
-163
lines changed

6 files changed

+11
-163
lines changed

charts/platform-registry/templates/deployment.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ spec:
4848
{{- if .Values.platform.token }}
4949
{{ toYaml .Values.platform.token | indent 10 }}
5050
{{- end }}
51-
{{- if .Values.zipkin }}
52-
- name: NP_ZIPKIN_URL
53-
value: {{ .Values.zipkin.url }}
54-
- name: NP_ZIPKIN_SAMPLE_RATE
55-
value: {{ .Values.zipkin.sampleRate | default 0 | quote }}
56-
{{- end }}
5751
{{- if .Values.sentry }}
58-
- name: NP_SENTRY_DSN
52+
- name: SENTRY_DSN
5953
value: {{ .Values.sentry.dsn }}
60-
- name: NP_SENTRY_CLUSTER_NAME
54+
- name: SENTRY_CLUSTER_NAME
6155
value: {{ .Values.sentry.clusterName }}
56+
- name: SENTRY_APP_NAME
57+
value: {{ .Values.sentry.appName }}
6258
- name: NP_SENTRY_SAMPLE_RATE
6359
value: {{ .Values.sentry.sampleRate | default 0 | quote }}
6460
{{- end }}

charts/platform-registry/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ ingress:
3939
service:
4040
annotations: {}
4141

42-
zipkin: {}
43-
44-
sentry: {}
42+
sentry:
43+
appName: platform-registry
44+
sampleRate: 0.002
4545

4646
priorityClassName: ""

platform_registry_api/api.py

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from aiohttp.web import (
3232
Application,
3333
HTTPBadRequest,
34+
HTTPForbidden,
3435
HTTPNotFound,
3536
HTTPUnauthorized,
3637
Request,
@@ -44,11 +45,7 @@
4445
from neuro_auth_client.security import AuthScheme, setup_security
4546
from neuro_logging import (
4647
init_logging,
47-
make_sentry_trace_config,
48-
make_zipkin_trace_config,
4948
setup_sentry,
50-
setup_zipkin,
51-
setup_zipkin_tracer,
5249
trace,
5350
)
5451
from yarl import URL
@@ -914,18 +911,6 @@ async def add_version_to_header(request: Request, response: StreamResponse) -> N
914911
response.headers["X-Service-Version"] = f"platform-registry-api/{package_version}"
915912

916913

917-
def make_tracing_trace_configs(config: Config) -> list[aiohttp.TraceConfig]:
918-
trace_configs = []
919-
920-
if config.zipkin:
921-
trace_configs.append(make_zipkin_trace_config())
922-
923-
if config.sentry:
924-
trace_configs.append(make_sentry_trace_config())
925-
926-
return trace_configs
927-
928-
929914
async def create_app(config: Config) -> aiohttp.web.Application:
930915
app = aiohttp.web.Application()
931916

@@ -946,7 +931,6 @@ async def on_request_redirect(
946931

947932
session = await exit_stack.enter_async_context(
948933
aiohttp.ClientSession(
949-
trace_configs=[trace_config] + make_tracing_trace_configs(config),
950934
connector=aiohttp.TCPConnector(force_close=True),
951935
)
952936
)
@@ -967,24 +951,19 @@ async def on_request_redirect(
967951
)
968952

969953
if is_aws:
970-
client = app["v2_app"]["upstream"]._client
971-
exclude = [client.exceptions.RepositoryNotFoundException]
972-
else:
973-
exclude = []
954+
app["v2_app"]["upstream"]._client
974955

975956
auth_client = await exit_stack.enter_async_context(
976957
AuthClient(
977958
url=config.auth.server_endpoint_url,
978959
token=config.auth.service_token,
979-
trace_configs=make_tracing_trace_configs(config),
980960
)
981961
)
982962
app["v2_app"]["auth_client"] = auth_client
983963

984964
await setup_security(
985965
app=app, auth_client=auth_client, auth_scheme=AuthScheme.BASIC
986966
)
987-
setup_tracing(config, exclude)
988967

989968
yield
990969

@@ -999,39 +978,17 @@ async def on_request_redirect(
999978

1000979
app.on_response_prepare.append(add_version_to_header)
1001980

1002-
if config.zipkin:
1003-
setup_zipkin(app)
1004-
1005981
return app
1006982

1007983

1008-
def setup_tracing(config: Config, exclude: list[type[BaseException]]) -> None:
1009-
if config.zipkin:
1010-
setup_zipkin_tracer(
1011-
config.zipkin.app_name,
1012-
config.server.host,
1013-
config.server.port,
1014-
config.zipkin.url,
1015-
config.zipkin.sample_rate,
1016-
)
1017-
1018-
if config.sentry:
1019-
setup_sentry(
1020-
config.sentry.dsn,
1021-
app_name=config.sentry.app_name,
1022-
cluster_name=config.sentry.cluster_name,
1023-
sample_rate=config.sentry.sample_rate,
1024-
exclude=exclude,
1025-
)
1026-
1027-
1028984
def main() -> None:
1029985
init_logging()
1030986

1031987
loop = asyncio.get_event_loop()
1032988

1033989
config = EnvironConfigFactory().create()
1034990
logger.info("Loaded config: %r", config)
991+
setup_sentry(ignore_errors=[HTTPUnauthorized, HTTPForbidden])
1035992
app = loop.run_until_complete(create_app(config))
1036993
aiohttp.web.run_app(app, host=config.server.host, port=config.server.port)
1037994

platform_registry_api/config.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,12 @@ def is_oauth(self) -> bool:
6060
return self.type == UpstreamType.OAUTH
6161

6262

63-
@dataclass(frozen=True)
64-
class ZipkinConfig:
65-
url: URL
66-
app_name: str = "platform-registry"
67-
sample_rate: float = 0
68-
69-
70-
@dataclass(frozen=True)
71-
class SentryConfig:
72-
dsn: URL
73-
cluster_name: str
74-
app_name: str = "platform-registry"
75-
sample_rate: float = 0
76-
77-
7863
@dataclass(frozen=True)
7964
class Config:
8065
server: ServerConfig
8166
upstream_registry: UpstreamRegistryConfig
8267
auth: AuthConfig
8368
cluster_name: str
84-
zipkin: ZipkinConfig | None = None
85-
sentry: SentryConfig | None = None
8669

8770

8871
class EnvironConfigFactory:
@@ -158,43 +141,15 @@ def create_auth(self) -> AuthConfig:
158141
token = self._environ["NP_REGISTRY_AUTH_TOKEN"]
159142
return AuthConfig(server_endpoint_url=url, service_token=token)
160143

161-
def create_zipkin(self) -> ZipkinConfig | None:
162-
if "NP_ZIPKIN_URL" not in self._environ:
163-
return None
164-
165-
url = URL(self._environ["NP_ZIPKIN_URL"])
166-
app_name = self._environ.get("NP_ZIPKIN_APP_NAME", ZipkinConfig.app_name)
167-
sample_rate = float(
168-
self._environ.get("NP_ZIPKIN_SAMPLE_RATE", ZipkinConfig.sample_rate)
169-
)
170-
return ZipkinConfig(url=url, app_name=app_name, sample_rate=sample_rate)
171-
172-
def create_sentry(self) -> SentryConfig | None:
173-
if "NP_SENTRY_DSN" not in self._environ:
174-
return None
175-
176-
return SentryConfig(
177-
dsn=URL(self._environ["NP_SENTRY_DSN"]),
178-
cluster_name=self._environ["NP_SENTRY_CLUSTER_NAME"],
179-
app_name=self._environ.get("NP_SENTRY_APP_NAME", SentryConfig.app_name),
180-
sample_rate=float(
181-
self._environ.get("NP_SENTRY_SAMPLE_RATE", SentryConfig.sample_rate)
182-
),
183-
)
184-
185144
def create(self) -> Config:
186145
server_config = self.create_server()
187146
upstream_registry_config = self.create_upstream_registry()
188147
auth_config = self.create_auth()
189-
zipkin_config = self.create_zipkin()
190-
sentry_config = self.create_sentry()
191148
cluster_name = self._environ["NP_CLUSTER_NAME"]
192149
assert cluster_name
193150
return Config(
194151
server=server_config,
195152
upstream_registry=upstream_registry_config,
196153
auth=auth_config,
197154
cluster_name=cluster_name,
198-
zipkin=zipkin_config,
199-
sentry=sentry_config,
200155
)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ install_requires =
2727
# have it fixed. See the issue above for testing instructions.
2828
uvloop==0.19.0
2929
aiobotocore==2.12.3
30-
neuro-logging==21.12.2
30+
neuro-logging==24.4.0
3131
trafaret==2.1.1
3232
yarl==1.9.4
3333

tests/unit/test_config.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
AuthConfig,
55
Config,
66
EnvironConfigFactory,
7-
SentryConfig,
87
ServerConfig,
98
UpstreamRegistryConfig,
109
UpstreamType,
11-
ZipkinConfig,
1210
)
1311

1412

@@ -64,9 +62,6 @@ def test_oauth(self) -> None:
6462
"NP_REGISTRY_UPSTREAM_TOKEN_REGISTRY_SCOPE": "",
6563
"NP_REGISTRY_UPSTREAM_TOKEN_REPO_SCOPE_ACTIONS": "push,pull",
6664
"NP_CLUSTER_NAME": "test-cluster",
67-
"NP_ZIPKIN_URL": "http://zipkin.io:9411/",
68-
"NP_SENTRY_DSN": "https://sentry",
69-
"NP_SENTRY_CLUSTER_NAME": "test",
7065
}
7166
config = EnvironConfigFactory(environ=environ).create()
7267
assert config == Config(
@@ -88,8 +83,6 @@ def test_oauth(self) -> None:
8883
service_token="test_auth_token",
8984
),
9085
cluster_name="test-cluster",
91-
zipkin=ZipkinConfig(URL("http://zipkin.io:9411/")),
92-
sentry=SentryConfig(dsn=URL("https://sentry"), cluster_name="test"),
9386
)
9487
assert config.upstream_registry.is_oauth
9588

@@ -179,56 +172,3 @@ def test_basic(self) -> None:
179172
)
180173
assert config.upstream_registry.is_basic
181174
assert not config.upstream_registry.is_oauth
182-
183-
def test_create_zipkin_none(self) -> None:
184-
result = EnvironConfigFactory({}).create_zipkin()
185-
186-
assert result is None
187-
188-
def test_create_zipkin_default(self) -> None:
189-
env = {"NP_ZIPKIN_URL": "https://zipkin:9411"}
190-
result = EnvironConfigFactory(env).create_zipkin()
191-
192-
assert result == ZipkinConfig(url=URL("https://zipkin:9411"))
193-
194-
def test_create_zipkin_custom(self) -> None:
195-
env = {
196-
"NP_ZIPKIN_URL": "https://zipkin:9411",
197-
"NP_ZIPKIN_APP_NAME": "api",
198-
"NP_ZIPKIN_SAMPLE_RATE": "1",
199-
}
200-
result = EnvironConfigFactory(env).create_zipkin()
201-
202-
assert result == ZipkinConfig(
203-
url=URL("https://zipkin:9411"), app_name="api", sample_rate=1
204-
)
205-
206-
def test_create_sentry_none(self) -> None:
207-
result = EnvironConfigFactory({}).create_sentry()
208-
209-
assert result is None
210-
211-
def test_create_sentry_default(self) -> None:
212-
env = {
213-
"NP_SENTRY_DSN": "https://sentry",
214-
"NP_SENTRY_CLUSTER_NAME": "test",
215-
}
216-
result = EnvironConfigFactory(env).create_sentry()
217-
218-
assert result == SentryConfig(dsn=URL("https://sentry"), cluster_name="test")
219-
220-
def test_create_sentry_custom(self) -> None:
221-
env = {
222-
"NP_SENTRY_DSN": "https://sentry",
223-
"NP_SENTRY_APP_NAME": "api",
224-
"NP_SENTRY_CLUSTER_NAME": "test",
225-
"NP_SENTRY_SAMPLE_RATE": "1",
226-
}
227-
result = EnvironConfigFactory(env).create_sentry()
228-
229-
assert result == SentryConfig(
230-
dsn=URL("https://sentry"),
231-
app_name="api",
232-
cluster_name="test",
233-
sample_rate=1,
234-
)

0 commit comments

Comments
 (0)