monitoring-mixins / mixtool

mixtool is a helper for easily working with jsonnet mixins.
Apache License 2.0
139 stars 15 forks source link

Support for mixins with Jsonnet external-variables #36

Open ArthurSens opened 3 years ago

ArthurSens commented 3 years ago

It is possible to generate mixins using jsonnet external variables, but not possible to use mixtool with those jsonnet files:

gitpod /workspace/observability $ mixtool lint monitoring-satellite/main.jsonnet 
RUNTIME ERROR: Undefined external variable: remote_write_url
        monitoring-satellite/main.jsonnet:11:7-37       builtin function <extVar>
        monitoring-satellite/main.jsonnet:89:57-59
        <std>:1293:24-25        thunk from <function <anonymous>>
        <std>:1293:5-33 function <anonymous>
        monitoring-satellite/main.jsonnet:89:40-77      $

        2:16-58 thunk <mixin> from <$>
        4:21-26 thunk from <$>
        <std>:1302:21-22        thunk from <function <anonymous>>
        <std>:1302:5-32 function <anonymous>
        4:4-47  $
        During evaluation

RUNTIME ERROR: Undefined external variable: remote_write_url
        monitoring-satellite/main.jsonnet:11:7-37       builtin function <extVar>
        monitoring-satellite/main.jsonnet:89:57-59
        <std>:1293:24-25        thunk from <function <anonymous>>
        <std>:1293:5-33 function <anonymous>
        monitoring-satellite/main.jsonnet:89:40-77      $

        2:16-58 thunk <mixin> from <$>
        4:21-26 thunk from <$>
        <std>:1302:21-22        thunk from <function <anonymous>>
        <std>:1302:5-32 function <anonymous>
        4:4-48  $
        During evaluation

2021/05/12 18:58:19 failed to lint the file monitoring-satellite/main.jsonnet: 2 lint errors found

It would be nice if we could run for example:

mixtool lint --ext-str remote_write_url='my-remote-backend-url' monitoring-satellite/main.jsonnet 
metalmatze commented 3 years ago

That sounds good. Happy to add this in a PR.

rgeyer commented 2 years ago

Mixtool should also support TLAs (Top-level arguments).

This is going to require fairly significant refactoring of the eval methods, since we can no longer assume that the content of the loaded mixin file will be a "simple" object with known properties. It could be a function in the case of TLAs, for example.