Skip to content

Commit

Permalink
Add the ability to set an additional service for the recevier (#1213)
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
petewall authored Feb 7, 2025
1 parent d23456c commit 82e2880
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 0 deletions.
3 changes: 3 additions & 0 deletions charts/k8s-monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ podLogs:
| alloy-receiver.controller.type | string | `"daemonset"` | The type of controller to use for the Alloy Receiver instance. |
| alloy-receiver.enabled | bool | `false` | Deploy the Alloy instance for opening receivers to collect application data. |
| alloy-receiver.extraConfig | string | `""` | Extra Alloy configuration to be added to the configuration file. |
| alloy-receiver.extraService.enabled | bool | `false` | Create an extra service for the Alloy receiver. This service will mirror the alloy-receiver service, but its name can be customized to match existing application settings. |
| alloy-receiver.extraService.fullname | string | `""` | If set, the full name of the extra service to create. This will result in the format `<fullname>`. |
| alloy-receiver.extraService.name | string | `"alloy"` | The name of the extra service to create. This will result in the format `<release-name>-<name>`. |
| alloy-receiver.liveDebugging.enabled | bool | `false` | Enable live debugging for the Alloy instance. Requires stability level to be set to "experimental". |
| alloy-receiver.logging.format | string | `"logfmt"` | Format to use for writing Alloy log lines. |
| alloy-receiver.logging.level | string | `"info"` | Level at which Alloy log lines should be written. |
Expand Down
42 changes: 42 additions & 0 deletions charts/k8s-monitoring/templates/receiver-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- if and (index .Values "alloy-receiver").enabled (index .Values "alloy-receiver").extraService.enabled -}}
{{- $name := printf "%s-%s" .Release.Name (index .Values "alloy-receiver").extraService.name | trunc 63 | trimSuffix "-" }}
{{- if (index .Values "alloy-receiver").extraService.fullname }}
{{- $name = (index .Values "alloy-receiver").extraService.fullname }}
{{- end }}

apiVersion: v1
kind: Service
metadata:
name: {{ $name }}
labels:
{{- include "alloy.labels" (index .Subcharts "alloy-receiver") | nindent 4 }}
app.kubernetes.io/component: networking
{{- with (index .Values "alloy-receiver").service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ (index .Values "alloy-receiver").service.type }}
{{- if (index .Values "alloy-receiver").service.clusterIP }}
clusterIP: {{ (index .Values "alloy-receiver").service.clusterIP }}
{{- end }}
selector:
{{- include "alloy.selectorLabels" . | nindent 4 }}
{{- if semverCompare ">=1.26-0" .Capabilities.KubeVersion.Version }}
internalTrafficPolicy: {{ (index .Values "alloy-receiver").service.internalTrafficPolicy}}
{{- end }}
ports:
- name: http-metrics
{{- if eq (index .Values "alloy-receiver").service.type "NodePort" }}
nodePort: {{ (index .Values "alloy-receiver").service.nodePort }}
{{- end }}
port: {{ (index .Values "alloy-receiver").alloy.listenPort }}
targetPort: {{ (index .Values "alloy-receiver").alloy.listenPort }}
protocol: "TCP"
{{- range $portMap := (index .Values "alloy-receiver").alloy.extraPorts }}
- name: {{ $portMap.name }}
port: {{ $portMap.port }}
targetPort: {{ $portMap.targetPort }}
protocol: {{ coalesce $portMap.protocol "TCP" }}
{{- end }}
{{- end }}
109 changes: 109 additions & 0 deletions charts/k8s-monitoring/tests/receiver-service_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# yamllint disable rule:document-start rule:line-length rule:trailing-spaces
suite: Test Extra Receiver Service
templates:
- receiver-service.yaml
tests:
- it: does not create a Service by default
set:
cluster: {name: test-cluster}
alloy-receiver:
enabled: true
extraConfig: " "
asserts:
- hasDocuments:
count: 0

- it: creates a Service when enabled
set:
cluster: {name: test-cluster}
alloy-receiver:
enabled: true
extraConfig: " "
extraService:
enabled: true
asserts:
- hasDocuments:
count: 1
- isKind:
of: Service
- equal:
path: metadata.name
value: RELEASE-NAME-alloy

- it: creates a Service with a specified name
set:
cluster: {name: test-cluster}
alloy-receiver:
enabled: true
extraConfig: " "
extraService:
enabled: true
name: alloy-ingester
asserts:
- hasDocuments:
count: 1
- isKind:
of: Service
- equal:
path: metadata.name
value: RELEASE-NAME-alloy-ingester

- it: creates a Service with a specified full name
set:
cluster: {name: test-cluster}
alloy-receiver:
enabled: true
extraConfig: " "
extraService:
enabled: true
fullname: alloy-ingester
asserts:
- hasDocuments:
count: 1
- isKind:
of: Service
- equal:
path: metadata.name
value: alloy-ingester

- it: has the same extraPorts as the main receiver
set:
cluster: {name: test-cluster}
alloy-receiver:
enabled: true
extraConfig: " "
alloy:
extraPorts:
- name: otlp-http
port: 4318
targetPort: 4318
protocol: TCP
- name: otlp-grpc
port: 4317
targetPort: 4317
protocol: TCP
extraService:
enabled: true
asserts:
- hasDocuments:
count: 1
- isKind:
of: Service
- equal:
path: spec.ports
value:
- name: http-metrics
port: 12345
targetPort: 12345
protocol: TCP
- name: otlp-http
port: 4318
targetPort: 4318
protocol: TCP
- name: otlp-grpc
port: 4317
targetPort: 4317
protocol: TCP



14 changes: 14 additions & 0 deletions charts/k8s-monitoring/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,20 @@
"extraConfig": {
"type": "string"
},
"extraService": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"fullname": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"liveDebugging": {
"type": "object",
"properties": {
Expand Down
12 changes: 12 additions & 0 deletions charts/k8s-monitoring/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,18 @@ alloy-receiver:
# @ignored
crds: {create: false}

extraService:
# -- Create an extra service for the Alloy receiver. This service will mirror the alloy-receiver service, but its
# name can be customized to match existing application settings.
# @section -- Collectors - Alloy Receiver
enabled: false
# -- The name of the extra service to create. This will result in the format `<release-name>-<name>`.
# @section -- Collectors - Alloy Receiver
name: alloy
# -- If set, the full name of the extra service to create. This will result in the format `<fullname>`.
# @section -- Collectors - Alloy Receiver
fullname: ""

# An Alloy instance for gathering profiles.
# To see additional valid options, please see the [Alloy Helm chart documentation](https://github.com/grafana/alloy/tree/main/operations/helm/charts/alloy).
alloy-profiles:
Expand Down

0 comments on commit 82e2880

Please sign in to comment.