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

Adding JSON schema for configuration file #12083

Open
alan910127 opened this issue Feb 28, 2024 · 4 comments
Open

Adding JSON schema for configuration file #12083

alan910127 opened this issue Feb 28, 2024 · 4 comments
Labels
type/feature Something new we should do

Comments

@alan910127
Copy link

alan910127 commented Feb 28, 2024

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 JStickler added the type/feature Something new we should do label Mar 11, 2024
@JStickler
Copy link
Contributor

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
Copy link
Author

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:

  • SchemaStore can either host schemas in their repository or link to self-hosted schemas, and I believe that self-hosting the schema in the Loki repository would be a better fit since it can be updated effortlessly. If so, where should the schema be generated?
  • According to JSON Schema Spec, it supports a list of more fine-grained validation rules such as regex patterns, enums, or min/max lengths/values, which are currently described with usage strings in the RegisterFlags functions. To make a more precise JSON schema, it might need some level of refactoring in the Config structs.

@quantumsheep
Copy link

quantumsheep commented Apr 27, 2024

Hey! I wanted a JSON Schema too. By tweaked the doc-generator, I made one SchemaStore/schemastore#3743.

@karlrwjohnson
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Something new we should do
Projects
None yet
Development

No branches or pull requests

4 participants