-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add SharedInformer and SharedInformerFactory setDebugItems #3121
Open
codefromthecrypt
wants to merge
3
commits into
kubernetes-client:master
Choose a base branch
from
codefromthecrypt:watch-log
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add SharedInformer and SharedInformerFactory setDebugItems #3121
codefromthecrypt
wants to merge
3
commits into
kubernetes-client:master
from
codefromthecrypt:watch-log
+95
−31
Commits on Feb 27, 2024
-
This adds debug logging for the logger: io.kubernetes.client.util.Watch Notably, this logs when a watch is created, receives a new response body line, is exhausted, or closed. The below is an example log from spring-cloud-kubernetes discoveryserver which uses watches. As you'll notice, its log format already includes the thread name. However, the path watched is in the log message so that formats that don't include the thread can disambiguate. Feedback welcome! See kubernetes-client#275 (comment) ``` 2024-02-27T14:56:19.253Z DEBUG 1 --- [s.V1Endpoints-1] [ ] io.kubernetes.client.util.Watch : creating watch /api/v1/namespaces/default/endpoints 2024-02-27T14:56:19.256Z DEBUG 1 --- [els.V1Service-1] [ ] io.kubernetes.client.util.Watch : creating watch /api/v1/namespaces/default/services --snip-- 2024-02-27T14:57:46.137Z DEBUG 1 --- [s.V1Endpoints-1] [ ] io.kubernetes.client.util.Watch : /api/v1/namespaces/default/endpoints response line: {"type":"MODIFIED","object":{"kind":"Endpoints","apiVersion":"v1","metadata":{"name":"demo2","namespace":"default","uid":"7f00905a-2f1f-4f19-ab0f-13e8131fc6d5","resourceVersion":"151340","creationTimestamp":"2024-02-23T07:43:53Z","labels":{"app.kubernetes.io/instance":"demo2","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"demo2","app.kubernetes.io/version":"1.16.0","helm.sh/chart":"demo2-0.1.0"},"managedFields":[{"manager":"k3s","operation":"Update","apiVersion":"v1","time":"2024-02-23T07:43:54Z","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{".":{},"f:app.kubernetes.io/instance":{},"f:app.kubernetes.io/managed-by":{},"f:app.kubernetes.io/name":{},"f:app.kubernetes.io/version":{},"f:helm.sh/chart":{}}}}}]}}} ``` Signed-off-by: Adrian Cole <adrian@tetrate.io>
Adrian Cole committedFeb 27, 2024 Configuration menu - View commit details
-
Copy full SHA for 7ca1f04 - Browse repository at this point
Copy the full SHA 7ca1f04View commit details
Commits on Feb 28, 2024
-
Add SharedInformer and SharedInformerFactory setDebugItems
This centralizes logging into the existing `ReflectorRunnable` type, notably adding conditional logging of events. This is toggled by `setDebugItems(bool)` on `SharedInformer` and `SharedInformerFactory` as `ReflectorRunnable` isn't directly accessible by end users. Now, you can configure these independent of `ApiType` or if your needs are simple, use the logger. ```java boolean shouldDebugItems = LogFactory.getLog(ReflectorRunnable.class).isDebugEnabled(); sharedInformerFactory.setDebugItems(shouldDebugItems); serviceInformer.setDebugItems(shouldDebugItems); endpointsInformer.setDebugItems(shouldDebugItems); ``` Then, you can see streaming updates like this: ``` 2024-02-28T01:29:56.980Z DEBUG 1 --- [s.V1Endpoints-1] [ ] i.k.c.informer.cache.ReflectorRunnable : V1Endpoints#Receiving resourceVersion 154844 2024-02-28T01:30:06.582Z DEBUG 1 --- [s.V1Endpoints-1] [ ] i.k.c.informer.cache.ReflectorRunnable : V1Endpoints#Next item class V1Endpoints { apiVersion: v1 kind: Endpoints metadata: class V1ObjectMeta { annotations: {endpoints.kubernetes.io/last-change-trigger-time=2024-02-28T01:30:06Z} creationTimestamp: 2024-02-27T05:54:17Z deletionGracePeriodSeconds: null deletionTimestamp: null finalizers: null generateName: null generation: null labels: {app.kubernetes.io/instance=zipkin, app.kubernetes.io/managed-by=Helm, app.kubernetes.io/name=zipkin, app.kubernetes.io/version=3.0.6, helm.sh/chart=zipkin-0.2.0} managedFields: [class V1ManagedFieldsEntry { apiVersion: v1 fieldsType: FieldsV1 fieldsV1: {f:metadata={f:annotations={.={}, f:endpoints.kubernetes.io/last-change-trigger-time={}}, f:labels={.={}, f:app.kubernetes.io/instance={}, f:app.kubernetes.io/managed-by={}, f:app.kubernetes.io/name={}, f:app.kubernetes.io/version={}, f:helm.sh/chart={}}}, f:subsets={}} manager: k3s operation: Update subresource: null time: 2024-02-28T01:30:06Z }] name: zipkin namespace: default ownerReferences: null resourceVersion: 154855 selfLink: null uid: 462ae678-e912-4491-bc93-3851580cae10 } subsets: [class V1EndpointSubset { addresses: [class V1EndpointAddress { hostname: null ip: 10.42.0.225 nodeName: colima targetRef: class V1ObjectReference { apiVersion: null fieldPath: null kind: Pod name: zipkin-57667879f-kc49k namespace: default resourceVersion: null uid: 8670d47d-7582-4d0c-93b3-cff41d8a5a50 } }] notReadyAddresses: null ports: [class CoreV1EndpointPort { appProtocol: null name: http-query port: 9411 protocol: TCP }] }] } 2024-02-28T01:30:06.586Z DEBUG 1 --- [s.V1Endpoints-1] [ ] i.k.c.informer.cache.ReflectorRunnable : V1Endpoints#Receiving resourceVersion 154855 ``` This also reduces the verbosity of log lines, by making the log tag match the simple name of the type instead of the type's `toString()`. As a side effect, this also matches the item `toString` values who also use the simple name. For example, without this change, the log message prefix is extremely long and includes "class io.kubernetes.client.openapi.models." which isn't needed to disambiguate types watched. ``` 2024-02-28T01:07:55.114Z DEBUG 1 --- [els.V1Service-1] [ ] i.k.c.informer.cache.ReflectorRunnable : class io.kubernetes.client.openapi.models.V1Service#Extract resourceVersion 154265 list meta 2024-02-28T01:07:55.114Z DEBUG 1 --- [els.V1Service-1] [ ] i.k.c.informer.cache.ReflectorRunnable : class io.kubernetes.client.openapi.models.V1Service#Initial items [class V1Service { ``` Signed-off-by: Adrian Cole <adrian@tetrate.io>
Adrian Cole committedFeb 28, 2024 Configuration menu - View commit details
-
Copy full SHA for c71d1f1 - Browse repository at this point
Copy the full SHA c71d1f1View commit details
Commits on Mar 5, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 14c791b - Browse repository at this point
Copy the full SHA 14c791bView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.