Skip to content

Commit f80f8b4

Browse files
Adds eureka and test infrastructure to support it (#15)
This adds Eureka discovery properties, and some test infrastructure so we can easily verify it from a different (test) pod. Signed-off-by: Adrian Cole <[email protected]>
1 parent 3038dc9 commit f80f8b4

10 files changed

+166
-6
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ You can then run `helm search repo zipkin` to see the charts.
2121
| Key | Type | Default | Description |
2222
|--------------------------------------------|--------|------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2323
| affinity | object | `{}` | |
24+
| args | list | `[]` | arguments to the zipkin start command |
2425
| autoscaling.enabled | bool | `false` | |
2526
| autoscaling.maxReplicas | int | `100` | |
2627
| autoscaling.minReplicas | int | `1` | |
2728
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
29+
| command | list | `["start-zipkin"]` | command used to start zipkin |
2830
| fullnameOverride | string | `""` | |
2931
| image.pullPolicy | string | `"IfNotPresent"` | |
3032
| image.repository | string | `"openzipkin/zipkin-slim"` | |
@@ -54,6 +56,11 @@ You can then run `helm search repo zipkin` to see the charts.
5456
| serviceAccount.name | string | `""` | If not set and create is true, a name is generated using the fullname template |
5557
| serviceAccount.psp | bool | `false` | |
5658
| tolerations | list | `[]` | |
59+
| zipkin.discovery.eureka.serviceUrl | string | no default | v2 endpoint of Eureka, e.g. `https://eureka-prod/eureka/v2` |
60+
| zipkin.discovery.eureka.app | string | `"zipkin"` | The application this instance registers to |
61+
| zipkin.discovery.eureka.hostName | string | detects | The instance `hostName` and `vipAddress` |
62+
| zipkin.discovery.eureka.instanceId | string | `"hostName:app:port"` | |
63+
| zipkin.storage.type | string | `"mem"` | |
5764
| zipkin.selfTracing.enabled | bool | `false` | |
5865
| zipkin.storage.elasticsearch.hosts | string | no default | |
5966
| zipkin.storage.elasticsearch.index | string | `"zipkin"` | |

charts/zipkin/ci/default-values.yaml

-2
This file was deleted.

charts/zipkin/ci/eureka-values.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# To avoid a race, sleep until Eureka is running before starting zipkin.
3+
command: ['/bin/sh', '-c']
4+
args:
5+
- 'while ! wget -q --spider http://localhost:8761/eureka/v2/apps;do sleep 1; done && start-zipkin'
6+
7+
zipkin:
8+
discovery:
9+
eureka:
10+
serviceUrl: http://localhost:8761/eureka/v2
11+
hostName: zipkin
12+
13+
# extra containers are in the same pod, so this means Eureka is accessible to
14+
# zipkin via localhost.
15+
extraContainers:
16+
- name: eureka
17+
image: 'ghcr.io/openzipkin/zipkin-eureka'
18+
ports:
19+
- containerPort: 8761
20+
21+
# test-connection runs in a different pod, so it can't verify Eureka unless we
22+
# expose a service port.
23+
extraServicePorts:
24+
- port: 8761
25+
targetPort: 8761
26+
protocol: TCP
27+
name: eureka
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Tests use a different pod and access zipkin via its service port.
3+
# This makes sure we can change this to a value different from what the
4+
# container listens on (9411).
5+
service:
6+
port: 9413
7+
8+
zipkin: {}

charts/zipkin/templates/_helpers.tpl

+11
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ Add extra containers to the pod spec
9292
{{- end }}
9393
{{- end }}
9494
{{- end }}
95+
96+
{{/*
97+
Add extra ports to the pod spec
98+
*/}}
99+
{{- define "zipkin.extraServicePorts" -}}
100+
{{- if .Values.extraServicePorts }}
101+
{{- with .Values.extraServicePorts }}
102+
{{- toYaml . | nindent 2 }}
103+
{{- end }}
104+
{{- end }}
105+
{{- end }}

charts/zipkin/templates/deployment.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,41 @@ spec:
4747
securityContext:
4848
{{- toYaml .Values.securityContext | nindent 12 }}
4949
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
50+
{{- if .Values.command }}
51+
command:
52+
{{- range .Values.command }}
53+
- {{ . }}
54+
{{- end }}
55+
{{- end }}
56+
{{- if .Values.args }}
57+
args:
58+
{{- range .Values.args }}
59+
- {{ . }}
60+
{{- end }}
61+
{{- end }}
5062
env:
5163
{{- if .Values.zipkin.selfTracing.enabled }}
5264
- name: SELF_TRACING_ENABLED
5365
value: "true"
5466
{{- end }}
67+
{{- if .Values.zipkin.discovery.eureka }}
68+
{{- with .Values.zipkin.discovery.eureka }}
69+
- name: EUREKA_SERVICE_URL
70+
value: {{ .serviceUrl | quote }}
71+
{{- if .app }}
72+
- name: EUREKA_APP_NAME
73+
value: {{ .app | quote }}
74+
{{- end }}
75+
{{- if .hostName }}
76+
- name: EUREKA_APP_NAME
77+
value: {{ .hostName | quote }}
78+
{{- end }}
79+
{{- if .instanceId }}
80+
- name: EUREKA_INSTANCE_ID
81+
value: {{ .instanceId | quote }}
82+
{{- end }}
83+
{{- end }}
84+
{{- end }}
5585
- name: STORAGE_TYPE
5686
value: "{{ .Values.zipkin.storage.type }}"
5787
{{- if eq .Values.zipkin.storage.type "elasticsearch" }}

charts/zipkin/templates/service.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ spec:
2525
targetPort: 9411
2626
protocol: TCP
2727
name: http-query
28+
{{- include "zipkin.extraServicePorts" . | nindent 2 }}
2829
selector:
2930
{{- include "zipkin.selectorLabels" . | nindent 4 }}

charts/zipkin/templates/tests/test-connection.yaml

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,23 @@ metadata:
99
"helm.sh/hook": test
1010
spec:
1111
containers:
12-
- name: get-api-services
12+
{{- if .Values.zipkin.discovery.eureka }}
13+
- name: verify-eureka
1314
image: 'ghcr.io/openzipkin/alpine:3.19.1'
1415
command: [ '/bin/sh', '-c' ]
16+
# Make sure zipkin registered in Eureka at startup
17+
args: [ 'wget -q --spider http://{{ include "zipkin.fullname" . }}:8761/eureka/v2/apps/ZIPKIN' ]
18+
{{- end }}
19+
- name: get-api
20+
image: "ghcr.io/openzipkin/alpine:3.19.1"
21+
command: [ '/bin/sh', '-c' ]
1522
# Get an arbitrary API endpoint using the ClusterIP and service port
16-
args: [ 'wget -qO ---spider --header "b3: cafebabecafebabe-cafebabecafebabe-1" http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/services' ]
23+
args: [ 'wget -q --spider --header "b3: cafebabecafebabe-cafebabecafebabe-1" http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/services' ]
1724
{{- if .Values.zipkin.selfTracing.enabled }}
1825
- name: get-trace
1926
image: 'ghcr.io/openzipkin/alpine:3.19.1'
2027
command: [ '/bin/sh', '-c' ]
2128
# If self-tracing, sleep for the trace to process. Then, get it by the constant ID passed above.
22-
args: [ 'sleep 3 && wget -qO ---spider http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/trace/cafebabecafebabe' ]
29+
args: [ 'sleep 3 && wget -q --spider http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/trace/cafebabecafebabe' ]
2330
{{- end }}
2431
restartPolicy: Never

charts/zipkin/values.schema.json

+57
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"affinity": {
66
"type": "object"
77
},
8+
"args": {
9+
"description": "Arguments to the zipkin start command",
10+
"type": "array",
11+
"items": {
12+
"type": "string"
13+
}
14+
},
815
"autoscaling": {
916
"type": "object",
1017
"properties": {
@@ -22,6 +29,26 @@
2229
}
2330
}
2431
},
32+
"command": {
33+
"description": "Zipkin start command",
34+
"type": "array",
35+
"items": {
36+
"type": "string"
37+
}
38+
},
39+
"extraServicePorts": {
40+
"type": "array",
41+
"items": {
42+
"type": "object",
43+
"required": ["name"],
44+
"properties": {
45+
"name": {"type": "string"},
46+
"protocol": {"enum": ["TCP", "UDP", "SCTP"]},
47+
"port": {"type": "integer"},
48+
"targetPort": {"type": "integer"}
49+
}
50+
}
51+
},
2552
"extraContainers": {
2653
"type": "array",
2754
"items": {
@@ -173,6 +200,36 @@
173200
"zipkin": {
174201
"type": "object",
175202
"properties": {
203+
"discovery": {
204+
"type": "object",
205+
"properties": {
206+
"eureka": {
207+
"type": "object",
208+
"properties": {
209+
"serviceUrl": {
210+
"type": "string"
211+
},
212+
"app": {
213+
"type": "string"
214+
},
215+
"hostName": {
216+
"type": "string"
217+
},
218+
"instanceId": {
219+
"type": "string"
220+
}
221+
},
222+
"required": [
223+
"serviceUrl"
224+
]
225+
},
226+
"type": {
227+
"enum": [
228+
"eureka"
229+
]
230+
}
231+
}
232+
},
176233
"storage": {
177234
"type": "object",
178235
"properties": {

charts/zipkin/values.yaml

+15-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ image:
1818
# Overrides the image tag whose default is the chart appVersion.
1919
tag: ""
2020

21+
# Zipkin start command
22+
command: ["start-zipkin"]
23+
# Arguments to pass to the zipkin start command
24+
args: []
25+
2126
imagePullSecrets: []
2227
nameOverride: ""
2328
fullnameOverride: ""
@@ -101,6 +106,7 @@ affinity: {}
101106
priorityClassName: ""
102107

103108
zipkin:
109+
discovery: {}
104110
# selfTracing generates traces for HTTP paths under /api
105111
selfTracing:
106112
enabled: false
@@ -113,5 +119,13 @@ zipkin:
113119
extraEnv: {}
114120
# JAVA_OPTS: "-Xms128m -Xmx512m -XX:+ExitOnOutOfMemoryError"
115121

116-
# extra containers to add to the same pod (accessible via localhost)
122+
# The below are typically only used in tests:
123+
# extra containers to add to the same pod.
117124
extraContainers: []
125+
126+
# extra ports to add besides the default service.port
127+
extraServicePorts: []
128+
# - port: 9410
129+
# targetPort: 9410
130+
# protocol: TCP
131+
# name: scribe

0 commit comments

Comments
 (0)