Skip to content

TextParser: Tolerate trailing whitespace #33

Open

Description

@beorn7

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

Activity

  1. beorn7 commented on Sep 9, 2016

    @beorn7
    ContributorAuthor

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

  2. self-assigned this
    on Jan 5, 2017
  3. beorn7 commented on Aug 8, 2017

    @beorn7
    ContributorAuthor

    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.

  4. removed their assignment
    on Aug 8, 2017
  5. added 2 commits that reference this issue on Jul 22, 2018
  6. RalfJung commented on Dec 30, 2019

    @RalfJung

    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.

  7. brian-brazil commented on Dec 30, 2019

    @brian-brazil
    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.

  8. beorn7 commented on Jan 20, 2020

    @beorn7
    ContributorAuthor

    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.)

  9. brian-brazil commented on Jan 20, 2020

    @brian-brazil
    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.

  10. beorn7 commented on Jan 20, 2020

    @beorn7
    ContributorAuthor

    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.)

  11. brian-brazil commented on Jan 20, 2020

    @brian-brazil
    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.

  12. beorn7 commented on Jan 20, 2020

    @beorn7
    ContributorAuthor

    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).
  13. brian-brazil commented on Jan 20, 2020

    @brian-brazil
    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.

  14. beorn7 commented on Jan 20, 2020

    @beorn7
    ContributorAuthor

    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:

  15. brian-brazil commented on Jan 20, 2020

    @brian-brazil
    Contributor
  16. beorn7 commented on Jan 20, 2020

    @beorn7
    ContributorAuthor

    The Prometheus server currently tolerates trailing whitespace.

  17. brian-brazil commented on Jan 20, 2020

    @brian-brazil
    Contributor

    That is a problem then.

  18. RalfJung commented on Jan 20, 2020

    @RalfJung

    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.

  19. brian-brazil commented on Jan 20, 2020

    @brian-brazil
    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.

  20. roidelapluie commented on Jan 20, 2020

    @roidelapluie
    Member

    2.15 and master might differ on this.

  21. brian-brazil commented on Jan 20, 2020

    @brian-brazil
    Contributor

    Oh? Is this a recent regression?

  22. roidelapluie commented on Jan 20, 2020

    @roidelapluie
    Member

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

  23. beorn7 commented on Jan 20, 2020

    @beorn7
    ContributorAuthor

    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.

  24. aaaidan commented on Oct 17, 2021

    @aaaidan

    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.

  25. roidelapluie commented on Oct 17, 2021

    @roidelapluie
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions