Skip to content

Commit 68250e1

Browse files
committed
upstream pr tweaks
Signed-off-by: Tyler Horvath <[email protected]>
1 parent 9cca948 commit 68250e1

File tree

4 files changed

+120
-6
lines changed

4 files changed

+120
-6
lines changed

templates/ingress-distributor.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{- $root := . -}}
2+
{{- if .Values.distributor.ingresses.enabled -}}
3+
{{- $svcPort := .Values.distributor.service.port -}}
4+
{{- range .Values.distributor.ingresses.scopeIDs }}
5+
{{- $rootScope := . -}}
6+
{{- if semverCompare ">=1.14-0" $root.Capabilities.KubeVersion.GitVersion -}}
7+
---
8+
apiVersion: networking.k8s.io/v1beta1
9+
{{- else -}}
10+
apiVersion: extensions/v1beta1
11+
{{- end }}
12+
kind: Ingress
13+
metadata:
14+
name: {{ template "cortex.fullname" $root }}-{{ .scopeName }}
15+
labels:
16+
app: {{ template "cortex.name" $root }}
17+
chart: {{ template "cortex.chart" $root }}
18+
release: {{ $root.Release.Name }}
19+
heritage: {{ $root.Release.Service }}
20+
{{- with .annotations }}
21+
annotations:
22+
{{- toYaml . | nindent 4 }}
23+
nginx.ingress.kubernetes.io/configuration-snippet: |
24+
proxy_set_header X-Org-ScopeID {{ $rootScope.scopeID }};
25+
{{- end }}
26+
spec:
27+
{{- if .tls }}
28+
tls:
29+
- hosts:
30+
- {{ .tls.host | quote }}
31+
secretName: {{ .tls.secretName }}
32+
{{- end }}
33+
rules:
34+
- host: {{ .host | quote }}
35+
http:
36+
paths:
37+
- path: /api/prom/push
38+
backend:
39+
serviceName: {{ template "cortex.fullname" $root }}
40+
servicePort: {{ $svcPort }}
41+
---
42+
{{- end }}
43+
{{- end }}

templates/nginx-config.yaml

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,31 @@ data:
2020
worker_connections 4096; ## Default: 1024
2121
}
2222
23+
2324
http {
2425
default_type application/octet-stream;
2526
log_format main '$remote_addr - $remote_user [$time_local] $status '
2627
'"$request" $body_bytes_sent "$http_referer" '
27-
'"$http_user_agent" "$http_x_forwarded_for"';
28+
'"$http_user_agent" "$http_x_forwarded_for" $http_x_scope_orgid';
2829
access_log /dev/stderr main;
2930
sendfile on;
3031
tcp_nopush on;
3132
resolver {{ default "kube-dns.kube-system.svc.cluster.local" .Values.nginx.config.dnsResolver }};
32-
33+
{{- if .Values.config.auth_enabled }}
34+
map $http_x_org_scopeid $scopeid {
35+
default $http_x_org_scopeid;
36+
"" "{{ .Values.auth.defaultScope }}";
37+
}
38+
{{- end }}
3339
server { # simple reverse-proxy
3440
listen {{ .Values.nginx.http_listen_port }};
35-
#proxy_set_header X-Scope-OrgID 0;
41+
{{- if .Values.config.auth_enabled }}
42+
proxy_set_header X-Scope-OrgID $scopeid;
43+
{{- end }}
3644
proxy_connect_timeout 300s;
3745
proxy_send_timeout 300s;
3846
proxy_read_timeout 300s;
39-
47+
4048
location = /healthz {
4149
return 200 'alive';
4250
}
@@ -48,13 +56,46 @@ data:
4856
location = /ring {
4957
proxy_pass http://{{ template "cortex.fullname" . }}-distributor.{{ .Release.Namespace }}.svc.cluster.local$request_uri;
5058
}
59+
5160
location = /all_user_stats {
5261
proxy_pass http://{{ template "cortex.fullname" . }}-distributor.{{ .Release.Namespace }}.svc.cluster.local$request_uri;
5362
}
5463

5564
location ~ /api/prom/.* {
5665
proxy_pass http://{{ template "cortex.fullname" . }}-query-frontend.{{ .Release.Namespace }}.svc.cluster.local$request_uri;
5766
}
67+
68+
# Alertmanager Config
69+
location ~ /api/v1/alerts {
70+
proxy_pass http://{{ template "cortex.fullname" . }}-alertmanager.{{ .Release.Namespace }}.svc.cluster.local$request_uri;
71+
}
72+
73+
location ~ /multitenant_alertmanager/status {
74+
proxy_pass http://{{ template "cortex.fullname" . }}-alertmanager.{{ .Release.Namespace }}.svc.cluster.local$request_uri;
75+
}
76+
77+
{{- $root := . }}
78+
{{- range .Values.alertmanager.ui.scopeIDs }}
79+
{{ $rootScope := . }}
80+
location = /alerts/{{ $rootScope.scopeName }} {
81+
proxy_set_header X-Scope-OrgID {{ $rootScope.scopeID }};
82+
proxy_pass http://{{ template "cortex.fullname" $root }}-alertmanager.{{ $root.Release.Namespace }}.svc.cluster.local/api/prom/alertmanager/;
83+
}
84+
85+
location ~ /alerts/{{ $rootScope.scopeName }}/(.*) {
86+
proxy_set_header X-Scope-OrgID {{ $rootScope.scopeID }};
87+
proxy_pass http://{{ template "cortex.fullname" $root }}-alertmanager.{{ $root.Release.Namespace }}.svc.cluster.local/api/prom/alertmanager/$1;
88+
}
89+
{{- end }}
90+
91+
# Ruler Config
92+
location ~ /api/v1/rules {
93+
proxy_pass http://{{ template "cortex.fullname" . }}-ruler.{{ .Release.Namespace }}.svc.cluster.local$request_uri;
94+
}
95+
96+
location ~ /ruler/ring {
97+
proxy_pass http://{{ template "cortex.fullname" . }}-ruler.{{ .Release.Namespace }}.svc.cluster.local$request_uri;
98+
}
5899
}
59100
}
60-
{{- end}}
101+
{{- end }}

