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

TextParser: Tolerate trailing whitespace #33

Open
beorn7 opened this issue Mar 8, 2016 · 22 comments
Open

TextParser: Tolerate trailing whitespace #33

beorn7 opened this issue Mar 8, 2016 · 22 comments
Labels

Comments

@beorn7
Copy link
Member

beorn7 commented Mar 8, 2016

Apparently, trailing whitespace is not tolerated, see prometheus/prometheus#1469 .

@beorn7
Copy link
Member Author

beorn7 commented Sep 9, 2016

Depending on the decision on prometheus/docs#543, it might be alright to not tolerate trailing whitespace.

@beorn7 beorn7 self-assigned this Jan 5, 2017
@beorn7
Copy link
Member Author

beorn7 commented Aug 8, 2017

Un-assigning from myself as I intend to focus on other Prometheus project. Right now, others are way more involved in text format affairs than I am.

@beorn7 beorn7 removed their assignment Aug 8, 2017
gouthamve pushed a commit to gouthamve/common that referenced this issue Jul 22, 2018
b990f48 Merge pull request prometheus#42 from kinvolk/lorenzo/fix-git-diff
224a145 Check if SHA1 exists before calling `git diff`
1c3000d Add auto_apply config for wcloud
0ebf5c0 Fix wcloud -serivice
4fe078a Merge pull request prometheus#39 from weaveworks/fix-wrong-subtree-use
3f4934d Remove generate_latest_map
48beb60 Sync changes done directly in scope/tools
45dcdd5 Merge pull request prometheus#37 from weaveworks/fix-mflag-missing
b895344 Use mflag package from weaveworks fork until we find a better solution
e030008 Merge pull request prometheus#36 from weaveworks/wcloud-service-flags
9cbab40 Add wcloud Makefile
ef55901 Review feedback, and build wcloud in circle.
3fe92f5 Add wcloud deploy --service flag
3527b56 Merge pull request prometheus#34 from weaveworks/repo-branch
92cd0b8 [wcloud] Add support for repo_branch option
9f760ab Allow wcloud users to override username
38037f8 Merge pull request prometheus#33 from weaveworks/wcloud-templates
7acfbd7 Propagate the local username
e6876d1 Add template fields to wcloud config.
f1bb537 Merge pull request prometheus#30 from weaveworks/mike/shell-lint/dont-error-if-empty
e60f5df Merge pull request prometheus#31 from weaveworks/mike/fix-shell-lint-errors
e8e2b69 integrations: Fix a shellcheck linter error
a781575 shell-lint: Don't fail if no shell scripts found
db5efc0 Merge pull request prometheus#28 from weaveworks/mike/add-image-tag
5312c40 Import image-tag script into build tools so it can be shared
7e850f8 Fix logs path
dda9785 Update deploy api
f2f4e5b Fix the wcloud client
3925eb6 Merge pull request prometheus#27 from weaveworks/wcloud-events
77355b9 Lint
d9a1c6c Add wcloud events, update flags and error nicely when there is no config

git-subtree-dir: tools
git-subtree-split: b990f488bdc7909b62d9245bc4b4caf58f5ae7ea
gouthamve pushed a commit to gouthamve/common that referenced this issue Jul 22, 2018
…clearer

Use orgID and userID for the user context
@RalfJung
Copy link

I just ran into this. The error message with a trailing space is really confusing. It says text format parsing error in line 1: expected integer as timestamp, got \"\". But when you add a timestamp it says that's wrong, too.

@brian-brazil
Copy link
Contributor

I don't think we'll be making any changes here, if you use a client library it'll handle it for you plus OpenMetrics will supersede all this.

@beorn7
Copy link
Member Author

beorn7 commented Jan 20, 2020

I guess a typical scenario where to run into this is the textfile collector of the node exporter. That's where all kind of whitespace usage will be encountered because the textfile snippets are often created in a makeshift way. From that perspective, I see value in allowing trailing whitespace.

A different story is if and when the textfile collector will switch to OpenMetrics. If it does, we'd impose the strict whitespace requirement of OpenMetrics to all the creators of textfile snippets. (In principle, I'd love to let the textfile collector converge on OpenMetrics, too, but I'd also prefer OpenMetrics to be liberal with whitespace, which isn't going to happen.)

@brian-brazil
Copy link
Contributor

My thoughts are that changing the Prometheus text format this late in the game is unwise, anything that it currently does is now defacto the standard. Keep in mind that there are parsers other than the ones we maintain, and this would be a breaking change.

@beorn7
Copy link
Member Author

beorn7 commented Jan 20, 2020

We wouldn't change the creation code, we would only make the parser more tolerant. It doesn't have to be part of the standard, it's just following the https://en.wikipedia.org/wiki/Robustness_principle .

Obviously, it would be bad if we saw the parser as a test to certify standard compliance of Prometheus text format generators. I wouldn't see it that way, simply because the Prometheus text format is not a publicly advertised standard. (That would be OpenMetrics, for which those tests exist or will exist.)

@brian-brazil
Copy link
Contributor

Obviously, it would be bad if we saw the parser as a test to certify standard compliance of Prometheus text format generators

This code is the official parser. If it parses it, it's in compliance.

We wouldn't change the creation code, we would only make the parser more tolerant.

Thus that would be changing the standard.

it's just following the https://en.wikipedia.org/wiki/Robustness_principle

This turns out to be a bad idea, due to things like this.

I wouldn't see it that way, simply because the Prometheus text format is not a publicly advertised standard.

