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

persist starlark state for more starlark types #15924

Open
gazpachoking opened this issue Sep 22, 2024 · 3 comments
Open

persist starlark state for more starlark types #15924

gazpachoking opened this issue Sep 22, 2024 · 3 comments
Labels
area/starlark feature request Requests for new plugin and for new features to existing plugins help wanted Request for community participation, code, contribution size/m 2-4 day effort

Comments

@gazpachoking
Copy link
Contributor

Use Case

#15170 added the ability for the starlark processor to persist the global state to the statefile between runs. This is very nice, but it can't store lists, dicts, tuples, or metrics to the state file which severely limits its usefulness. If you try any more complex type you get an error like invalid starlark type *starlark.Metric when it tries to write the state file.

My desired use case is similar to the example for comparing a metric to the previous one. This doesn't work because it stores both a dict and a metric in the global state.

Expected behavior

Starlark standard types (lists, dicts, tuples, and maybe also metrics) can be persisted to the statefile.

Actual behavior

Error when persisting the plugin states.

Additional info

No response

@gazpachoking gazpachoking added the feature request Requests for new plugin and for new features to existing plugins label Sep 22, 2024
@srebhan
Copy link
Member

srebhan commented Oct 8, 2024

Next steps: implement a function to convert starlark values to go-values and vice versa.

@srebhan srebhan added help wanted Request for community participation, code, contribution area/starlark size/m 2-4 day effort labels Oct 8, 2024
@knollet
Copy link
Contributor

knollet commented Oct 9, 2024

Hi, the statefile saves json, and you can in fact save lists, dicts, strings, numbers, booleans and Nonetype (None, null). (I will call this "simple-type")

To allow for storing arbitrary types could be a problem, because not every object can be stored (Resource handles of any kind (open files, handles for secrets, etc) come to mind).

I would recommend to implement "simple-type"-serializers and deserializers (marshallers and unmarshallers) for every type (or Metric at least) which should be storable.

So have something like
Metric.serialize() -> dict # {"name": ..., "tags": { ... }, "fields": { ... }, "time": ...}
and
Metric.__init__(marsh: dict) -> Metric

Also: state could have an interface which denies everything which isn't a "simple-type", so it would error out before it tries to write it to the statefile.

@srebhan
Copy link
Member

srebhan commented Oct 10, 2024

The metric should be serialized as gob and encoded as base64 to be able to distinct integer/float types which is not possible with pure JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/starlark feature request Requests for new plugin and for new features to existing plugins help wanted Request for community participation, code, contribution size/m 2-4 day effort
Projects
None yet
Development

No branches or pull requests

3 participants