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

feat: Add timezone to kube_cronjob_info / Make kube_cronjob_next_schedule_time timezone-aware #2376

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mrueg
Copy link
Member

@mrueg mrueg commented Apr 22, 2024

What this PR does / why we need it:
Cronjob is not timezone aware.
How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
Adds one label to the kube_cronjob_info metric.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2206

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 22, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mrueg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 22, 2024
@mrueg mrueg changed the title feat: Add timezone to kube_cronjob_info WIP: feat: Add timezone to kube_cronjob_info Apr 22, 2024
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 22, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 22, 2024
@mrueg mrueg changed the title WIP: feat: Add timezone to kube_cronjob_info feat: Add timezone to kube_cronjob_info Apr 22, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 22, 2024
@mrueg mrueg changed the title feat: Add timezone to kube_cronjob_info feat: Add timezone to kube_cronjob_info / Make kube_cronjob_next_schedule_time timezone-aware Apr 22, 2024
@mrueg mrueg force-pushed the cronjob-add-timezone branch 2 times, most recently from 6b1fa06 to 35252bd Compare April 22, 2024 18:23
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: []string{"schedule", "concurrency_policy"},
LabelValues: []string{j.Spec.Schedule, string(j.Spec.ConcurrencyPolicy)},
LabelKeys: []string{"schedule", "concurrency_policy", "timezone"},
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't it be better in its own metric rather than in the info metric?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a 1:1 relationship, why would you prefer a dedicated metric for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dgrisonnet any feedback here?

Copy link
Member

Choose a reason for hiding this comment

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

_info is not a very intuitive suffix which is why I don't really like these metrics where we just end up dumping a bunch of labels that aren't really related between one another.

I don't know what was the historical reasoning for putting labels into these metrics, but I can also see some dedicated metrics for values part of objects spec:

func createPodRestartPolicyFamilyGenerator() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_pod_restart_policy",
"Describes the restart policy in use by this pod.",
metric.Gauge,
basemetrics.STABLE,
"",
wrapPodFunc(func(p *v1.Pod) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
LabelKeys: []string{"type"},
LabelValues: []string{string(p.Spec.RestartPolicy)},
Value: float64(1),
},
},
}
}),
)
}

To me, info should be limited to the default labels. Any other information that we want to expose should be in its own dedicated metric. What is your opinion on that?

Copy link
Member Author

@mrueg mrueg May 15, 2024

Choose a reason for hiding this comment

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

I agree on having a separate metric for anything that does not have a 1:n relationship within the object. For 1:1 relationships, additional time series make it difficult to correlate between multiple labels vs. simply extracting the ones you need:
max(resource_info) by (label1, label2, label3).
Trying to do the same with multiple metrics can get very annoying and more error-prone.

To me, the _info metric should describe all single-value keys of the object that are static over its lifetime and non-numeric.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to define it here:
the _info metric should describe all single-value keys of the object that are static over its lifetime and non-numeric

Copy link
Member

Choose a reason for hiding this comment

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

I meant a documentation/standard of sorts in the repository that enforces this. Not sure if there is one.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add that in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm currently working on a tool that will generate ideal metric names but it will take some time.

Copy link
Member

@rexagod rexagod Jul 16, 2024

Choose a reason for hiding this comment

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

I believe the tool's definition of an incorrect or correct metric representation for a nested object needs to weigh in the point Damien raised above.

Basically, are we in consensus on what is the standard approach for representing a nested value (since more granularity leads to more joins, but more abstractions lead to more cardinal label-sets (which is comparatively more harmful))?

@logicalhan
Copy link
Member

/triage accepted
/assign @dgrisonnet

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 2, 2024
@mrueg mrueg added this to the v2.13.0 milestone Jun 14, 2024
@mrueg
Copy link
Member Author

mrueg commented Jul 15, 2024

@dgrisonnet @rexagod anything left to do to get this change in?

@mrueg mrueg removed this from the v2.13.0 milestone Jul 17, 2024
@der-eismann
Copy link
Contributor

@dgrisonnet @rexagod Sorry for the ping, but this feature is pretty important to us since we can't set the timezone on AWS' Bottlerocket OS. Is there any way to accelerate the review process?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kube_cronjob_next_schedule_time in the past when cronjob timezone specified
6 participants