I don't see how that's relevant. We've always defined this code to be the reference implementation.

@beorn7
Copy link
Member Author

beorn7 commented Jan 20, 2020

I don't follow that line of argument. It all hinges on the premise that the parser is a compliance test and that the parser code defines the standard.

For better or worse, that was never standardized or advertized.

We are in a gray area here. I would like to navigate this ambiguity to the benefit of our users. In this case, allowing trailing whitespace is what most people will expect (as proved by multiple people that have run into this). We'll help all of them.

The counter case to bring up here is that somebody might have implemented a parser that doesn't tolerate trailing whitespace, too. If now somebody creates text format with trailing whitespace that then somehow makes it to that 3rd party parser, there will be a problem. That's a lot of If's:

  • A 3rd party parser has been implemented (reasonably likely), and it also rejects trailing whitespace (which is less likely – even our own intention was to accept trailing whitespace, it came as a surprise that we didn't, note that this issue is filed as a bug almost four years ago).
  • Then somebody creates Prometheus text format with trailing whitespaces (likely, that's the whole point of fixing this issue), which is then fed to a parser that accepts trailing whitespace, and then the same text snippet is fed to a parser that doesn't accept trailing whitespace (which should be extremely rare, it's not that there are many opportunities to pass around makeshift constructed Prometheus text format – the most prominent example is the textfile collector, but those snippets are always ever read by the textfile collector).

@brian-brazil
Copy link
Contributor

For better or worse, that was never standardized or advertized.

It's been stated multiple times over the years. For example if promtool (which uses this) parses your /metrics then it is valid.

It has always been the reference implementation.

The counter case to bring up here is that somebody might have implemented a parser that doesn't tolerate trailing whitespace, too.

This describes both the current version of this parser and the parser inside Prometheus.

Differing versions of Prometheus, the node exporter or pgw doing different things for what is nominally all the v0.0.4 format is not desirable behaviour. We might have gotten away with this a few years back, but today changing this would require defining a v0.0.5 - which I don't think we're going to do.

as proved by multiple people that have run into this

Also as far as I'm aware we've only ever had one report related to this, for a user who has (presumably) long resolved their issue. It seems a bit disproportionate to introduce such risk/complexity for a use case that effectively doesn't exist. It's not practical to change the format every time a user comes up with a new form of invalid input.

@beorn7
Copy link
Member Author

beorn7 commented Jan 20, 2020

Most people who run into this issue will probably realize after a while that they made a mistake. Very few will come here and complain. It is still surprising that no trailing whitespaces are accepted, which is made worse by the confusing error message. I would expect many brain cycles of humanity wasted on this.

If the Prometheus server rejected trailing whitespace, then fixing this issue would indeed also require changing Prometheus because I do think we should be consistent within the project, including the degree of tolerance our parsers apply. I'd see it as an argument to change neither the Prometheus server's behavior nor the text parser at this point.

But what if the Prometheus server accepted trailing whitespace? :philosoraptor:

@brian-brazil
Copy link
Contributor

brian-brazil commented Jan 20, 2020 via email

@beorn7
Copy link
Member Author

beorn7 commented Jan 20, 2020

The Prometheus server currently tolerates trailing whitespace.

@brian-brazil
Copy link
Contributor

That is a problem then.

@RalfJung
Copy link

Not accepting trailing whitespaces would not have been a big problem if the error message would not have said the exact opposite of what is actually the problem. That was the real problem.

@brian-brazil
Copy link
Contributor

The official parser and the Prometheus parser doing different things here is something that needs resolving, one way or the other. The Prometheus parser is wrong by the letter of the law, but this could be considered by some to be a breaking change.

Improving error messages is also good.

@roidelapluie
Copy link
Member

2.15 and master might differ on this.

@brian-brazil
Copy link
Contributor

Oh? Is this a recent regression?

@roidelapluie
Copy link
Member

mmh no. I was thinking that maybe the new parser was more strict about this. it is not.

@beorn7
Copy link
Member Author

beorn7 commented Jan 20, 2020

The Prometheus parser is wrong by the letter of the law

This is again based on the premise that the expfmt parser sets the standard. I already challenged that, so you could at least acknowledge that your understanding is not the common one.

IMHO, the letter of the law is https://prometheus.io/docs/instrumenting/exposition_formats/ . It says:

Within a line, tokens can be separated by any number of blanks and/or tabs (and must be separated by at least one if they would otherwise merge with the previous token). Leading and trailing whitespace is ignored.

That's crystal clear. The expfmt parser has a bug, and the prometheus/prometheus parser is right.

@aaaidan
Copy link

aaaidan commented Oct 17, 2021

Hello, just dropping in here to weigh in. I'm a newly minted prometheus user, though I'm have a fair bit of development experience.

Please, allow extra whitespace! 🙏 I'm glad the docs seem to come down on the right side of this.

The current behavior is confusing and discouraging. A format in this simple human-readable style sends a strong message that extra whitespace is ignored. At the moment, it's hard to figure it out that it's not.

I almost gave up on an exporter script because of this. I'm glad I pushed through. Not everyone will not have the time and energy to do so. This comment is the only reason I considered whitespace was my issue (thanks @beorn7!).

A friendly/helpful error message may be good low hanging fruit, but I'd love to see the underlying whitespace problem sorted. Hope this is useful, and let me know if I can help any other way.

@roidelapluie
Copy link
Member

Yes it's a bug because the docs say otherwise as implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants