Skip to content

yaml/parse check reports invalid Prometheus rule that seems valid #1572

@wbollock

Description

@wbollock

Hello! I believe the yaml/parse check is incorrectly identifying labels with integer values as invalid Prometheus rules. I've found Prometheus parses the integer label values just fine into a string.

pint version                                                                                                                                                                                                                            
0.75.0 (revision: 8d7858af608e8c6ebe991b1ca3c1513409970343)pint lint --min-severity=bug prometheus_recording_rules.yaml  
                                                                                                                                                          
level=INFO msg="Finding all rules to check" paths=["prometheus_recording_rules.yaml"]
level=INFO msg="Checking Prometheus rules" entries=56 workers=10 online=true
Fatal: This rule is not a valid Prometheus rule: `labels dc_id value must be a string, got integer instead`. (yaml/parse)

  ---> prometheus_recording_rules.yaml:9
 9 |       dc_id: 55
     ^^^ This rule is not a valid Prometheus rule: `labels dc_id value must be a string, got integer instead`.

level=INFO msg="Problems found" Fatal=1
level=ERROR msg="Execution completed with error(s)" err="found 1 problem(s) with severity Bug or higher"

However in practice, Prometheus parses the integer value into the label value:

datacenter_info{dc_id="55"}

I couldn't find any upstream docs on if a string is mandated though:

I tried tracking down the upstream code for the rule YAML parsing and got to around here:

I believe Pint's yaml parsing here is stricter than Prometheus'. We've been using this pattern with various Prometheus versions from 2 to 3+.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions