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

Display formatted logs for Toolkit Components #748

Closed
w0wka91 opened this issue Jan 20, 2021 · 6 comments · Fixed by #1075
Closed

Display formatted logs for Toolkit Components #748

w0wka91 opened this issue Jan 20, 2021 · 6 comments · Fixed by #1075

Comments

@w0wka91
Copy link

w0wka91 commented Jan 20, 2021

It would be nice if the CLI would be able to display formatted logs for all of the Toolkit Components.
We could grab the logs from the specific pod, pass the logs into a json processor and show it to the user.

The API could be something like:

flux log (helm|source|kustomize|notification) --watch

@stefanprodan
Copy link
Member

I think such a command would be a good UX improvement if we allow users to filter the logs by level, kind, name and namespace.

Print kustomize-controller reconciliation errors:

flux logs kustomize-controller --level=error --watch=true --tail=100

Print reconciliations errors of a Kustomization named podinfo from the default namespace:

flux logs kustomize-controller --level=error --kind=Kustomization --name=podinfo --namespace=default

We need to decide how we want to display the logs in the console output.
Here is the json log of a reconciliation error:

{"level":"error","ts":"2021-01-20T08:27:45.548Z","logger":"controller.kustomization","msg":"Reconciler error","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"podinfo","namespace":"default","error":"apply failed: The Deployment \"podinfo\" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{\"app\":\"podinfo\", \"app.kubernetes.io/name\":\"podinfo\"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable\n"}

@w0wka91
Copy link
Author

w0wka91 commented Jan 20, 2021

It could be also useful to filter logs by level without specifying the component

Print all recently occured errors:
flux logs --level=error --watch=true --tail=100

We could provide a default output-format and let the user overwrite it via an environment variable?!
Default could be something like this:

%TIMESTAMP %LEVEL %KIND - %MESSAGE

The output would look like this:
2021-01-20 08:27:45 ERROR Kustomization - apply failed: The Deployment \"podinfo\" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{\"app\":\"podinfo\", \"app.kubernetes.io/name\":\"podinfo\"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Another approach would be to simply pass the current json log to a json processor like: jq

@stefanprodan
Copy link
Member

stefanprodan commented Jan 20, 2021

Showing the error field is not enough, we need msg as well.

Another approach would be to simply pass the current json log to a json processor like: jq

Then I see no reason to implement flux logs, a combination of kubectl logs | jq <filters> is what I currently use. If we go for a command like flux logs we should filter and parse the json is a readable format so people don't have to pipe it into jq.

@w0wka91
Copy link
Author

w0wka91 commented Jan 20, 2021

Showing the error field is not enough, we need msg as well.

Output for log level ERROR:

2021-01-20 08:27:45 ERROR Kustomization - Reconciler error
  apply failed: The Deployment \"podinfo\" is invalid: spec.selector: Invalid value: 
    v1.LabelSelector{MatchLabels:map[string]string{\"app\":\"podinfo\", \"app.kubernetes.io/name\":\"podinfo\"}, 
    MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Output for log level INFO:

2021-01-20 08:27:45 INFO Kustomization - Kustomization applied in 345.21018ms. 
  helmrepository.source.toolkit.fluxcd.io/podinfo: unchanged
  helmrepository.source.toolkit.fluxcd.io/bitnami: unchanged

@stefanprodan
Copy link
Member

I propose this format:

<TS> <LEVEL> <kind/name.namespace> - <MSG> <ERROR>

@w0wka91
Copy link
Author

w0wka91 commented Jan 20, 2021

Sounds good to me

ybelleguic pushed a commit to ybelleguic/flux2 that referenced this issue Jan 9, 2023
OCI HelmRepo: handle status conditions in-line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants