Live data from Hacker News

Jsonnet – A data templating language

jsonnet.org

41–50 of 90 posts

Re: Jsonnet – A data templating language

#42
post #39

Finally a public version of GCL/Borgcfg :-) For people who doesn't know, GCL (Generic/Google Config Language) is a language that uses dynamic scope. You can define a `template` object with a variable defined as `external`. This way you can create similar objects by providing a concrete value for those `external`s at the time of instantiating. The following paper was referenced in Google's borg paper and gives a good…

(shameless plug) The missing piece to turn it into borgcfg: https://github.com/bitnami/kubecfg

Re: Jsonnet – A data templating language

#43
post #17
post #10

Why would I use this over, say, Jinja? Do I really want imperative code in my config files? And if so, why not just use vanilla JS?

Why don't you take a look at the link? It has a page specifically addressing these questions: https://jsonnet.org/articles/comparisons.html

Very nice page. I'm missing the comparison with Dhall though (there is Nix).

Re: Jsonnet – A data templating language

#44
post #36

All the people suggesting to use JS instead of Jsonnet are completely missing the point. Jsonnet is a functional lazy evaluated language that supports powerful referential concepts. Unfortunately the website sucks at getting this across. JS on the other hand is an imperative programming language. If you say "use JS" you may as well say "use Python", the 2 are equivalent in this context and neither are in the same cla…

We tried jsonnet for several months to generate config, but eventually abandoned it because the templates got too hairy. Plus rendering is slow.

We ended making the effort to simplify config of all our app’s components to just read from one large yaml file. Far happier with this solution.

Re: Jsonnet – A data templating language

#45
post #39

Finally a public version of GCL/Borgcfg :-) For people who doesn't know, GCL (Generic/Google Config Language) is a language that uses dynamic scope. You can define a `template` object with a variable defined as `external`. This way you can create similar objects by providing a concrete value for those `external`s at the time of instantiating. The following paper was referenced in Google's borg paper and gives a good…

Maybe it’s because I’m not a top 1% intelligence that I don’t get this but under what circumstances would configurations become complex enough to where this becomes necessary?

Re: Jsonnet – A data templating language

#47
Also check out https://dhall-lang.org

It's GCL but with a strong type system and termination guarantees.

I personally like the syntax a bit more than jsonnet. It's a bit less noisy.

I'm also a bit biased because I work on https://github.com/dhall-lang/dhall-kubernetes . We're currently working on a 2.0 release so the current state of the repo is a bit in turmoil.

Programmable configuration language like dhall an jsonet are very powerful and I like them way more than for example helm charts, where templating happens on the string level instead of at the data level.

Re: Jsonnet – A data templating language

#48
I have never used a language/tool like this at scale and enjoyed it.

For example, embedding a bash script in a templating language. This is such an incredibly crap idea I don't know how it keeps getting perpetuated. Use of this pattern works as follows: user A writes the script, tests it, shoves it into template. user B modifies the template, commits it, it later breaks silently because it was not tested, because it's in a template language, so you can't lint it and it has no tests written for it (because how did you know it would even get generated based on your input/function, let alone all the places it would be used and how, because templates). user C finds the hidden breakage after tearing out hair, removes the script from template, and writes it as a normal script that takes options and writes a test for good measure. (If you try to use normal dev patterns around the templates, like generate-template-then-commit-to-vcs, relying on and testing the generated versions, your tests have to be reworked whenever you regenerate, and later the generator gradually begins to break, so you just modify the copy in VCS rather than using the template)

A separate problem is that templating languages that give you advanced functionality lead you to want to use that functionality, and the more you do, the harder it is to maintain over time. It may not be readily apparent that trying to make Ansible configs work declaratively requires an annoying amount of complexity, or writing entire applications that cannot be easily reused and calling them "modules" or "plugins". (Whatever you are trying to template/generate, the only way to know for sure you're doing it validly is to have a function that actually parses and outputs the format according to a spec, because just spitting out a template and then externally validating it becomes very difficult to debug, because you don't know why the template is spitting out the output the way it is. So your templating language eventually becomes a compiler)

Since this is a new language, you also have to re-implement everything you normally have for a language, like a plug-in for your IDE, linter, debugger, code analyzer, port the standard libraries to different systems, etc. And of course all new devs have to learn this thing and all its quirks before they can start doing work. An entire ecosystem eventually needs to exist to support its continued use, and if you have problems, you hope this ecosystem continues to flourish so you can get support for this unsupported language tool thing, or you'll be hiring internal devs to do it.

Maybe the problem is these start out as tools for developers, and only when they get used for operations do the anti-patterns surface. I've gone through it several times and it always ends up a PITA.

Re: Jsonnet – A data templating language

#49
We’ve been using jsonnet to combine Prometheus alerts and Grafana dashboards into little packages called monitoring Mixins: https://github.com/kubernetes-monitoring/kubernetes-mixin

A bunch more exist for things like Prometheus, consul, etc, vault, cluster, ceph, memcached etc

We’ve also built a super simple package manager for this called jsonnet-bundler (jb for short).

And of course we use jsonnet (with the ksonnet lib) at Grafana Labs for all our Kubernetes jobs.

Re: Jsonnet – A data templating language

#50

There's a real need for JSON templating languages not targeting developers. Tools like Zapier, Customer.io's webhooks, etc. allow integration with arbitrary APIs and have become a standard part of many marketing/sales stacks. These apps use things like Jinja, Mustache, or Liquid which are great for text but not JSON templates. Curly braces as primary delimiters, not allowing trailing commas on final elements, and oth…

What is it about "curly braces as primary delimiters" that you think is a hassle? What would you suggest instead?
Post reply on HN