feat: replace zipkin with sentry traces (via otel)

This commit is contained in:
MiniDigger | Martin 2023-04-25 19:36:02 +02:00
parent de6b54b69a
commit 00f9e3bb05
13 changed files with 31 additions and 254 deletions

View File

@ -81,6 +81,7 @@ docker run -d -p 9411:9411 openzipkin/zipkin
```
Then just enable it in the `application.yml` under `management.tracing`.
You also need to comment in the dependency in the pom.xml
## License

View File

@ -232,6 +232,11 @@
<artifactId>sentry-logback</artifactId>
<version>${sentry.version}</version>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-opentelemetry-core</artifactId>
<version>${sentry.version}</version>
</dependency>
<!-- logging -->
<dependency>
@ -288,10 +293,10 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<!--dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
</dependency-->
<!-- cache -->
<dependency>

View File

@ -2,8 +2,12 @@ package io.papermc.hangar.config;
import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.aop.ObservedAspect;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.papermc.hangar.observability.CacheableObservationAspect;
import io.papermc.hangar.observability.ObservabilitySqlLogger;
import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor;
import io.sentry.opentelemetry.SentryPropagator;
import io.sentry.opentelemetry.SentrySpanProcessor;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.spi.JdbiPlugin;
import org.jdbi.v3.core.statement.SqlLogger;
@ -46,4 +50,20 @@ public class ObservabilityConfig {
}
};
}
// sentry
@Bean
public SentrySpanProcessor sentrySpanProcessor() {
return new SentrySpanProcessor();
}
@Bean
public ContextPropagators sentryPropagators() {
return ContextPropagators.create(new SentryPropagator());
}
@Bean
public OpenTelemetryLinkErrorEventProcessor otelLinkEventProcessor() {
return new OpenTelemetryLinkErrorEventProcessor();
}
}

View File

@ -38,7 +38,6 @@ public class ApplicationController extends HangarComponent {
.disallow("/error")
.disallow("/version-info")
.disallow("/api")
.disallow("/zipkin")
.disallow("/notifications")
.disallow("/*/settings")
.disallow("/*/*/channels")

View File

@ -68,6 +68,6 @@ public class ObservabilitySqlLogger implements SqlLogger {
private String getObservationName(final StatementContext context) {
final Method method = context.getExtensionMethod().getMethod();
return method.getDeclaringClass().getSimpleName() + "#" + method.getName();
return method.getDeclaringClass().getSimpleName().replace("DAO", "dao") + "#" + method.getName();
}
}

View File

@ -68,11 +68,3 @@ Create the name of the service account to use
{{- default "default" .Values.backend.serviceAccount.name }}
{{- end }}
{{- end }}
{{- define "hangar.zipkin.serviceAccountName" -}}
{{- if .Values.zipkin.serviceAccount.create }}
{{- default (printf "%s-zipkin" (include "hangar.fullname" .)) .Values.zipkin.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.zipkin.serviceAccount.name }}
{{- end }}
{{- end }}

View File

@ -1,74 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "hangar.fullname" . }}-zipkin
labels:
{{- include "hangar.labels" . | nindent 4 }}
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
selector:
matchLabels:
{{- include "hangar.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: "zipkin"
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret-hangar-zipkin.yaml") . | sha256sum }}
{{- with .Values.backend.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "hangar.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: "zipkin"
spec:
{{- with .Values.zipkin.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "hangar.zipkin.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.zipkin.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.zipkin.securityContext | nindent 12 }}
image: "{{ .Values.zipkin.image.repository }}:{{ .Values.zipkin.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.zipkin.image.pullPolicy }}
ports:
- name: http
containerPort: 9411
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 5
periodSeconds: 5
envFrom:
- secretRef:
name: hangar-zipkin
resources:
{{- toYaml .Values.zipkin.resources | nindent 12 }}
{{- with .Values.zipkin.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.zipkin.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.zipkin.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

View File

@ -1,44 +0,0 @@
{{- if .Values.zipkin.ingress.enabled -}}
{{- $fullName := include "hangar.fullname" . -}}
{{- $svcPort := .Values.zipkin.service.port -}}
{{- if and .Values.zipkin.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.zipkin.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.zipkin.ingress.annotations "kubernetes.io/ingress.class" .Values.zipkin.ingress.className}}
{{- end }}
{{- end }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}-zipkin
labels:
{{- include "hangar.labels" . | nindent 4 }}
{{- with .Values.zipkin.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.zipkin.ingress.className }}
{{- if .Values.zipkin.ingress.tls }}
tls:
{{- range .Values.zipkin.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
- host: {{ .Values.zipkin.ingress.host | quote }}
http:
paths:
{{- range .Values.zipkin.ingress.paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ $fullName }}-zipkin
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}

View File

@ -35,9 +35,6 @@ stringData:
enabled: true
tracing:
enabled: {{ .Values.backend.config.tracing }}
zipkin:
tracing:
endpoint: "{{ .Values.backend.config.zipkinEndpoint }}"
hangar:
dev: false
@ -75,6 +72,8 @@ stringData:
sentry:
dsn: "{{ .Values.backend.config.sentry.dsn }}"
environment: "{{ .Values.backend.config.sentry.environment }}"
traces-sample-rate: 1.0
instrumenter: "otel"
logging:
level:

View File

@ -1,10 +0,0 @@
apiVersion: v1
kind: Secret
metadata:
name: hangar-zipkin
labels:
{{- include "hangar.labels" . | nindent 4 }}
type: Opaque
stringData:
TEST: "{{ .Values.zipkin.config.test }}"
STORAGE_TYPE: mem

View File

@ -1,18 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "hangar.fullname" . }}-zipkin
labels:
{{- include "hangar.labels" . | nindent 4 }}
annotations:
service.kubernetes.io/topology-aware-hints: "auto"
spec:
type: {{ .Values.zipkin.service.type }}
ports:
- port: {{ .Values.zipkin.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "hangar.selectorLabels" . | nindent 4 }}
app.kubernetes.io/component: "zipkin"

View File

@ -1,12 +0,0 @@
{{- if .Values.zipkin.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "hangar.zipkin.serviceAccountName" . }}
labels:
{{- include "hangar.labels" . | nindent 4 }}
{{- with .Values.zipkin.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

View File

@ -192,7 +192,6 @@ backend:
cdnEndpoint: ""
cdnIncludeBucket: true
announcement: "This is a staging server for testing purposes. Data could be deleted at any time. That said, signups are open, please test stuff and report and feedback on github or discord!"
zipkinEndpoint: "http://hangar-zipkin:9411/api/v2/spans"
tracing: true
mail:
from: noreply@mail.papermc.dev
@ -200,83 +199,3 @@ backend:
pass: dum
host: mailslurper
port: 1025
zipkin:
image:
repository: ghcr.io/openzipkin/zipkin
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
ingress:
enabled: false
className: ""
annotations: { }
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
host: hangar.test
tls:
- secretName: hangar-tls
hosts:
- hangar.test
paths:
- path: /zipkin
pathType: ImplementationSpecific
serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
podAnnotations: {}
podSecurityContext:
fsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
service:
type: ClusterIP
port: 9411
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80
nodeSelector: {}
tolerations: []
affinity: {}
config:
test: "TEST"