Skip to content

Commit

Permalink
Update volumeattachment
Browse files Browse the repository at this point in the history
  • Loading branch information
CatherineF-dev committed Jan 2, 2024
1 parent 53dab94 commit 6873732
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 45 deletions.
2 changes: 1 addition & 1 deletion internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func (b *Builder) buildValidatingWebhookConfigurationStores() []cache.Store {
}

func (b *Builder) buildVolumeAttachmentStores() []cache.Store {
return b.buildStoresFunc(volumeAttachmentMetricFamilies, &storagev1.VolumeAttachment{}, createVolumeAttachmentListWatch, b.useAPIServerCache)
return b.buildStoresFunc(volumeAttachmentMetricFamilies(), &storagev1.VolumeAttachment{}, createVolumeAttachmentListWatch, b.useAPIServerCache)
}

func (b *Builder) buildLeasesStores() []cache.Store {
Expand Down
91 changes: 49 additions & 42 deletions internal/store/volumeattachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ var (
descVolumeAttachmentLabelsName = "kube_volumeattachment_labels"
descVolumeAttachmentLabelsHelp = "Kubernetes labels converted to Prometheus labels."
descVolumeAttachmentLabelsDefaultLabels = []string{"volumeattachment"}
)

volumeAttachmentMetricFamilies = []generator.FamilyGenerator{
func volumeAttachmentMetricFamilies() []generator.FamilyGenerator {
return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability(
descVolumeAttachmentLabelsName,
descVolumeAttachmentLabelsHelp,
Expand All @@ -45,15 +47,16 @@ var (
"",
wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
labelKeys, labelValues := kubeMapToPrometheusLabels("label", va.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: labelValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, labelKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -63,15 +66,16 @@ var (
basemetrics.ALPHA,
"",
wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: []string{"attacher", "node"},
LabelValues: []string{va.Spec.Attacher, va.Spec.NodeName},
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: []string{va.Spec.Attacher, va.Spec.NodeName},
Value: 1,
},
}
metric.SetLabelKeys(ms, []string{"attacher", "node"})
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -82,12 +86,14 @@ var (
"",
wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
if !va.CreationTimestamp.IsZero() {
m := metric.Metric{
LabelKeys: nil,
LabelValues: nil,
Value: float64(va.CreationTimestamp.Unix()),
ms := []*metric.Metric{
{
Value: float64(va.CreationTimestamp.Unix()),
},
}
return &metric.Family{Metrics: []*metric.Metric{&m}}

metric.SetLabelKeys(ms, []string{})
return &metric.Family{Metrics: ms}
}
return &metric.Family{Metrics: []*metric.Metric{}}
}),
Expand All @@ -100,15 +106,15 @@ var (
"",
wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
if va.Spec.Source.PersistentVolumeName != nil {
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: []string{"volumename"},
LabelValues: []string{*va.Spec.Source.PersistentVolumeName},
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: []string{*va.Spec.Source.PersistentVolumeName},
Value: 1,
},
}
metric.SetLabelKeys(ms, []string{"volumename"})

return &metric.Family{Metrics: ms}
}
return &metric.Family{}
}),
Expand All @@ -120,15 +126,15 @@ var (
basemetrics.ALPHA,
"",
wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: nil,
LabelValues: nil,
Value: boolFloat64(va.Status.Attached),
},
ms := []*metric.Metric{
{
Value: boolFloat64(va.Status.Attached),
},
}
metric.SetLabelKeys(ms, []string{})
return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
Expand All @@ -139,19 +145,20 @@ var (
"",
wrapVolumeAttachmentFunc(func(va *storagev1.VolumeAttachment) *metric.Family {
labelKeys, labelValues := mapToPrometheusLabels(va.Status.AttachmentMetadata, "metadata")
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: labelValues,
Value: 1,
},
ms := []*metric.Metric{
{
LabelValues: labelValues,
Value: 1,
},
}
metric.SetLabelKeys(ms, labelKeys)
return &metric.Family{
Metrics: ms,
}
}),
),
}
)
}

func wrapVolumeAttachmentFunc(f func(*storagev1.VolumeAttachment) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
Expand Down
4 changes: 2 additions & 2 deletions internal/store/volumeattachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestVolumeAttachmentStore(t *testing.T) {
}
)
for i, c := range cases {
c.Func = generator.ComposeMetricGenFuncs(volumeAttachmentMetricFamilies)
c.Headers = generator.ExtractMetricFamilyHeaders(volumeAttachmentMetricFamilies)
c.Func = generator.ComposeMetricGenFuncs(volumeAttachmentMetricFamilies())
c.Headers = generator.ExtractMetricFamilyHeaders(volumeAttachmentMetricFamilies())
if err := c.run(); err != nil {
t.Errorf("unexpected collecting result in %vth run:\n%s", i, err)
}
Expand Down

0 comments on commit 6873732

Please sign in to comment.