Skip to content

Commit dbb4a12

Browse files
committed
feat: add flag for resourceVersion=0
1 parent da95fba commit dbb4a12

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

flags/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ type FlagsProfiling struct {
275275
type FlagsMetadata struct {
276276
ExternalLabels map[string]string `help:"Label(s) to attach to all profiles."`
277277
ContainerRuntimeSocketPath string `help:"The filesystem path to the container runtimes socket. Leave this empty to use the defaults."`
278+
ListFromCache bool `default:"false" help:"listing pods from apiserver cache instead of etcd"`
278279

279280
DisableCaching bool `default:"false" help:"[deprecated] Disable caching of metadata."`
280281
EnableProcessCmdline bool `default:"false" help:"[deprecated] Add /proc/[pid]/cmdline as a label, which may expose sensitive information like secrets in profiling data."`

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ func mainWithExitCode() flags.ExitCode {
337337
f.Debuginfo.UploadQueueSize,
338338
f.Debuginfo.TempDir,
339339
f.Node,
340+
f.Metadata.ListFromCache,
340341
relabelConfigs,
341342
buildInfo.VcsRevision,
342343
reg,

reporter/metadata/containermetadata.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ type containerMetadataProvider struct {
112112
// the kubernetes node name used to retrieve the pod information.
113113
nodeName string
114114

115+
// used to list pods.
116+
listFromCache bool
117+
115118
// containerIDCache stores per process container ID information.
116119
containerIDCache *lru.SyncedLRU[libpf.PID, containerIDEntry]
117120

@@ -162,7 +165,7 @@ type containerIDEntry struct {
162165
}
163166

164167
// NewContainerMetadataProvider creates a new container metadata provider.
165-
func NewContainerMetadataProvider(ctx context.Context, nodeName string) (MetadataProvider, error) {
168+
func NewContainerMetadataProvider(ctx context.Context, nodeName string, listFromCache bool) (MetadataProvider, error) {
166169
containerIDCache, err := lru.NewSynced[libpf.PID, containerIDEntry](
167170
containerIDCacheSize, libpf.PID.Hash32)
168171
if err != nil {
@@ -175,6 +178,7 @@ func NewContainerMetadataProvider(ctx context.Context, nodeName string) (Metadat
175178
dockerClient: getDockerClient(),
176179
containerdClient: getContainerdClient(),
177180
nodeName: nodeName,
181+
listFromCache: listFromCache,
178182
}
179183

180184
p.deferredPID, err = lru.NewSynced[libpf.PID, libpf.Void](deferredLRUSize,
@@ -597,9 +601,13 @@ func (p *containerMetadataProvider) getKubernetesPodMetadata(pidContainerID stri
597601
log.Debugf("Get kubernetes pod metadata for container id %v", pidContainerID)
598602

599603
p.kubernetesClientQueryCount.Add(1)
600-
pods, err := p.kubeClientSet.CoreV1().Pods("").List(context.TODO(), v1.ListOptions{
604+
listOption := v1.ListOptions{
601605
FieldSelector: "spec.nodeName=" + p.nodeName,
602-
})
606+
}
607+
if p.listFromCache {
608+
listOption.ResourceVersion = "0"
609+
}
610+
pods, err := p.kubeClientSet.CoreV1().Pods("").List(context.TODO(), listOption)
603611
if err != nil {
604612
return nil, fmt.Errorf("failed to retrieve kubernetes pods, %v", err)
605613
}

reporter/parca_reporter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ func New(
526526
uploaderQueueSize uint32,
527527
cacheDir string,
528528
nodeName string,
529+
listFromCache bool,
529530
relabelConfigs []*relabel.Config,
530531
agentRevision string,
531532
reg prometheus.Registerer,
@@ -563,7 +564,7 @@ func New(
563564
}
564565
}
565566

566-
cmp, err := metadata.NewContainerMetadataProvider(context.TODO(), nodeName)
567+
cmp, err := metadata.NewContainerMetadataProvider(context.TODO(), nodeName, listFromCache)
567568
if err != nil {
568569
return nil, err
569570
}

0 commit comments

Comments
 (0)