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

promtail: fix high CPU usage on large kubernetes clusters. #1118

Merged
merged 3 commits into from
Jul 3, 2020
Merged
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
18 changes: 16 additions & 2 deletions pkg/promtail/targets/filetargetmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery"
sd_config "github.com/prometheus/prometheus/discovery/config"
"github.com/prometheus/prometheus/discovery/kubernetes"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/pkg/relabel"
Expand All @@ -26,8 +27,9 @@ import (
)

const (
pathLabel = "__path__"
hostLabel = "__host__"
pathLabel = "__path__"
hostLabel = "__host__"
kubernetesPodNodeField = "spec.nodeName"
)

var (
Expand Down Expand Up @@ -121,6 +123,18 @@ func NewFileTargetManager(
}
}

// Add an additional api-level node filtering, so we only fetch pod metadata for
// all the pods from the current node. Without this filtering we will have to
// download metadata for all pods running on a cluster, which may be a long operation.
for _, kube := range cfg.ServiceDiscoveryConfig.KubernetesSDConfigs {
if kube.Role == kubernetes.RolePod {
selector := fmt.Sprintf("%s=%s", kubernetesPodNodeField, hostname)
kube.Selectors = []kubernetes.SelectorConfig{
{Role: kubernetes.RolePod, Field: selector},
}
}
}

s := &targetSyncer{
log: logger,
positions: positions,
Expand Down