diff --git a/README.md b/README.md index 77465e86..b37eff5c 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,8 @@ metadata: yawol.stackit.cloud/logForward: "true" # Defines loki URL for the log forwarding. yawol.stackit.cloud/logForwardLokiURL: "http://example.com:3100/loki/api/v1/push" + # Defines proxy URL for the log forwarding. + yawol.stackit.cloud/logForwardProxyURL: "http://proxy.example.com:8000" # Defines labels that are added when forwarding logs # The prefix "logging.yawol.stackit.cloud/" will be trimmed # and only "foo": "bar" will be added as a label diff --git a/api/v1beta1/loadbalancer_types.go b/api/v1beta1/loadbalancer_types.go index 0556340f..d76a65d7 100644 --- a/api/v1beta1/loadbalancer_types.go +++ b/api/v1beta1/loadbalancer_types.go @@ -55,6 +55,8 @@ const ( ServiceLogForward = "yawol.stackit.cloud/logForward" // ServiceLogForwardLokiURL set loki url into LoadBalancer ServiceLogForwardLokiURL = "yawol.stackit.cloud/logForwardLokiURL" + // ServiceLogForwardProxyURL set proxy url to connect to loki + ServiceLogForwardProxyURL = "yawol.stackit.cloud/logForwardProxyURL" // ServiceServerGroupPolicy set openstack server group policy for a LoadBalancer ServiceServerGroupPolicy = "yawol.stackit.cloud/serverGroupPolicy" // ServiceAdditionalNetworks adds additional openstack networks for the loadbalancer (comma separated list) @@ -179,6 +181,9 @@ type LoadBalancerLogForward struct { // LokiUrl defines the loki push url (Example: http://example.com:3100/loki/api/v1/push). // +optional LokiURL string `json:"lokiUrl"` + // ProxyUrl defines the http proxy url to use for connection to loki + // +optional + ProxyURL string `json:"proxyUrl"` // Labels define extra labels for loki. // +optional Labels map[string]string `json:"labels"` diff --git a/charts/yawol-controller/crds/yawol.stackit.cloud_loadbalancers.yaml b/charts/yawol-controller/crds/yawol.stackit.cloud_loadbalancers.yaml index bb94948b..74d3b924 100644 --- a/charts/yawol-controller/crds/yawol.stackit.cloud_loadbalancers.yaml +++ b/charts/yawol-controller/crds/yawol.stackit.cloud_loadbalancers.yaml @@ -251,6 +251,10 @@ spec: description: 'LokiUrl defines the loki push url (Example: http://example.com:3100/loki/api/v1/push).' type: string + proxyUrl: + description: ProxyUrl defines the http proxy url to use for + connection to loki + type: string type: object serverGroupPolicy: description: |- diff --git a/internal/helper/loadbalancermachine.go b/internal/helper/loadbalancermachine.go index 35b9bbde..ebb71c98 100644 --- a/internal/helper/loadbalancermachine.go +++ b/internal/helper/loadbalancermachine.go @@ -495,6 +495,7 @@ positions: clients: - url: '` + logForward.LokiURL + `' + proxy_url: '` + logForward.ProxyURL + `' scrape_configs: - job_name: messages diff --git a/internal/helper/loadbalancermachine_test.go b/internal/helper/loadbalancermachine_test.go index 56760bd5..7b4c4904 100644 --- a/internal/helper/loadbalancermachine_test.go +++ b/internal/helper/loadbalancermachine_test.go @@ -34,6 +34,7 @@ positions: clients: - url: 'localhost' + proxy_url: '' scrape_configs: - job_name: messages @@ -48,6 +49,41 @@ scrape_configs: job: yawol-logs lb: some-lb lbm: some-lbm + ` + Expect(config).To(Equal(expected)) + }) + }) + When("proxy url is set", func() { + It("should render it in the promtail config", func() { + logForward := yawolv1beta1.LoadBalancerLogForward{ + LokiURL: "localhost", + ProxyURL: "proxy-url", + } + + config, err := generatePromtailConfig("some-lb", "some-lbm", logForward) + Expect(err).ToNot(HaveOccurred()) + + expected := `server: + disable: true + +positions: + filename: /tmp/positions.yaml + +clients: + - url: 'localhost' + proxy_url: 'proxy-url' + +scrape_configs: + - job_name: messages + static_configs: + - targets: + - localhost + labels: + __path__: /var/log/messages + application: messages + job: yawol-logs + lb: some-lb + lbm: some-lbm ` Expect(config).To(Equal(expected)) }) diff --git a/internal/helper/service.go b/internal/helper/service.go index 03e09fbd..6332aef5 100644 --- a/internal/helper/service.go +++ b/internal/helper/service.go @@ -75,6 +75,9 @@ func GetOptions(svc *coreV1.Service, recorder record.EventRecorder) yawolv1beta1 if svc.Annotations[yawolv1beta1.ServiceLogForwardLokiURL] != "" { options.LogForward.LokiURL = svc.Annotations[yawolv1beta1.ServiceLogForwardLokiURL] } + if svc.Annotations[yawolv1beta1.ServiceLogForwardProxyURL] != "" { + options.LogForward.ProxyURL = svc.Annotations[yawolv1beta1.ServiceLogForwardProxyURL] + } labels := map[string]string{} for annotation := range svc.Annotations {