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

[receiver/kubeletstatsreciever] add volume attrs for CSI-backed PVCs #32055

Closed
Closed
31 changes: 31 additions & 0 deletions .chloggen/kubeletstats_add_csi_volume_attrs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: kubeletstatsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add CSI driver and volume handle attributes for PVCs

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32055]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Add `csi.driver` and `csi.volume.handle` resource attributes to PVC metrics.
Label volume metrics with type `csiPersistentVolume` if backed by CSI.
If a GCP PD is detected (uses `pd.csi.storage.gke.io`), set `gce.pd.name` to the parsed disk name.
This will match with disk names in GCP, allowing for correlation of GCE-native metrics.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 2 additions & 0 deletions receiver/kubeletstatsreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ The time since the pod started
| ---- | ----------- | ------ | ------- |
| aws.volume.id | The id of the AWS Volume | Any Str | true |
| container.id | Container id used to identify container | Any Str | true |
| csi.driver | CSI driver | Any Str | true |
| csi.volume.handle | CSI volume handle | Any Str | true |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

csi is kubernetes specific concern only, right? In that case, it's better to prepend it with k8s. namespace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's not the case...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not 100% sure about the naming here. csi namespace may be too ambiguous. I don't have any suggestions at this point. I'm open to merging the PR as is. Can you please submit a PR for open-telemetry/semantic-conventions#1119? Maybe we will get some more feedback there

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done open-telemetry/semantic-conventions#1337

The alteration of k8s.volume.type done here (adding a special csiPersistentVolume value) maybe looks less appealing if we want to keep the 1:1 mapping here. It's still technically a persistentVolumeClaim, so perhaps we should leave it at that, and users can query for defined(csi.driver) or something to enumerate CSI-backed PVCs.

| fs.type | The filesystem type of the Volume | Any Str | true |
| gce.pd.name | The name of the persistent disk in GCE | Any Str | true |
| glusterfs.endpoints.name | The endpoint name that details Glusterfs topology | Any Str | true |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ const (
labelValueLocalVolume = "local"
labelValueAWSEBSVolume = "awsElasticBlockStore"
labelValueGCEPDVolume = "gcePersistentDisk"
labelValueCSIPersistentVolume = "csiPersistentVolume"
labelValueGlusterFSVolume = "glusterfs"
)
25 changes: 25 additions & 0 deletions receiver/kubeletstatsreceiver/internal/kubelet/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package kubelet // import "github.com/open-telemetry/opentelemetry-collector-con

import (
"strconv"
"strings"

"go.opentelemetry.io/collector/pdata/pcommon"
v1 "k8s.io/api/core/v1"
Expand All @@ -13,6 +14,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kubeletstatsreceiver/internal/metadata"
)

const (
csiDriverGCP = "pd.csi.storage.gke.io"
)

func addVolumeMetrics(mb *metadata.MetricsBuilder, volumeMetrics metadata.VolumeMetrics, s stats.VolumeStats, currentTime pcommon.Timestamp) {
recordIntDataPoint(mb, volumeMetrics.Available, s.AvailableBytes, currentTime)
recordIntDataPoint(mb, volumeMetrics.Capacity, s.CapacityBytes, currentTime)
Expand Down Expand Up @@ -65,6 +70,8 @@ func SetPersistentVolumeLabels(rb *metadata.ResourceBuilder, pv v1.PersistentVol
Path: pv.Glusterfs.Path,
ReadOnly: pv.Glusterfs.ReadOnly,
})
case pv.CSI != nil:
csiPersistentVolumeDims(rb, *pv.CSI)
}
}

Expand All @@ -90,3 +97,21 @@ func glusterfsDims(rb *metadata.ResourceBuilder, vs v1.GlusterfsVolumeSource) {
rb.SetGlusterfsEndpointsName(vs.EndpointsName)
rb.SetGlusterfsPath(vs.Path)
}

func csiPersistentVolumeDims(rb *metadata.ResourceBuilder, vs v1.CSIPersistentVolumeSource) {
rb.SetK8sVolumeType(labelValueCSIPersistentVolume)

// CSI specific labels.
rb.SetCsiVolumeHandle(vs.VolumeHandle)
rb.SetCsiDriver(vs.Driver)
rb.SetFsType(vs.FSType)

// CSI driver specific labels.
if vs.Driver == csiDriverGCP {
// This is in one of two formats:
// projects/<project>/regions/<region>/disks/<disk>
// projects/<project>/zones/<zone>/disks/<disk>
parts := strings.SplitN(vs.VolumeHandle, "/", 6)
rb.SetGcePdName(parts[len(parts)-1])
}
}
33 changes: 33 additions & 0 deletions receiver/kubeletstatsreceiver/internal/kubelet/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,39 @@ func TestDetailedPVCLabels(t *testing.T) {
"k8s.namespace.name": "pod-namespace",
},
},
{
name: "persistentVolumeClaim - with detailed PVC labels (CSI PV with GCP driver)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also enhance the scraper's tests like at https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/kubeletstatsreceiver/scraper_test.go#L598? The resulted files are really useful for reference since they contain the whole information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, these tests appear to be at least somewhat broken. You can alter anything in the expectedVolumes section of the successful test and it still passes.

volumeName: "volume0",
volumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: "claim-name",
},
},
pod: pod{uid: "uid-1234", name: "pod-name", namespace: "pod-namespace"},
detailedPVCLabelsSetterOverride: func(rb *metadata.ResourceBuilder, _, _, _ string) error {
SetPersistentVolumeLabels(rb, v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
Driver: csiDriverGCP,
VolumeHandle: "projects/project-name/zones/us-central1-a/disks/disk-name",
ReadOnly: false,
FSType: "ext4",
},
})
return nil
},
want: map[string]any{
"k8s.volume.name": "volume0",
"k8s.volume.type": labelValueCSIPersistentVolume,
"k8s.persistentvolumeclaim.name": "claim-name",
"k8s.pod.uid": "uid-1234",
"k8s.pod.name": "pod-name",
"k8s.namespace.name": "pod-namespace",
"gce.pd.name": "disk-name",
"csi.driver": csiDriverGCP,
"csi.volume.handle": "projects/project-name/zones/us-central1-a/disks/disk-name",
"fs.type": "ext4",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ all_set:
enabled: true
container.id:
enabled: true
csi.driver:
enabled: true
csi.volume.handle:
enabled: true
fs.type:
enabled: true
gce.pd.name:
Expand Down Expand Up @@ -263,6 +267,10 @@ none_set:
enabled: false
container.id:
enabled: false
csi.driver:
enabled: false
csi.volume.handle:
enabled: false
fs.type:
enabled: false
gce.pd.name:
Expand Down Expand Up @@ -299,6 +307,14 @@ filter_set_include:
enabled: true
metrics_include:
- regexp: ".*"
csi.driver:
enabled: true
metrics_include:
- regexp: ".*"
csi.volume.handle:
enabled: true
metrics_include:
- regexp: ".*"
fs.type:
enabled: true
metrics_include:
Expand Down Expand Up @@ -361,6 +377,14 @@ filter_set_exclude:
enabled: true
metrics_exclude:
- strict: "container.id-val"
csi.driver:
enabled: true
metrics_exclude:
- strict: "csi.driver-val"
csi.volume.handle:
enabled: true
metrics_exclude:
- strict: "csi.volume.handle-val"
fs.type:
enabled: true
metrics_exclude:
Expand Down
8 changes: 8 additions & 0 deletions receiver/kubeletstatsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ resource_attributes:
description: "Glusterfs volume path"
enabled: true
type: string
csi.volume.handle:
description: "CSI volume handle"
enabled: true
type: string
csi.driver:
description: "CSI driver"
enabled: true
type: string

attributes:
interface:
Expand Down
Loading