Skip to content
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

feat: area/helm: Modify helm template to use http_listen_port and grpc_listen_port instead of hardcoded value #11646

Merged
merged 32 commits into from
Mar 15, 2024

Conversation

Sheikh-Abubaker
Copy link
Contributor

@Sheikh-Abubaker Sheikh-Abubaker commented Jan 10, 2024

What this PR does / why we need it:
This PR basically modifies helm template to use parameters http_listen_port and grpc_listen_port instead of hardcoded value to handle the cases where user assigns some other port other than default.
Which issue(s) this PR fixes:
Fixes #11641

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@Sheikh-Abubaker Sheikh-Abubaker requested a review from a team as a code owner January 10, 2024 21:42
Signed-off-by: Sheikh-Abubaker <[email protected]>
Copy link
Contributor

@bebosudo bebosudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it working for you?
My loki-read pod is stuck in an endless list of errors:

level=warn ts=2024-01-11T08:43:57.902636597Z caller=scheduler_processor.go:98 msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 172.28.12.169:9095: connect: connection refused\"" addr=172.28.12.169:9095
level=warn ts=2024-01-11T08:43:57.985055672Z caller=scheduler_processor.go:98 msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 172.28.12.169:9095: connect: connection refused\"" addr=172.28.12.169:9095
level=error ts=2024-01-11T08:43:58.268012236Z caller=frontend_scheduler_worker.go:237 msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 172.28.12.169:9095: connect: connection refused\"" addr=172.28.12.169:9095
level=error ts=2024-01-11T08:43:58.619265229Z caller=frontend_scheduler_worker.go:237 msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 172.28.12.169:9095: connect: connection refused\"" addr=172.28.12.169:9095
level=warn ts=2024-01-11T08:43:59.015424721Z caller=scheduler_processor.go:98 msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 172.28.12.169:9095: connect: connection refused\"" addr=172.28.12.169:9095
level=warn ts=2024-01-11T08:43:59.171403506Z caller=scheduler_processor.go:98 msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 172.28.12.169:9095: connect: connection refused\"" addr=172.28.12.169:9095
level=warn ts=2024-01-11T08:43:59.206568576Z caller=scheduler_processor.go:98 msg="error contacting scheduler" err="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 172.28.12.169:9095: connect: connection refused\"" addr=172.28.12.169:9095

The 172.28.12.169 address is the backend pod address.

There are many more places where we need to edit hardcoded values. I'll open a PR to your personal branch.

Edit: PR ready here: Sheikh-Abubaker#1. Already tested to be working fine.

The memberlist port is still hardcoded to 7946 (grep for it in the helm templates) though.

@@ -13,6 +13,10 @@ Entries should include a reference to the pull request that introduced the chang

