Skip to content

feat: tf api metrics#4880

Merged
google-oss-prow[bot] merged 4 commits intoGoogleCloudPlatform:masterfrom
acpana:acpana/kcc-api-metrics-tfs
Aug 5, 2025
Merged

feat: tf api metrics#4880
google-oss-prow[bot] merged 4 commits intoGoogleCloudPlatform:masterfrom
acpana:acpana/kcc-api-metrics-tfs

Conversation

@acpana
Copy link
Collaborator

@acpana acpana commented Jul 30, 2025

Change description

Adds support for tf level metrics too!

$ curl http://localhost:8888/prom-metrics | grep "gcp_api_requests_total"

# HELP configconnector_gcp_api_requests_total Total number of GCP API requests
# TYPE configconnector_gcp_api_requests_total counter
...
configconnector_gcp_api_requests_total{controller_name="tagstagkey-controller",method="GET",status_code="2xx"} 4
configconnector_gcp_api_requests_total{controller_name="tagstagkey-controller",method="POST",status_code="2xx"} 3

Special notes for your reviewer:

Does this PR add something which needs to be 'release noted'?


  • Reviewer reviewed release note.

Additional documentation e.g., references, usage docs, etc.:


Intended Milestone

Please indicate the intended milestone.

  • Reviewer tagged PR with the actual milestone.

Tests you have done

  • Run make ready-pr to ensure this PR is ready for review.
  • Perform necessary E2E testing for changed resources.

metaC := baseConfig.Clone()
metaC.Context = metricstransport.WithControllerName(ctx, r.controllerName) // for metrics transport
meta = metaC
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in my experience, we needed to clone this Config as the Context that it uses for HTTP requests is the one that we first configure the provider with AND NOT the ctx that we have in hand here.

@acpana acpana force-pushed the acpana/kcc-api-metrics-tfs branch from 0ec2d47 to ae01764 Compare July 30, 2025 01:29
@yuwenma
Copy link
Collaborator

yuwenma commented Jul 30, 2025

/lgtm
/assign @maqiuyujoyce

@google-oss-prow google-oss-prow bot added the lgtm label Jul 30, 2025
@acpana acpana added this to the 1.134 milestone Jul 30, 2025
meta = metaC
}

requeue, err := r.sync(ctx, resource, meta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems strange you are passing 1 context directly to sync and a different context to sync through the meta object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes that's what I wanted to highlight here:

#4880 (comment)

Note "we" were always doing this before in that the TF Apply command takes in the ctx for some operations but for actual HTTP calls and transport calls it uses the Context in the meta

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still don't like this. To quote from https://go.dev/blog/context-and-structs "Contexts should not be stored inside a struct type, but instead passed to each function that needs it."

To quote from https://pkg.go.dev/context "Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it. This is discussed further in https://go.dev/blog/context-and-structs. The Context should be the first parameter, typically named ctx:"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I realize this is not an anti-pattern your putting in, but it is very much an anti-pattern.

@acpana
Copy link
Collaborator Author

acpana commented Jul 30, 2025

/hold want to merge #4879 first

@acpana acpana force-pushed the acpana/kcc-api-metrics-tfs branch from ae01764 to f1f84ed Compare August 2, 2025 00:36
@google-oss-prow google-oss-prow bot removed the lgtm label Aug 2, 2025
@acpana
Copy link
Collaborator Author

acpana commented Aug 2, 2025

/hold cancel

@cheftako
Copy link
Collaborator

cheftako commented Aug 3, 2025

/hold want to merge #4879 first

4879 is merged

RequestBatcherIam *RequestBatcher
}

func (c *Config) Clone() *Config {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this really need to be in the third_party directory? Could we maybe move it into the controller, and have a function like CloneAndChangeContext, and in the comment for that we say what it is doing, how this is sort of a hack, but it's a reasonable thing to do given what we have to work with.

acpana added 4 commits August 5, 2025 14:42
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
@acpana acpana force-pushed the acpana/kcc-api-metrics-tfs branch from 2123e27 to c1db92b Compare August 5, 2025 14:42
@cheftako
Copy link
Collaborator

cheftako commented Aug 5, 2025

/lgtm
/approve

@google-oss-prow
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheftako

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

The pull request process is described here

Details 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

@google-oss-prow google-oss-prow bot merged commit eca274e into GoogleCloudPlatform:master Aug 5, 2025
62 checks passed
fqbright pushed a commit to fqbright/k8s-config-connector that referenced this pull request Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants