-
Notifications
You must be signed in to change notification settings - Fork 12
CP-47394: Shard Alloy work across replicas #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| {{- /* | ||
| Headless service for Alloy cluster peer discovery. | ||
|
|
||
| Only rendered in clustered mode, where the Alloy container runs. Alloy replicas | ||
| find each other through --cluster.join-addresses (see agent-deploy.yaml), which | ||
| resolves this name via DNS and expects one A record per replica. | ||
|
|
||
| Two properties matter and are not interchangeable with the regular server | ||
| service in agent-service.yaml: | ||
|
|
||
| - clusterIP: None. A normal ClusterIP service load-balances to a single | ||
| backend, so a replica would discover at most one arbitrary peer. Headless | ||
| DNS returns every pod IP, which is what forms a complete ring. | ||
|
|
||
| - publishNotReadyAddresses: true. A starting replica has to be discoverable | ||
| before it passes its readiness probe, otherwise a full restart of the | ||
| deployment deadlocks: no pod is in the service until it is ready, and the | ||
| ring cannot form from pods that cannot see each other. | ||
|
|
||
| The port must match --server.http.listen-addr in agent-deploy.yaml; Alloy | ||
| gossips over its HTTP listen port rather than a dedicated one. | ||
| */ -}} | ||
| {{- if eq (include "cloudzero-agent.Values.components.agent.mode" .) "clustered" }} | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: {{ include "cloudzero-agent.server.clusterServiceName" . }} | ||
| namespace: {{ .Release.Namespace }} | ||
| {{- include "cloudzero-agent.generateLabels" (dict | ||
| "root" . | ||
| "name" "server" | ||
| "labels" (list | ||
| .Values.defaults.labels | ||
| .Values.commonMetaLabels | ||
| ) | ||
| ) | nindent 2 }} | ||
| {{- include "cloudzero-agent.generateAnnotations" (dict | ||
| "root" . | ||
| "annotations" (list | ||
| .Values.defaults.annotations | ||
| ) | ||
| ) | nindent 2 }} | ||
| spec: | ||
| type: ClusterIP | ||
| clusterIP: None | ||
| publishNotReadyAddresses: true | ||
| ports: | ||
| - port: 9090 | ||
| targetPort: 9090 | ||
| name: http-metrics | ||
| protocol: TCP | ||
| selector: | ||
| {{- include "cloudzero-agent.server.matchLabels" . | nindent 4 }} | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| suite: test Alloy cluster peer-discovery service | ||
| templates: | ||
| - templates/agent-cluster-service.yaml | ||
| tests: | ||
| # The service exists only to let Alloy replicas find each other, so it is | ||
| # pointless outside clustered mode, where no Alloy container runs. | ||
| - it: should not be rendered when Alloy is not in use | ||
| set: | ||
| components.agent.mode: agent | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 0 | ||
|
|
||
| - it: should not be rendered in server mode | ||
| set: | ||
| components.agent.mode: server | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 0 | ||
|
|
||
| - it: should be rendered in clustered mode | ||
| set: | ||
| components.agent.mode: clustered | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 1 | ||
| - isKind: | ||
| of: Service | ||
| - equal: | ||
| path: metadata.name | ||
| value: RELEASE-NAME-cz-server-cluster | ||
|
|
||
| # These two fields are the entire point of the service. A ClusterIP would | ||
| # load-balance discovery to a single arbitrary replica, and omitting | ||
| # publishNotReadyAddresses deadlocks a full restart, since a pod would have to | ||
| # be ready before its peers could find it. | ||
| - it: should be headless and publish not-ready addresses | ||
| set: | ||
| components.agent.mode: clustered | ||
| asserts: | ||
| - equal: | ||
| path: spec.clusterIP | ||
| value: None | ||
| - equal: | ||
| path: spec.publishNotReadyAddresses | ||
| value: true | ||
|
|
||
| # Alloy gossips over its HTTP listen port, so this must track | ||
| # --server.http.listen-addr in agent-deploy.yaml. | ||
| - it: should expose the Alloy HTTP listen port | ||
| set: | ||
| components.agent.mode: clustered | ||
| asserts: | ||
| - equal: | ||
| path: spec.ports[0].port | ||
| value: 9090 | ||
| - equal: | ||
| path: spec.ports[0].targetPort | ||
| value: 9090 | ||
|
|
||
| # Discovery only works if the selector matches the Alloy pods; a mismatch | ||
| # yields an empty DNS response and silently degrades to single-member rings. | ||
| - it: should select the server pods | ||
| set: | ||
| components.agent.mode: clustered | ||
| asserts: | ||
| - equal: | ||
| path: spec.selector["app.kubernetes.io/name"] | ||
| value: server | ||
|
|
||
| # The suffix is what makes this Service's name distinct from the regular | ||
| # server Service. Appending it and only then truncating to 63 would cut the | ||
| # suffix away for a name already at the limit, giving two Services one name: | ||
| # a duplicate resource on install, and on upgrade an attempt to convert an | ||
| # existing ClusterIP Service to a headless one, which Kubernetes rejects. | ||
| - it: should not collide with the server service name at the length limit | ||
| set: | ||
| components.agent.mode: clustered | ||
| server.fullnameOverride: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
| asserts: | ||
| - equal: | ||
| path: metadata.name | ||
| value: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-cluster | ||
|
|
||
| # A server name that already ends in the suffix rebuilds itself: trimming to | ||
| # 55 and appending "-cluster" reproduces the original exactly. Shortening | ||
| # further does not help, because the same reconstruction happens at other | ||
| # lengths -- hence the different fallback suffix. | ||
| - it: should not collide when the server name already ends in the suffix | ||
| set: | ||
| components.agent.mode: clustered | ||
| server.fullnameOverride: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-cluster" | ||
| asserts: | ||
| - notEqual: | ||
| path: metadata.name | ||
| value: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-cluster | ||
|
|
||
| # The 62-character variant, where trimming to 55 cuts the separator and the | ||
| # trailing dash is trimmed away, so a naive fallback that only shortens | ||
| # reconstructs the base a second time. | ||
| - it: should not collide at the length where shortening also reconstructs | ||
| set: | ||
| components.agent.mode: clustered | ||
| server.fullnameOverride: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-cluster" | ||
| asserts: | ||
| - notEqual: | ||
| path: metadata.name | ||
| value: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-cluster |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.