[//]: # (<AUTOMATED_UPDATES_LOCATOR> : do not remove this line. This locator is used by the CI pipeline to automatically create a changelog entry for each new Loki release. Add other chart versions and respective changelog entries bellow this line.)

## 5.41.6

- [ENHANCEMENT] Modified helm template to use parameters http_listen_port and grpc_listen_port instead of hardcoded value of 3100 and 9095.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [ENHANCEMENT] Modified helm template to use parameters http_listen_port and grpc_listen_port instead of hardcoded value of 3100 and 9095.
- [ENHANCEMENT] Modified helm template to use parameters http_listen_port and grpc_listen_port instead of hardcoded values.

@@ -14,11 +14,11 @@ spec:
publishNotReadyAddresses: true
ports:
- name: http-metrics
port: 3100
port: {{ .Values.loki.server.http_listen_port | default 3100 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
port: {{ .Values.loki.server.http_listen_port | default 3100 }}
port: {{ .Values.loki.server.http_listen_port }}

No need to set defaults here too, if the user didn't specify the value, helm will use the default from the values.yaml provided by the helm chart, so that resolves to {{ 3100 | default 3100 }}.
This means that there are less "magic numbers" defined across the helm chart, and if the default values will need to be changed in the future they could be changed only in the values.yaml and it would be updated everywhere immediately.

targetPort: http-metrics
protocol: TCP
- name: grpc
port: 9095
port: {{ .Values.loki.server.grpc_listen_port | default 9095 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
port: {{ .Values.loki.server.grpc_listen_port | default 9095 }}
port: {{ .Values.loki.server.grpc_listen_port }}

@@ -28,11 +28,11 @@ spec:
clusterIP: None
ports:
- name: http-metrics
port: 3100
port: {{ .Values.loki.server.http_listen_port | default 3100 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
port: {{ .Values.loki.server.http_listen_port | default 3100 }}
port: {{ .Values.loki.server.http_listen_port }}

targetPort: http-metrics
protocol: TCP
- name: grpc
port: 9095
port: {{ .Values.loki.server.grpc_listen_port | default 9095 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
port: {{ .Values.loki.server.grpc_listen_port | default 9095 }}
port: {{ .Values.loki.server.grpc_listen_port }}

…ki_server_ports

[helm] Replace all hardcoded loki server ports
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jan 11, 2024
@bebosudo
Copy link
Contributor

The memberlist port is still hardcoded to 7946 (grep for it in the helm templates) though.

May I substitute those harcdoded value with varibles ? as we did it for http and grpc ?

The problem with that port number is that there is currently no variable in the helm values that defines the port, so the default port is hardcoded everywhere: if you grep for the port number 7946 you'll only find occurrences in service.yaml files, but not in config files! So if we search-and-replace it everywhere, loki will spawn the process on the default 7946, but the services would be listening on another port number.

From the loki docs it seems it can be set with the following variable:

# Gossip port to advertise to other members in the cluster. Used for NAT
# traversal.
# CLI flag: -memberlist.advertise-port
[advertise_port: <int> | default = 7946]

In the values file we can define values to be set in the memberlist section of the config. Therefore I added to my values the following:

loki:
  extraMemberlistConfig:  
    advertise_port: 7498

And the value shows up correctly in the configmap:

[alberto@fedora]$ k get cm/loki -o yaml
apiVersion: v1
data:
  config.yaml: |2
    ...
    memberlist:
      advertise_port: 7498
      join_members:
      - loki-memberlist

And loki seems to read it without any issue:

$ curl loki-backend:3101/config

target: backend
http_prefix: ""
...
memberlist:
  node_name: ""
  ...
  advertise_addr: ""
  advertise_port: 7498

But the pods are not obeying it somehow:

[alberto@fedora]$ k exec -it pod/loki-backend-0 -c loki -- sh
/ $ netstat -tuplen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 :::3101                 :::*                    LISTEN      1/loki
tcp        0      0 :::9096                 :::*                    LISTEN      1/loki
tcp        0      0 :::7946                 :::*                    LISTEN      1/loki

For this reason I'd open a separate issue. If you find a solution ping me in the new PR and I'll happily test it!

@Sheikh-Abubaker
Copy link
Contributor Author

Sheikh-Abubaker commented Jan 11, 2024

But the pods are not obeying it somehow:

[alberto@fedora]$ k exec -it pod/loki-backend-0 -c loki -- sh
/ $ netstat -tuplen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 :::3101                 :::*                    LISTEN      1/loki
tcp        0      0 :::9096                 :::*                    LISTEN      1/loki
tcp        0      0 :::7946                 :::*                    LISTEN      1/loki

For this reason I'd open a separate issue. If you find a solution ping me in the new PR and I'll happily test it!

@bebosudo I'm onto completing the above memberlist port task

@bebosudo
Copy link
Contributor

I'd discourage putting the memberlist port task change in this PR: these are different changes and it'd be better fixing them in different PRs.
1 PR, 1 simple fix.

@Sheikh-Abubaker
Copy link
Contributor Author

I'd discourage putting the memberlist port task change in this PR: these are different changes and it'd be better fixing them in different PRs. 1 PR, 1 simple fix.

@bebosudo okk, is there anything I'm supposed to do for this PR ?

@bebosudo
Copy link
Contributor

@bebosudo okk, is there anything I'm supposed to do for this PR ?

Nope, it's ready for review by a maintainer :-)

@Sheikh-Abubaker
Copy link
Contributor Author

Sheikh-Abubaker commented Jan 11, 2024

Nope, it's ready for review by a maintainer :-)

It was great working with you, looking forward to connecting. resolving issues and opening more PR's together :-)

@Sheikh-Abubaker Sheikh-Abubaker changed the title area/helm: Modified helm template to use http_listen_port and grpc_listen_port instead of hardcoded value feat:area/helm: Modified helm template to use http_listen_port and grpc_listen_port instead of hardcoded value Feb 22, 2024
Signed-off-by: Sheikh-Abubaker <[email protected]>
@Sheikh-Abubaker Sheikh-Abubaker changed the title feat:area/helm: Modified helm template to use http_listen_port and grpc_listen_port instead of hardcoded value feat: area/helm: Modified helm template to use http_listen_port and grpc_listen_port instead of hardcoded value Feb 22, 2024
@MichelHollands MichelHollands merged commit 347fd4d into grafana:main Mar 15, 2024
13 checks passed
@MaxThom
Copy link

MaxThom commented Mar 17, 2024

Hey guys! I think this PR introduced an issue on the templates/monitoring/_helpers-monitoring.tpl.
So this PR changed from hardcoded to the templated values, but in the printf function, its using %s instead of %d which causes this error in the agent.

grafana-agent 2024/03/17 22:40:27 error loading config file /var/lib/grafana-agent/config/agent.yml: parse "http://hummus-loki.max-dev.svc.cluster.local:%!s(float64=3100)/loki/api/v1/push": invalid port ":%!s(float64=3100)" after host 

If I overwrite the http_listen_port to "3100" (with quotes), then it works, but then the loki core fails with same error: want int instead of string.

I manage to get it to work by using %v instead of %s. If using:

  • %d: same error
  • %f: works, but then print 3100.0000 which then fails
  • %v: work beautifully

Ive been trying the single binary installation, here's my values:

  loki:
    commonConfig:
      replication_factor: 1
    storage:
      type: "filesystem"
  singleBinary:
    replicas: 1

@MichelHollands
Copy link
Contributor

Hey guys! I think this PR introduced an issue on the templates/monitoring/_helpers-monitoring.tpl. So this PR changed from hardcoded to the templated values, but in the printf function, its using %s instead of %d which causes this error in the agent.

@MaxThom Apologies, that did indeed cause a problem. The fix is here: #12242

rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
…rpc_listen_port instead of hardcoded value (grafana#11646)

Signed-off-by: Sheikh-Abubaker <[email protected]>
Co-authored-by: Alberto Chiusole <[email protected]>
Co-authored-by: Michel Hollands <[email protected]>
@Sheikh-Abubaker Sheikh-Abubaker changed the title feat: area/helm: Modified helm template to use http_listen_port and grpc_listen_port instead of hardcoded value feat: area/helm: Modify helm template to use http_listen_port and grpc_listen_port instead of hardcoded value May 31, 2024
mraboosk pushed a commit to mraboosk/loki that referenced this pull request Oct 7, 2024
…rpc_listen_port instead of hardcoded value (grafana#11646)

Signed-off-by: Sheikh-Abubaker <[email protected]>
Co-authored-by: Alberto Chiusole <[email protected]>
Co-authored-by: Michel Hollands <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Actually plug http_listen_port and grpc_listen_port into helm code
4 participants