Skip to content

Commit be6fc00

Browse files
committed
feat: Add timezone to kube_cronjob_info
1 parent 9e85514 commit be6fc00

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

docs/metrics/workload/cronjob-metrics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| Metric name | Metric type | Description | Labels/tags | Status |
44
| ---------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
55
| kube_cronjob_annotations | Gauge | Kubernetes annotations converted to Prometheus labels controlled via [--metric-annotations-allowlist](../../developer/cli-arguments.md) | `cronjob`=&lt;cronjob-name&gt; <br> `namespace`=&lt;cronjob-namespace&gt; <br> `annotation_CRONJOB_ANNOTATION`=&lt;CRONJOB_ANNOTATION&gt; | EXPERIMENTAL |
6-
| kube_cronjob_info | Gauge | | `cronjob`=&lt;cronjob-name&gt; <br> `namespace`=&lt;cronjob-namespace&gt; <br> `schedule`=&lt;schedule&gt; <br> `concurrency_policy`=&lt;concurrency-policy&gt; | STABLE |
6+
| kube_cronjob_info | Gauge | | `cronjob`=&lt;cronjob-name&gt; <br> `namespace`=&lt;cronjob-namespace&gt; <br> `schedule`=&lt;schedule&gt; <br> `concurrency_policy`=&lt;concurrency-policy&gt; <br> `timezone`=&lt;timezone&gt; | STABLE |
77
| kube_cronjob_labels | Gauge | Kubernetes labels converted to Prometheus labels controlled via [--metric-labels-allowlist](../../developer/cli-arguments.md) | `cronjob`=&lt;cronjob-name&gt; <br> `namespace`=&lt;cronjob-namespace&gt; <br> `label_CRONJOB_LABEL`=&lt;CRONJOB_LABEL&gt; | STABLE |
88
| kube_cronjob_created | Gauge | | `cronjob`=&lt;cronjob-name&gt; <br> `namespace`=&lt;cronjob-namespace&gt; | STABLE |
99
| kube_cronjob_next_schedule_time | Gauge | | `cronjob`=&lt;cronjob-name&gt; <br> `namespace`=&lt;cronjob-namespace&gt; | STABLE |

internal/store/cronjob.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ func cronJobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
9696
basemetrics.STABLE,
9797
"",
9898
wrapCronJobFunc(func(j *batchv1.CronJob) *metric.Family {
99+
timeZone := "local"
100+
if j.Spec.TimeZone != nil {
101+
timeZone = *j.Spec.TimeZone
102+
}
99103
return &metric.Family{
100104
Metrics: []*metric.Metric{
101105
{
102-
LabelKeys: []string{"schedule", "concurrency_policy"},
103-
LabelValues: []string{j.Spec.Schedule, string(j.Spec.ConcurrencyPolicy)},
106+
LabelKeys: []string{"schedule", "concurrency_policy", "timezone"},
107+
LabelValues: []string{j.Spec.Schedule, string(j.Spec.ConcurrencyPolicy), timeZone},
104108
Value: 1,
105109
},
106110
},

internal/store/cronjob_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040
ActiveRunningCronJob1LastScheduleTime = time.Unix(1520742896, 0)
4141
SuspendedCronJob1LastScheduleTime = time.Unix(1520742896+5.5*3600, 0) // 5.5 hours later
4242
ActiveCronJob1NoLastScheduledCreationTimestamp = time.Unix(1520742896+6.5*3600, 0)
43+
TimeZone = "Europe/Berlin"
4344
)
4445

4546
func TestCronJobStore(t *testing.T) {
@@ -159,7 +160,7 @@ func TestCronJobStore(t *testing.T) {
159160
# TYPE kube_cronjob_status_active gauge
160161
# TYPE kube_cronjob_metadata_resource_version gauge
161162
# TYPE kube_cronjob_status_last_schedule_time gauge
162-
kube_cronjob_info{concurrency_policy="Forbid",cronjob="ActiveRunningCronJob1",namespace="ns1",schedule="0 */6 * * *"} 1
163+
kube_cronjob_info{concurrency_policy="Forbid",cronjob="ActiveRunningCronJob1",namespace="ns1",schedule="0 */6 * * *",timezone="local"} 1
163164
kube_cronjob_annotations{annotation_app_k8s_io_owner="@foo",cronjob="ActiveRunningCronJob1",namespace="ns1"} 1
164165
kube_cronjob_spec_failed_job_history_limit{cronjob="ActiveRunningCronJob1",namespace="ns1"} 1
165166
kube_cronjob_spec_starting_deadline_seconds{cronjob="ActiveRunningCronJob1",namespace="ns1"} 300
@@ -206,6 +207,7 @@ func TestCronJobStore(t *testing.T) {
206207
ConcurrencyPolicy: "Forbid",
207208
Suspend: &SuspendTrue,
208209
Schedule: "0 */3 * * *",
210+
TimeZone: &TimeZone,
209211
SuccessfulJobsHistoryLimit: &SuccessfulJobHistoryLimit3,
210212
FailedJobsHistoryLimit: &FailedJobHistoryLimit1,
211213
},
@@ -233,7 +235,7 @@ func TestCronJobStore(t *testing.T) {
233235
# TYPE kube_cronjob_metadata_resource_version gauge
234236
# TYPE kube_cronjob_status_last_schedule_time gauge
235237
# TYPE kube_cronjob_status_last_successful_time gauge
236-
kube_cronjob_info{concurrency_policy="Forbid",cronjob="SuspendedCronJob1",namespace="ns1",schedule="0 */3 * * *"} 1
238+
kube_cronjob_info{concurrency_policy="Forbid",cronjob="SuspendedCronJob1",namespace="ns1",schedule="0 */3 * * *",timezone="Europe/Berlin"} 1
237239
kube_cronjob_spec_failed_job_history_limit{cronjob="SuspendedCronJob1",namespace="ns1"} 1
238240
kube_cronjob_spec_starting_deadline_seconds{cronjob="SuspendedCronJob1",namespace="ns1"} 300
239241
kube_cronjob_spec_successful_job_history_limit{cronjob="SuspendedCronJob1",namespace="ns1"} 3
@@ -292,7 +294,7 @@ func TestCronJobStore(t *testing.T) {
292294
# TYPE kube_cronjob_metadata_resource_version gauge
293295
# TYPE kube_cronjob_status_last_schedule_time gauge
294296
# TYPE kube_cronjob_status_last_successful_time gauge
295-
kube_cronjob_info{concurrency_policy="Forbid",cronjob="SuspendedCronJob1",namespace="ns1",schedule="0 */3 * * *"} 1
297+
kube_cronjob_info{concurrency_policy="Forbid",cronjob="SuspendedCronJob1",namespace="ns1",schedule="0 */3 * * *",timezone="local"} 1
296298
kube_cronjob_spec_failed_job_history_limit{cronjob="SuspendedCronJob1",namespace="ns1"} 1
297299
kube_cronjob_spec_starting_deadline_seconds{cronjob="SuspendedCronJob1",namespace="ns1"} 300
298300
kube_cronjob_spec_successful_job_history_limit{cronjob="SuspendedCronJob1",namespace="ns1"} 3
@@ -359,7 +361,7 @@ func TestCronJobStore(t *testing.T) {
359361
kube_cronjob_spec_failed_job_history_limit{cronjob="ActiveCronJob1NoLastScheduled",namespace="ns1"} 1
360362
kube_cronjob_spec_successful_job_history_limit{cronjob="ActiveCronJob1NoLastScheduled",namespace="ns1"} 3
361363
kube_cronjob_spec_suspend{cronjob="ActiveCronJob1NoLastScheduled",namespace="ns1"} 0
362-
kube_cronjob_info{concurrency_policy="Forbid",cronjob="ActiveCronJob1NoLastScheduled",namespace="ns1",schedule="25 * * * *"} 1
364+
kube_cronjob_info{concurrency_policy="Forbid",cronjob="ActiveCronJob1NoLastScheduled",namespace="ns1",schedule="25 * * * *",timezone="local"} 1
363365
kube_cronjob_created{cronjob="ActiveCronJob1NoLastScheduled",namespace="ns1"} 1.520766296e+09
364366
` +
365367
fmt.Sprintf("kube_cronjob_next_schedule_time{cronjob=\"ActiveCronJob1NoLastScheduled\",namespace=\"ns1\"} %ve+09\n",

0 commit comments

Comments
 (0)