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

Log output error: json: error calling MarshalJSON for type time.Time #592

Open
johnhowlett opened this issue Feb 18, 2024 · 2 comments
Open

Comments

@johnhowlett
Copy link

If I start chaoskube with the --log-format=json in the log output there is a error:

./chaoskube --log-format=json --excluded-times-of-day="22:00-06:00" --excluded-weekdays=Sat,Sun --excluded-days-of-year=Apr1,Dec24 --labels="foo,bar" --kinds='!DaemonSet' --annotations='a.foo,a.bar'
{"dryRun":true,"interval":600000000000,"level":"info","maxRuntime":-1000000000,"msg":"starting up","time":"2024-02-18T11:15:37+01:00","version":"v0.31.0"}
{"level":"info","master":"https://127.0.0.1:6443","msg":"connected to cluster","serverVersion":{"major":"1","minor":"28","gitVersion":"v1.28.1+k3s1","gitCommit":"0d23cfe038ef22d7ca899764e9aaeea8a39d4874","gitTreeState":"clean","buildDate":"2023-09-08T17:15:00Z","goVersion":"go1.20.7","compiler":"gc","platform":"linux/arm64"},"time":"2024-02-18T11:15:37+01:00"}
{"annotations":[{},{}],"excludedPodNames":null,"includedPodNames":null,"kinds":[{}],"labels":[{},{}],"level":"info","maxKill":1,"minimumAge":0,"msg":"setting pod filter","namespaceLabels":null,"namespaces":null,"time":"2024-02-18T11:15:37+01:00"}
Failed to obtain reader, failed to marshal fields to JSON, json: error calling MarshalJSON for type time.Time: Time.MarshalJSON: year outside of range [0,9999]
{"level":"info","location":{},"msg":"setting timezone","name":"UTC","offset":0,"time":"2024-02-18T11:15:37+01:00"}

Also the parameter of the kinds, annotations, labels, ... are not shown in the log output.
The program is running fine, it is only the log output that has a error and thas not show all of the input parameters

With adding the String() method to the:

-               "labels":           labelSelector,
-               "annotations":      annotations,
-               "kinds":            kinds,
-               "namespaces":       namespaces,
-               "namespaceLabels":  namespaceLabels,
+               "labels":           labelSelector.String(),
+               "annotations":      annotations.String(),
+               "kinds":            kinds.String(),
+               "namespaces":       namespaces.String(),
+               "namespaceLabels":  namespaceLabels.String(),

and renaming the log field:

-               "timesOfDay": parsedTimesOfDay,
+               "timesOfDay": excludedTimesOfDay, 

I was able to solve the issue, but I'm not sure if this approach is in the spirit of the inventor.

@linki
Copy link
Owner

linki commented Apr 23, 2024

@johnhowlett Sounds good to me! Feel free to open a pull request with your changes.

@johnhowlett
Copy link
Author

made pull request:
https://github.com/linki/chaoskube/pull/602

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

No branches or pull requests

2 participants