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

OCPBUGS-17113: Lazy updates for Prometheus #2395

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rexagod
Copy link
Member

@rexagod rexagod commented Jun 26, 2024

Incorporate openshift/library-go#1575 downstream.

  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

@openshift-ci-robot openshift-ci-robot added jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jun 26, 2024
@openshift-ci-robot
Copy link
Contributor

@rexagod: This pull request references Jira Issue OCPBUGS-17113, which is invalid:

  • expected the bug to target either version "4.17." or "openshift-4.17.", but it targets "4.15.z" instead

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Incorporate openshift/library-go#1575 downstream.

  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested review from jan--f and slashpai June 26, 2024 00:41
Copy link
Contributor

openshift-ci bot commented Jun 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rexagod

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 26, 2024
@rexagod
Copy link
Member Author

rexagod commented Jun 26, 2024

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jun 26, 2024
@openshift-ci-robot
Copy link
Contributor

@rexagod: This pull request references Jira Issue OCPBUGS-17113, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.17.0) matches configured target version for branch (4.17.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @juzhao

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested a review from juzhao June 26, 2024 00:42
@rexagod rexagod marked this pull request as draft June 26, 2024 06:51
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 26, 2024
@rexagod rexagod marked this pull request as ready for review June 26, 2024 06:52
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 26, 2024
@rexagod rexagod force-pushed the mon-17113-lib-go-1575 branch 5 times, most recently from 484f320 to d394434 Compare June 26, 2024 13:53
@rexagod
Copy link
Member Author

rexagod commented Jun 26, 2024

/retest-required

@juzhao
Copy link

juzhao commented Jun 28, 2024

/retest-required

1 similar comment
@juzhao
Copy link

juzhao commented Jul 1, 2024

/retest-required

Incorporate openshift/library-go#1575
downstream.

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@rexagod
Copy link
Member Author

rexagod commented Jul 2, 2024

/test e2e-aws-ovn-techpreview

@juzhao
Copy link

juzhao commented Jul 4, 2024

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Jul 4, 2024
Copy link
Contributor

@machine424 machine424 left a comment

Choose a reason for hiding this comment

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

Thanks!
I left some comments.

_, err = c.dclient.
Resource(prometheusGVR).
Namespace(structuredRequiredPrometheus.GetNamespace()).
Create(ctx, unstructuredRequiredPrometheus, metav1.CreateOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can delegate the creation to ApplyUnstructuredResourceImproved as it already does that.

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 see. I tried to preserve the earlier behavior, albeit at the cost of no cache updates during creation, but this makes sense. Done!

return &didUpdate, nil
}

func prometheusDefaultingFunc(unstructuredPrometheus *unstructured.Unstructured) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that after our discussion here openshift/library-go#1575 (comment), we "agreed" to give the "cache approach" a try for now, as it's simpler (less code/less maintenance), and with the cache, IIUC, I don't think we need to care about the defaults (if the wanted config is the one stored in the cache which mean the one deployed, skip the update).
Any reasons behind the change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Referring to the same thread: openshift/library-go#1575 (comment), we do this in addition to the cache approach since that doesn't cache spec fields, in case of a metadata cache miss (same as what Trevor's patch targets in ef5f348#diff-2895f30116602d8fe6b0545c186d4f81247fa4eaab049dab174c6c91c0036e08R639-R667).

c := &Client{}
c.dclient = dynamicFake.NewSimpleDynamicClient(runtime.NewScheme(), initialPrometheus.DeepCopy())
c.eventRecorder = events.NewInMemoryRecorder("create-or-update-prometheus-test")
c.resourceCache = resourceapply.NewResourceCache()
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that the code seems to be using the "comparison approach" (I don't see any cache initialized there), but here we're testing the "cache approach", am I missing sth?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both of these are in use (PTAL my comment https://github.com/openshift/cluster-monitoring-operator/pull/2395/files#r1696698968). Here, we initialize the cache, and down below we use the defaulting approach to reject default spec updates (shouldUpdate is false for this case).

pkg/client/client_test.go Show resolved Hide resolved
}
unstructuredRequiredPrometheusMetadataLabels := unstructuredRequiredPrometheus.GetLabels()
Copy link
Contributor

Choose a reason for hiding this comment

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

these may be worth a comment.
Just to be sure I understand, is this done to avoid

?

Copy link
Member Author

Choose a reason for hiding this comment

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

func (c *Client) CreateOrUpdatePrometheus(ctx context.Context, p *monv1.Prometheus) error {
pclient := c.mclient.MonitoringV1().Prometheuses(p.GetNamespace())
existing, err := pclient.Get(ctx, p.GetName(), metav1.GetOptions{})
func (c *Client) CreateOrUpdatePrometheus(ctx context.Context, structuredRequiredPrometheus *monv1.Prometheus) (*bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to return a pointer instead of just a bool here?
I don't think tests should rely on this, I think we should retrieve whether the object was updated from the API/client.

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 looked at the usages and there doesn't seem to be a need for three states. Fixed! 👍🏼

Copy link
Contributor

openshift-ci bot commented Aug 5, 2024

@rexagod: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Comment on lines 1872 to 1880
shouldUpdate: true,
},
{
description: "apply no value to the existing prometheus",
prometheus: &monv1.Prometheus{
TypeMeta: initialPrometheus.TypeMeta,
ObjectMeta: initialPrometheus.ObjectMeta,
},
shouldUpdate: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

With the no defaulting approach, there won't be a difference between default and non-default applications, as both will trigger updates as compared to just the latter earlier, at the benefit of not maintaining hardcoded default values in CMO. LMK if I should revert this or if this sounds good.

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. jira/severity-moderate Referenced Jira bug's severity is moderate for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. qe-approved Signifies that QE has signed off on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants