grafana / alloy

OpenTelemetry Collector distribution with programmable pipelines
https://grafana.com/oss/alloy
Apache License 2.0
1.31k stars 180 forks source link

agent.extraPorts not working with service.type=NodePort #1089

Open mcfly722 opened 3 months ago

mcfly722 commented 3 months ago

What's wrong?

Hello, I configured Alloy with loki.source.syslog plugin to forward all logs to loki.write.

loki.source.syslog listens incoming traffic in container on its own port (in config it is = 31010). I need to configure each rsyslog on k8s nodes to forward logs to loki.source.syslog. I'm trying to publish it through agent.extraPorts parameter on NodePort service, but your service does not support nodePort option for extraPorts, so every time kubernetes replaces it with random one.

It is impossible to use it, because it is every time random.

Fix could be applied to: https://github.com/grafana/alloy/blob/main/operations/helm/charts/alloy/templates/service.yaml you should add

nodePort: {{ $portMap.nodePort }}

in extraPorts range, to make it work.

Steps to reproduce

Create values config

cat > grafana-alloy-values.yaml << EOF
service:
  type: NodePort
agent:
  extraPorts:
    - name: syslog
      port: 31010
      targetPort: 31010
      nodePort: 31010
      protocol: "TCP"
  configMap:
    content: |
      loki.source.syslog "syslog" {
        listener {
          address = "0.0.0.0:31010"
        }
        forward_to = [loki.write.syslog.receiver]
      }
      loki.write "syslog" {
        endpoint {
          url = "http://loki.observability.svc.cluster.local:3100/loki/api/v1/push"
        }
      }
EOF

deploy alloy:

microk8s.helm upgrade --install \
    --namespace grafana-alloy \
    --create-namespace \
    -f grafana-alloy-values.yaml \
    grafana-alloy grafana/alloy

view created service:

microk8s.kubectl describe service grafana-alloy -n grafana-alloy

Name:                     grafana-alloy
Namespace:                grafana-alloy
Labels:                   app.kubernetes.io/component=networking
                          app.kubernetes.io/instance=grafana-alloy
                          app.kubernetes.io/managed-by=Helm
                          app.kubernetes.io/name=alloy
                          app.kubernetes.io/part-of=alloy
                          app.kubernetes.io/version=v1.1.1
                          helm.sh/chart=alloy-0.3.2
Annotations:              meta.helm.sh/release-name: grafana-alloy
                          meta.helm.sh/release-namespace: grafana-alloy
Selector:                 app.kubernetes.io/instance=grafana-alloy,app.kubernetes.io/name=alloy
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.152.183.196
IPs:                      10.152.183.196
Port:                     http-metrics  12345/TCP
TargetPort:               12345/TCP
NodePort:                 http-metrics  31128/TCP
Endpoints:                10.1.127.92:12345,10.1.154.88:12345,10.1.251.97:12345
Port:                     syslog  31010/TCP
TargetPort:               31010/TCP
NodePort:                 syslog  30189/TCP <------------------------------------- !!! EVERY TIME RANDOM !!!
Endpoints:                10.1.127.92:31010,10.1.154.88:31010,10.1.251.97:31010
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

System information

No response

Software version

REVISION: 1

Configuration

No response

Logs

No response

github-actions[bot] commented 2 months ago

This issue has not had any activity in the past 30 days, so the needs-attention label has been added to it. If the opened issue is a bug, check to see if a newer release fixed your issue. If it is no longer relevant, please feel free to close this issue. The needs-attention label signals to maintainers that something has fallen through the cracks. No action is needed by you; your issue will be kept open and you do not have to respond to this comment. The label will be removed the next time this job runs if there is new activity. Thank you for your contributions!