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

Add proxy support for loki log upload #427

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down
1 change: 1 addition & 0 deletions internal/helper/loadbalancermachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ positions:

clients:
- url: '` + logForward.LokiURL + `'
proxy_url: '` + logForward.ProxyURL + `'

scrape_configs:
- job_name: messages
Expand Down
36 changes: 36 additions & 0 deletions internal/helper/loadbalancermachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ positions:

clients:
- url: 'localhost'
proxy_url: ''

scrape_configs:
- job_name: messages
Expand All @@ -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))
})
Expand Down
3 changes: 3 additions & 0 deletions internal/helper/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down