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

json serialization error for work units of linting helm charts #21773

Open
cburroughs opened this issue Dec 17, 2024 · 0 comments · May be fixed by #21792
Open

json serialization error for work units of linting helm charts #21773

cburroughs opened this issue Dec 17, 2024 · 0 comments · May be fixed by #21792
Labels

Comments

@cburroughs
Copy link
Contributor

Describe the bug

cd $(mktemp -d)

cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.23.0"
backend_packages = [
  "pants.backend.experimental.helm",
  "pants.backend.experimental.tools.workunit_logger",

]
[helm]
lint_strict = true
EOF

mkdir -p src/helm/foo/

cat > src/helm/foo/Chart.yaml <<EOF
apiVersion: v2
description: Foo Helm chart
name: foo
version: 0.1.0
EOF

cat > src/helm/foo/BUILD <<EOF
helm_chart()
EOF

PANTS_WORKUNIT_LOGGER_ENABLED=true pants --no-pantsd lint ::

error log:

7:08:00.73 [INFO] Completed: Lint Helm charts - helm succeeded.
Partition: foo
==> Linting foo
[INFO] Chart.yaml: icon is recommended
[INFO] values.yaml: file does not exist

1 chart(s) linted, 0 chart(s) failed




✓ helm succeeded.
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/threading.py", line 980, in _bootstrap_inner
    self.run()
  File "/home/ecsb/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/venvs/2.23.0/lib/python3.9/site-packages/pants/engine/streaming_workunit_handler.py", line 323, in run
    self.poll_workunits(finished=True)
  File "/home/ecsb/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/venvs/2.23.0/lib/python3.9/site-packages/pants/engine/streaming_workunit_handler.py", line 306, in poll_workunits
    callback(
  File "/home/ecsb/.cache/nce/ab1acf935c4cc43338c604ae7d0f6aa2419f2415d94eb9cae381601dbba70a61/bindings/venvs/2.23.0/lib/python3.9/site-packages/pants/backend/tools/workunit_logger/rules.py", line 71, in __call__
    json.dump(just_dump_map(self._completed_workunits), f)
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/json/encoder.py", line 429, in _iterencode
    yield from _iterencode_list(o, _current_indent_level)
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/home/ecsb/.cache/nce/67912efc04f9156d8f5b48a0348983defb964de043b8c13ddc6cc8a002f8e691/cpython-3.9.18+20240107-x86_64-unknown-linux-gnu-install_only.tar.gz/python/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Platform is not JSON serializable

Pants version
2.23.0 and main

@cburroughs cburroughs added the bug label Dec 17, 2024
cburroughs added a commit to cburroughs/pants that referenced this issue Dec 20, 2024
As described in pantsbuild#21773, having the Helm backend lint with the
workunit-logger results in json serialization errors.  Giving `Platform`
a string representation resolves this (and anywhere else we may want
to "print" it.

Example workunit:
```
{"name": "pants.backend.helm.util_rules.tool.download_external_helm_plugin", "span_id": "bdaa19a5cd1ef797", "level": "DEBUG", "parent_id": "c8c137a5b78f02ea", "start_secs": 1734722271, "start_nanos": 296631921, "duration_secs": 0, "duration_nanos": 51846519, "description": "Download external Helm plugin", "metadata": {"name": "unittest", "version": "0.3.3", "platform": "linux_x86_64"}}
```

NOTE: I think this is a totally safe one line change, but admit it is
to a rather core class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant