Skip to content

Commit

Permalink
update lease store to export namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lantingchiang committed Sep 28, 2022
1 parent 8f883f0 commit 5464a9d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/lease-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
| Metric name| Metric type | Labels/tags | Status |
| ---------- | ----------- |-------------------------------------------------------------------------------------------------------------------------------------------| ----------- |
| kube_lease_owner | Gauge | `lease`=&lt;lease-name&gt; <br> `owner_kind`=&lt;onwer kind&gt; <br> `owner_name`=&lt;owner name&gt; <br> `namespace` = &lt;namespace&gt; | EXPERIMENTAL |
| kube_lease_renew_time | Gauge | `lease`=&lt;lease-name&gt; <br> `namespace` = &lt;namespace&gt; | EXPERIMENTAL |
| kube_lease_renew_time | Gauge | `lease`=&lt;lease-name&gt; | EXPERIMENTAL |
6 changes: 3 additions & 3 deletions internal/store/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ var (
metric.Gauge,
"",
wrapLeaseFunc(func(l *coordinationv1.Lease) *metric.Family {
labelKeys := []string{"owner_kind", "owner_name"}
labelKeys := []string{"owner_kind", "owner_name", "namespace"}

owners := l.GetOwnerReferences()
if len(owners) == 0 {
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: labelKeys,
LabelValues: []string{"<none>", "<none>"},
LabelValues: []string{"<none>", "<none>", l.Namespace},
Value: 1,
},
},
Expand All @@ -59,7 +59,7 @@ var (
for i, owner := range owners {
ms[i] = &metric.Metric{
LabelKeys: labelKeys,
LabelValues: []string{owner.Kind, owner.Name},
LabelValues: []string{owner.Kind, owner.Name, l.Namespace},
Value: 1,
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/store/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestLeaseStore(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Generation: 2,
Name: "kube-master",
Namespace: "default",
CreationTimestamp: metav1.Time{Time: time.Unix(1500000000, 0)},
OwnerReferences: []metav1.OwnerReference{
{
Expand All @@ -54,7 +55,7 @@ func TestLeaseStore(t *testing.T) {
},
},
Want: metadata + `
kube_lease_owner{lease="kube-master",owner_kind="Node",owner_name="kube-master"} 1
kube_lease_owner{lease="kube-master",owner_kind="Node",owner_name="kube-master",namespace="default"} 1
kube_lease_renew_time{lease="kube-master"} 1.5e+09
`,
MetricNames: []string{
Expand Down

0 comments on commit 5464a9d

Please sign in to comment.