grafana / loki

Like Prometheus, but for logs.
https://grafana.com/loki
GNU Affero General Public License v3.0
22.82k stars 3.32k forks source link

Adding JSON schema for configuration file #12083

Open alan910127 opened 4 months ago

alan910127 commented 4 months ago

Is your feature request related to a problem? Please describe.

Currently, the configurations for Grafana Loki are documented on the website and can also be accessed from the binary using the -help tag. However, as a newcomer, I find it is still challenging to navigate and be overwhelmed by the large number of configurations. It would be great if we could reach the documentation more easily and get instant feedback on incorrect configuration directly in text editors/IDEs.

Describe the solution you'd like

I propose adding a JSON schema for the configuration file on SchemaStore. With tools supporting LSP, users would be able to access hover information (documentation) and obtain configuration validation in real time. While Grafana Loki configurations are written in YAML format, the tools should be capable of validating YAML files with a JSON schema.

I am not sure whether the configuration documentation is generated or not, I think the JSON schema should be able to be generated from the Config structs, but since the descriptions are currently located in the RegisterFlags functions, minor changes are needed.

Describe alternatives you've considered

N/A

Additional context

I am willing to contribute to this. 😊

JStickler commented 4 months ago

FYI, the configuration documentation is partially generated. The source file can be found at /docs/sources/configure/_index.md and the text is generated from /docs/sources/configure/index.template. This was added in #7916, just in case that's helpful.

alan910127 commented 3 months ago

This was added in #7916, just in case that's helpful.

It looks great, thanks! I have some questions regarding the information needed to generate the JSON schema:

quantumsheep commented 2 months ago

Hey! I wanted a JSON Schema too. By tweaked the doc-generator, I made one https://github.com/SchemaStore/schemastore/pull/3743.

karlrwjohnson commented 1 month ago

For what it's worth, I've written a script to parse the docs page and output Typescript typedefs in case someone else is trying to use Typescript to configure Loki.

I'm generating it from the generated YAML docs since it spares me the effort of figuring out how to parse types from Go code.

The next natural step would be to publish an NPM @types package, but I don't anticipate getting around to that.