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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
30 changes: 30 additions & 0 deletions .chloggen/kubeletstats_add_csi_volume_attrs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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 `container.csi.plugin.name` and `container.csi.volume.id` resource attributes to PVC metrics.
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 @@ -535,6 +535,8 @@ The time since the pod started
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| aws.volume.id | The id of the AWS Volume | Any Str | true |
| container.csi.plugin.name | Container Storage Interface plugin name | Any Str | true |
| container.csi.volume.id | Container Storage Interface volume ID | Any Str | true |
| container.id | Container id used to identify container | Any Str | true |
| 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 |
Expand Down
23 changes: 23 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,19 @@ func glusterfsDims(rb *metadata.ResourceBuilder, vs v1.GlusterfsVolumeSource) {
rb.SetGlusterfsEndpointsName(vs.EndpointsName)
rb.SetGlusterfsPath(vs.Path)
}

func csiPersistentVolumeDims(rb *metadata.ResourceBuilder, vs v1.CSIPersistentVolumeSource) {
// CSI specific labels.
rb.SetContainerCsiVolumeID(vs.VolumeHandle)
rb.SetContainerCsiPluginName(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": labelValuePersistentVolumeClaim,
"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",
"container.csi.plugin.name": csiDriverGCP,
"container.csi.volume.id": "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 @@ -124,6 +124,10 @@ all_set:
resource_attributes:
aws.volume.id:
enabled: true
container.csi.plugin.name:
enabled: true
container.csi.volume.id:
enabled: true
container.id:
enabled: true
fs.type:
Expand Down Expand Up @@ -277,6 +281,10 @@ none_set:
resource_attributes:
aws.volume.id:
enabled: false
container.csi.plugin.name:
enabled: false
container.csi.volume.id:
enabled: false
container.id:
enabled: false
fs.type:
Expand Down Expand Up @@ -311,6 +319,14 @@ filter_set_include:
enabled: true
metrics_include:
- regexp: ".*"
container.csi.plugin.name:
enabled: true
metrics_include:
- regexp: ".*"
container.csi.volume.id:
enabled: true
metrics_include:
- regexp: ".*"
container.id:
enabled: true
metrics_include:
Expand Down Expand Up @@ -373,6 +389,14 @@ filter_set_exclude:
enabled: true
metrics_exclude:
- strict: "aws.volume.id-val"
container.csi.plugin.name:
enabled: true
metrics_exclude:
- strict: "container.csi.plugin.name-val"
container.csi.volume.id:
enabled: true
metrics_exclude:
- strict: "container.csi.volume.id-val"
container.id:
enabled: true
metrics_exclude:
Expand Down
10 changes: 9 additions & 1 deletion receiver/kubeletstatsreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ resource_attributes:
description: "Glusterfs volume path"
enabled: true
type: string
container.csi.volume.id:
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 bit concerned from the semantic conventions perspective since those are not yet defined as resource attributes there. See open-telemetry/semantic-conventions#1337 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 This needs to go thru semconv first. I'm really not sure if container.csi.volume.id: is a good name.

Copy link
Member

Choose a reason for hiding this comment

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

Just to avoid possible confusion here. It has been added in SemConv with open-telemetry/semantic-conventions#1337 but is only part of the registry and not defined as Resource or metric attribute. So I'm not sure if we can already use it.

Copy link
Author

Choose a reason for hiding this comment

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

I opened open-telemetry/semantic-conventions#1499 to clear this up. Is there anything else you can see I'm missing?

description: "Container Storage Interface volume ID"
enabled: true
type: string
container.csi.plugin.name:
description: "Container Storage Interface plugin name"
enabled: true
type: string

attributes:
interface:
Expand Down Expand Up @@ -534,4 +542,4 @@ tests:
key_file: "testdata/testkey.key"
cert_file: "testdata/testcert.crt"
goleak:
skip: true
skip: true
Loading