Repository navigation
Closed
kubernetes-client/python-base
#171Labels
kind/bugCategorizes issue or PR as related to a bug.
Description
What happened (please include outputs or screenshots):
When I got log like blow (use stream)
{"level": "error", "message": "error on app"}
10.216.68.8 - - [12/Oct/2019 12:57:26] "GET /error HTTP/1.1" 200 -
{"level": "error", "message": "error on app"}
10.216.68.9 - - [12/Oct/2019 12:57:26] "GET /error HTTP/1.1" 200 -
10.216.91.1 - - [12/Oct/2019 12:57:30] "GET /readiness HTTP/1.1" 200 -
Error occured like below
Traceback (most recent call last):
File "/Users/hoyongpark/Documents/work/dference/groot/.venv/lib/python3.7/site-packages/kubernetes/watch/watch.py", line 149, in stream
yield self.unmarshal_event(line, return_type)
File "/Users/hoyongpark/Documents/work/dference/groot/.venv/lib/python3.7/site-packages/kubernetes/watch/watch.py", line 97, in unmarshal_event
js['raw_object'] = js['object']
KeyError: 'object'
What you expected to happen:
Get a logs without error
How to reproduce it (as minimally and precisely as possible):
Try to get json type log like this
{"level": "error", "message": "error on app"}
Anything else we need to know?:
def unmarshal_event(self, data, return_type):
# data => {"level": "error", "message": "error on app"}
try:
js = json.loads(data) # OMG data parsed!. js => {'level': "error", 'message': "error on app"}
except ValueError:
return data
js['raw_object'] = js['object'] # js doesn't have 'object'
if return_type:
obj = SimpleNamespace(data=json.dumps(js['raw_object']))
js['object'] = self._api_client.deserialize(obj, return_type)
if hasattr(js['object'], 'metadata'):
self.resource_version = js['object'].metadata.resource_version
# For custom objects that we don't have model defined, json
# deserialization results in dictionary
elif (isinstance(js['object'], dict) and 'metadata' in js['object']
and 'resourceVersion' in js['object']['metadata']):
self.resource_version = js['object']['metadata'][
'resourceVersion']
return js
Environment:
- Kubernetes version (
kubectl version): 1.15 - OS (e.g., MacOS 10.13.6): MacOS Mojave 10.14.6
- Python version (
python --version) : Python 3.7.3 - Python client version (
pip list | grep kubernetes) : 10.0.1
Metadata
Metadata
Assignees
Labels
kind/bugCategorizes issue or PR as related to a bug.
Activity
mikai21 commentedon Oct 12, 2019
I checked fix like below. But this is a bad solution.
If a log has the 'object' key, then It goes to problem...
roycaihw commentedon Oct 15, 2019
/assign
mikai21 commentedon Oct 22, 2019
@Ark-kun
Thank you for fixing.
But, I still have concern about parsing error if log is json type string and it has "object" key.
I think https://github.com/Ark-kun/python-base/commit/f11587d0e3cedf645ba12fe4dfd7971ee7162c9d is not a fundamental solution.
Add tests of unmarshaling literals to watch.py
Add tests of unmarshaling literals to watch.py
Add tests of unmarshaling literals to watch.py
Add tests of unmarshaling literals to watch.py
Ark-kun commentedon Oct 24, 2019
Unfortunately, the fundamental solution might not exist. dictionaries duck typed by design. You cannot type-check them. The code in question decided to do some transformation of the
data['object']. This design decision might not be easy to undo.Ark-kun commentedon Oct 24, 2019
Maybe we should just disable unmarshalling for logs.
fejta-bot commentedon Jan 31, 2020
Issues go stale after 90d of inactivity.
Mark the issue as fresh with
/remove-lifecycle stale.Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with
/close.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
roycaihw commentedon Feb 18, 2020
/remove-lifecycle stale
/unassign
/assign @jiahuif
k8s-ci-robot commentedon Feb 18, 2020
@roycaihw: GitHub didn't allow me to assign the following users: jiahuif.
Note that only kubernetes-client members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
jiahuif commentedon Feb 18, 2020
That is good enough to give me a ping. Let me recall the context.
Fixed Watch.unmarshal_event when data is not a JSON-serialized object
Fixed Watch.unmarshal_event when data is not a JSON-serialized object
Fixed Watch.unmarshal_event when data is not a JSON-serialized object