Skip to content

Commit

Permalink
Append, rather than set, '/pods' to the path in discovery.kubelet (#6013
Browse files Browse the repository at this point in the history
)

* Append, rather than set, '/pods' to the path in discovery.kubelet

---------

Signed-off-by: Pete Wall <[email protected]>
Co-authored-by: Paulin Todev <[email protected]>
  • Loading branch information
petewall and ptodev authored Jan 9, 2024
1 parent 631378e commit 341cab7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ v0.39.0-rc.0 (2024-01-05)
- `discovery.lightsail` now supports additional parameters for configuring HTTP client settings. (@ptodev)
- Add `sample_age_limit` to remote_write config to drop samples older than a specified duration. (@marctc)

- Handle paths in the Kubelet URL for `discovery.kubelet`. (@petewall)

### Bugfixes

- Update `pyroscope.ebpf` to fix a logical bug causing to profile to many kthreads instead of regular processes https://github.com/grafana/pyroscope/pull/2778 (@korniltsev)
Expand Down
5 changes: 2 additions & 3 deletions component/discovery/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ func NewKubeletDiscovery(args Arguments) (*Discovery, error) {
Transport: transport,
Timeout: 30 * time.Second,
}
// ensure the path is the kubelet pods endpoint
args.URL.Path = "/pods"
// Append the path to the kubelet pods endpoint
return &Discovery{
client: client,
url: args.URL.String(),
url: args.URL.String() + "/pods",
targetNamespaces: args.Namespaces,
}, nil
}
Expand Down
19 changes: 19 additions & 0 deletions component/discovery/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package kubelet

import (
"net/url"
"testing"

"github.com/prometheus/prometheus/discovery/targetgroup"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/grafana/agent/component/common/config"
"github.com/grafana/river"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -105,3 +107,20 @@ func TestDiscoveryPodWithoutPod(t *testing.T) {
require.NoError(t, err)
require.Len(t, kubeletDiscovery.discoveredPodSources, 2)
}

func TestWithDefaultKubeletHost(t *testing.T) {
kubeletDiscovery, err := NewKubeletDiscovery(DefaultConfig)
require.NoError(t, err)
require.Equal(t, "https://localhost:10250/pods", kubeletDiscovery.url)
}

func TestWithCustomPath(t *testing.T) {
kubeletProxyUrl, _ := url.Parse("https://kubernetes.default.svc.cluster.local:443/api/v1/nodes/cluster-node-1/proxy")
kubeletDiscovery, err := NewKubeletDiscovery(Arguments{
URL: config.URL{
URL: kubeletProxyUrl,
},
})
require.NoError(t, err)
require.Equal(t, "https://kubernetes.default.svc.cluster.local:443/api/v1/nodes/cluster-node-1/proxy/pods", kubeletDiscovery.url)
}
6 changes: 5 additions & 1 deletion docs/sources/flow/reference/components/discovery.kubelet.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The following arguments are supported:

Name | Type | Description | Default | Required
---- | ---- | ----------- | ------- | --------
`url` | `string` | URL of the Kubelet server. | | no
`url` | `string` | URL of the Kubelet server. | "https://localhost:10250" | no
`bearer_token` | `secret` | Bearer token to authenticate with. | | no
`bearer_token_file` | `string` | File containing a bearer token to authenticate with. | | no
`refresh_interval` | `duration` | How often the Kubelet should be polled for scrape targets | `5s` | no
Expand All @@ -49,6 +49,10 @@ One of the following authentication methods must be provided if kubelet authenti
The `namespaces` list limits the namespaces to discover resources in. If
omitted, all namespaces are searched.

`discovery.kubelet` appends a `/pods` path to `url` to request the available pods.
You can have additional paths in the `url`.
For example, if `url` is `https://kubernetes.default.svc.cluster.local:443/api/v1/nodes/cluster-node-1/proxy`, then `discovery.kubelet` sends a request on `https://kubernetes.default.svc.cluster.local:443/api/v1/nodes/cluster-node-1/proxy/pods`

## Blocks

The following blocks are supported inside the definition of
Expand Down

0 comments on commit 341cab7

Please sign in to comment.