GoogleCloudPlatform / k8s-config-connector

GCP Config Connector, a Kubernetes add-on for managing GCP resources
https://cloud.google.com/config-connector/docs/overview
Apache License 2.0
860 stars 199 forks source link

feat: add optional logging for expander stages #2162

Open xiaoweim opened 4 days ago

xiaoweim commented 4 days ago

This PR adds the option to enable logging for each expander stage for better debug ability.

Log message start with expanderDebugLog---${Kind}/${Namespace}/${Name}---version: ${Version}

Example log:

2024-06-29T00:35:34Z    DEBUG   events  expanderDebugLog---PConfig/team-a/team-a-config---version: 1    {"type": "Normal", "object": {"kind":"PConfig","namespace":"team-a","name":"team-a-config","uid":"9d674656-1db3-4d54-b5eb-f51bf90d8732","apiVersion":"facade.foocorp.com/v1alpha1","resourceVersion":"679"}, "reason": "Running expander stage 0: common"}
2024-06-29T00:35:34Z    DEBUG   events  expanderDebugLog---PConfig/team-a/team-a-config---version: 1---request: config:"apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: common-config\n  namespace: {{ pconfigs.metadata.namespace }}\n  labels:\n    createdby: \"composition-namespaceconfigmap\"\ndata:\n  key1: value1" context:"{\"apiVersion\":\"composition.google.com/v1alpha1\",\"kind\":\"Context\",\"metadata\":{\"creationTimestamp\":\"2024-06-29T00:35:33Z\",\"generation\":1,\"managedFields\":[{\"apiVersion\":\"composition.google.com/v1alpha1\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:spec\":{\".\":{},\"f:project\":{}}},\"manager\":\"testcases.test\",\"operation\":\"Update\",\"time\":\"2024-06-29T00:35:33Z\"}],\"name\":\"context\",\"namespace\":\"team-a\",\"resourceVersion\":\"678\",\"uid\":\"aafd1a60-c07c-4d2e-95e7-059be18ef8b9\"},\"spec\":{\"project\":\"proj-a\"}}" facade:"{\"apiVersion\":\"facade.foocorp.com/v1alpha1\",\"kind\":\"PConfig\",\"metadata\":{\"annotations\":{\"composition-expander-debug-logs\":\"true\"},\"creationTimestamp\":\"2024-06-29T00:35:33Z\",\"generation\":1,\"managedFields\":[{\"apiVersion\":\"facade.foocorp.com/v1alpha1\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:metadata\":{\"f:annotations\":{\".\":{},\"f:composition-expander-debug-logs\":{}}},\"f:spec\":{\".\":{},\"f:project\":{}}},\"manager\":\"testcases.test\",\"operation\":\"Update\",\"time\":\"2024-06-29T00:35:33Z\"}],\"name\":\"team-a-config\",\"namespace\":\"team-a\",\"resourceVersion\":\"679\",\"uid\":\"9d674656-1db3-4d54-b5eb-f51bf90d8732\"},\"spec\":{\"project\":\"proj-a\"}}" value:"{}" resource:"pconfigs", result: error:{} type:MANIFESTS manifests:"apiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: common-config\n  namespace: team-a\n  labels:\n    createdby: \"composition-namespaceconfigmap\"\ndata:\n  key1: value1"    {"type": "Normal", "object": {"kind":"PConfig","namespace":"team-a","name":"team-a-config","uid":"9d674656-1db3-4d54-b5eb-f51bf90d8732","apiVersion":"facade.foocorp.com/v1alpha1","resourceVersion":"679"}, "reason": "Expander stage common evaluation completed"}
2024-06-29T01:02:23Z    DEBUG   events  expanderDebugLog---PConfig/team-a/team-a-config---version: 1---resource count: 1    {"type": "Normal", "object": {"kind":"PConfig","namespace":"team-a","name":"team-a-config","uid":"431e53bf-1c9c-4ee2-873d-bdf4028c98db","apiVersion":"facade.foocorp.com/v1alpha1","resourceVersion":"678"}, "reason": "Finished expander stage 0: common"}
xiaoweim commented 3 days ago

/assign @barney-s @cheftako

google-oss-prow[bot] commented 3 days ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please ask for approval from barney-s. For more information see the Kubernetes Code Review Process.

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

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/GoogleCloudPlatform/k8s-config-connector/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment