forked from memgraph/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_helpers.tpl
More file actions
230 lines (214 loc) · 6.28 KB
/
Copy path_helpers.tpl
File metadata and controls
230 lines (214 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
{{/*
Expand the name of the chart.
*/}}
{{- define "memgraph.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "memgraph.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "memgraph.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "memgraph.labels" -}}
helm.sh/chart: {{ include "memgraph.chart" . }}
{{ include "memgraph.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "memgraph.selectorLabels" -}}
app.kubernetes.io/name: {{ include "memgraph.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "memgraph.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "memgraph.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Create the name for mg-exporter resources.
*/}}
{{- define "memgraph.mgExporterName" -}}
{{- printf "%s-mg-exporter" (include "memgraph.fullname" .) | trunc 63 | trimSuffix "-" -}}
{{- end }}
{{/*
Create the config map name for mg-exporter resources.
*/}}
{{- define "memgraph.mgExporterConfigName" -}}
{{- printf "%s-config" (include "memgraph.mgExporterName" .) | trunc 63 | trimSuffix "-" -}}
{{- end }}
{{- define "container.readinessProbe" -}}
readinessProbe:
{{- if .exec }}
exec:
command:
{{- range .exec.command }}
- {{ . | quote }}
{{- end }}
{{- else }}
tcpSocket:
port: {{ .tcpSocket.port }}
{{- end }}
failureThreshold: {{ .failureThreshold }}
timeoutSeconds: {{ .timeoutSeconds }}
periodSeconds: {{ .periodSeconds }}
initialDelaySeconds: {{ .initialDelaySeconds }}
{{- end }}
{{- define "container.livenessProbe" -}}
livenessProbe:
{{- if .exec }}
exec:
command:
{{- range .exec.command }}
- {{ . | quote }}
{{- end }}
{{- else }}
tcpSocket:
port: {{ .tcpSocket.port }}
{{- end }}
failureThreshold: {{ .failureThreshold }}
timeoutSeconds: {{ .timeoutSeconds }}
periodSeconds: {{ .periodSeconds }}
initialDelaySeconds: {{ .initialDelaySeconds }}
{{- end }}
{{- define "container.startupProbe" -}}
startupProbe:
{{- if .exec }}
exec:
command:
{{- range .exec.command }}
- {{ . | quote }}
{{- end }}
{{- else }}
tcpSocket:
port: {{ .tcpSocket.port }}
{{- end }}
failureThreshold: {{ .failureThreshold }}
timeoutSeconds: {{ .timeoutSeconds }}
periodSeconds: {{ .periodSeconds }}
initialDelaySeconds: {{ .initialDelaySeconds }}
{{- end }}
{{- define "memgraph.vector.script" -}}
# Wait for Memgraph to open the log websocket (avoids "Connection refused" on startup)
max_wait_seconds=120
elapsed=0
until bash -c "exec 3<>/dev/tcp/127.0.0.1/{{ .Values.service.websocketPortMonitoring }}" >/dev/null 2>&1; do
if [ "$elapsed" -ge "$max_wait_seconds" ]; then
echo "Timed out waiting for Memgraph monitoring port {{ .Values.service.websocketPortMonitoring }} after ${max_wait_seconds}s" >&2
exit 1
fi
sleep 2
elapsed=$((elapsed + 2))
done
cat > /tmp/vector.yaml << VECEOF
data_dir: /tmp/vector-data
sources:
memgraph_logs:
type: websocket
uri: "ws://127.0.0.1:{{ .Values.service.websocketPortMonitoring }}"
transforms:
enrich:
type: remap
inputs: [memgraph_logs]
source: |
normalized_level = ""
if exists(.message) && is_string(.message) {
parsed, err = parse_json(.message)
if err == null && is_object(parsed) {
. = merge!(., parsed)
}
}
if exists(.level) {
normalized_level = downcase(to_string!(.level))
} else if exists(.severity) {
normalized_level = downcase(to_string!(.severity))
}
if normalized_level == "warning" {
normalized_level = "warn"
} else if normalized_level == "critical" {
normalized_level = "fatal"
}
if normalized_level == "" {
normalized_level = "unknown"
}
.level = normalized_level
if !exists(._msg) {
if exists(.message) {
._msg = to_string!(.message)
} else if exists(.msg) {
._msg = to_string!(.msg)
} else if exists(.log) {
._msg = to_string!(.log)
} else {
._msg = encode_json(.)
}
}
.message = ._msg
.app = "memgraph"
.job = "memgraph"
.role = get_env_var!("ROLE")
.namespace = get_env_var!("POD_NAMESPACE")
.pod = get_env_var!("POD_NAME")
.cluster_id = get_env_var!("CLUSTER_ID")
.service_name = get_env_var!("SERVICE_NAME")
.cluster_env = get_env_var!("CLUSTER_ENV")
sinks:
logs:
type: loki
inputs: [enrich]
endpoint: "{{ required "vectorRemote.logsEndpoint is required when vectorRemote is enabled" .Values.vectorRemote.logsEndpoint }}"
healthcheck:
enabled: false
{{- if .Values.vectorRemote.auth.secretName }}
auth:
strategy: basic
user: "{{ "$" }}{{ "{MONITORING_USERNAME}" }}"
password: "{{ "$" }}{{ "{MONITORING_PASSWORD}" }}"
{{- end }}
encoding:
codec: text
labels:
app: "{{ "{{ app }}" }}"
job: "{{ "{{ job }}" }}"
role: "{{ "{{ role }}" }}"
namespace: "{{ "{{ namespace }}" }}"
pod: "{{ "{{ pod }}" }}"
level: "{{ "{{ level }}" }}"
cluster_id: "{{ "{{ cluster_id }}" }}"
service_name: "{{ "{{ service_name }}" }}"
cluster_env: "{{ "{{ cluster_env }}" }}"
remove_label_fields: true
VECEOF
mkdir -p /tmp/vector-data
exec vector -c /tmp/vector.yaml
{{- end }}