templates/ruler-dep.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ spec:
6060
- "-target=ruler"
6161
- "-config.file=/etc/cortex/cortex.yaml"
6262
- "-ruler.configs.url=http://{{ template "cortex.fullname" . }}-configs.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.config.server.http_listen_port }}"
63-
- "-ruler.alertmanager-url=http://{{ template "cortex.fullname" . }}-alertmanager.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.config.server.http_listen_port }}/api/prom/alertmanager/"
63+
- "-ruler.alertmanager-discovery=true"
64+
- "-ruler.alertmanager-url=http://_http-metrics._tcp.{{ template "cortex.name" . }}-alertmanager-headless/api/prom/alertmanager/"
6465
{{- if .Values.memcached.enabled }}
6566
- -store.chunks-cache.memcached.addresses=dns+{{ template "cortex.fullname" . }}-memcached.{{ .Release.Namespace }}.svc.cluster.local:11211
6667
- -store.chunks-cache.memcached.timeout=100ms

values.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ serviceAccount:
3636
useExternalConfig: false
3737
externalConfigSecretName: 'secret-with-config.yaml'
3838
externalConfigVersion: '0'
39+
40+
auth:
41+
# Make sure you enabled config.auth_enabled if you want to use auth
42+
defaultScope: "defaultScope"
43+
3944
config:
4045
auth_enabled: false
4146
ingester:
@@ -155,6 +160,12 @@ rbac:
155160

156161
alertmanager:
157162
replicas: 1
163+
ui:
164+
# If nginx is enabled, this will create a path at your ingress
165+
# at hostname/alerts/scopeName - allowing you to visit the alertmanager UI per scopeID
166+
scopeIDs:
167+
- scopeName: default
168+
scopeID: "defaultScope"
158169

159170
statefulSet:
160171
## If true, use a statefulset instead of a deployment for pod management.
@@ -312,6 +323,24 @@ alertmanager:
312323

313324
distributor:
314325
replicas: 2
326+
ingresses:
327+
## If true - can be used to make an ingress per scopeID. It still forwards to the nginx
328+
# service, but its meant to allow seperate ingress routes (and subsequently annotations)
329+
# for different auth/scope ids - allowing distinct things like basic auth to be configured per
330+
# client
331+
enabled: false
332+
annotations:
333+
kubernetes.io/ingress.class: nginx
334+
# kubernetes.io/tls-acme: "true"
335+
scopeIDs:
336+
- scopeID: someScopeID
337+
host: someScopeID.chart-example.local
338+
paths:
339+
- /api/prom/push
340+
tls: []
341+
# - secretName: chart-example-tls
342+
# hosts:
343+
# - chart-example.local
315344

316345
service:
317346
annotations: {}

0 commit comments

Comments
 (0)