-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Rule formatting tool. #21
Comments
…nation Support Protocol Buffer Message Decoding
👍 * 💯 |
Yep, that'd be great. Preserving comments is the biggest (and basically only) problem. And agreement on how to split expressions over multiple lines. |
Aren't we in the middle of adding this to promtool? |
Related: #1779 |
Use a protocol-relative URL to load Google Fonts
…r-promu Install promu package for OCP multistage builds
Some observations:
|
Our current YAML library doesn't do this, but is hoping to "soon". |
I'd like to include this in my gsoc proposal. @brian-brazil, can you link to the YAML library you're referring to? |
https://github.com/go-yaml/yaml, but I'd scope this to just the PromQL as this stands. |
@brian-brazil But since the PromQL from rules is always embedded in YAML files, it at least has to preserve YAML comments, right? Otherwise the tool wouldn't be very useful as nobody wants to lose their comments the benefit of formatting. |
That'd be nice, but we can get benefits without that. I'd rather also not depend on something with an unclear timeline for a gsoc project. |
Let's start with the PromQL part. The YAML part should be almost trivial once the library preserves comments and things like the |
Ok! |
v3 of the YAML library is out, which should allow for all of this. |
FYI perfectly readable rule in configuration
VS its garbage representation in the Web UI
|
@sylr I think you posted some other rule from the web UI. also @beorn7 I am starting to work on this issue. here's what it shows for me for your rule:
|
@geekodour Yes, I mixed up two rules. |
@haibeey There already has been some progress in that direction. When building such a formatter it probably would be best to start with what is already implemented here and add proper white space and comment handling. It would be also nice, when such features could be integrated with the upcoming PromQL language server. Inside the language server code a lot of the stuff that is needed to format YAML files is already implemented, and it might make sense to reuse some of it. |
alright! Thanks @slrtbtfs . i will start perusing the links shared ASAP . |
Can I take up this issue? Would love to implement this. |
It looks like @haibeey is already somehow planning working on this. |
@roidelapluie I have already implemented a part of it way before. It's just that I had not mentioned here. |
Is this formatting style acceptable? @codesome @juliusv @brian-brazil @beorn7 |
The final representation after formatting can be discussed and decided during the GSoC period (maybe even now if any maintainer wants to chime in, but I don't have the bandwidth to review it at the moment). I would suggest (to all GSoC aspirants) to focus on how would you achieve this. |
https://prometheus.io/docs/practices/rules/ uses the best practices. |
i wrote a rough prototype to preserve comments by augmenting the goyacc grammar rules a little. commit here haibeey@8855667 |
That doesn't look right, the operators aren't on their own line |
oh yes. that commit doesn't do formmating. it is just to preserve comments in promql expr after evaluation for printing. |
Putting the comments in the AST seems like a reasonable idea. I've left some comments about the implementation there. |
Please don't enforce:
over
|
Having grouping modifiers first is the best practice, and is already how we print it - it's very difficult to read non-trivial expressions otherwise. |
Yeah, I had strong opinions about this initially. At first Prometheus only supported I still don't like at all the exact formatting |
I think everyone is entitled to its own opinion about this, I personally find the "best practice" to be hideous, but, as all syntaxes are legal, please do not enforce one over the others. |
The whole point of a |
Yeah, |
As a side note, this is actively been sought after for the GSoC. @haibeey I see that you are also interested in GSoC. While I appreciate the upfront work that you have put now, I would appreciate some open discussions and design sharing, in the GSoC proposal or otherwise, for easier coordination of projects in GSoC :) |
Comment preserving is already supported very well in the new go-yamlv3 library. The implementation is so flawless that there is no loss of comments. Hence, we can keep preserving mechanism independent from the Prometheus code without any worries. |
alright. i guess it is time share my proposal draft GSoC proposal . Reviews would be appreciated before the final draft. Thanks |
@Harkishen-Singh There are two levels of comments: YAML comments and comments within a PromQL expression. #21 (comment) was talking about the PromQL ones (but YAML ones would be good to preserve as well). |
During evaluation of a PromQL expression is when the comments are removed. |
In relation to YAML comments, there's problems with v3 that's causing issues for Cortex so we should avoid further rollout of that until that's all resolved.
The web ui is the only place it's done. |
…ethod-in-new-postings-cloner Use `ExpandPostings()` in `NewPostingsCloner()`
Add generatorURL to Alert struct
…nt-version-2.6 [release-2.6] Added project component version
Like "gofmt" for Go, we ought to have a "promfmt" for Prometheus since we have a syntax tree. The idea being that the system produces uniform style that minimizes deviation and learning curve.
Update after we have totally moved to YAML rule files: In addition to formatting the PromQL expressions, we also want to format the YAML files to have a fixed structure, while preserving comments for both PromQL expressions and the YAML file.
The text was updated successfully, but these errors were encountered: