Search code examples
oauth-2.0yamlprometheus

"Could not find expected ':' " error on Prometheus YAML file


I am trying to configure a YAML using oauth2.0 and I keep getting a "Could not find expected ':'" error on the line towards the end that says "scopes."

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    metrics_path: '/actuator/prometheus'
    #scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:8080"]

    oauth2:
      client_id: ''
      [ client_secret: '']
      scopes: 
        [ - '']
      token_url: ''
      #tls_config:

Solution

  • Your YAML is invalid.

    I find the Prometheus config documentation confusing to read.

    In this case, you're misreading [ ... ]. It's used to denote that something is optional in the documentation. The [ and ] should not be literally included in your YAML.

    Use a tool like yamllint to validate your YAML.

    So, try:

    global:
      scrape_interval: 15s
      evaluation_interval: 15s
    
    alerting:
      alertmanagers:
        - static_configs:
            - targets: []
    
    rule_files: []
    
    scrape_configs:
      - job_name: "prometheus"
        metrics_path: "/actuator/prometheus"
        static_configs:
          - targets: ["localhost:8080"]
        oauth2:
          client_id: ""
          client_secret: ""
          scopes: []
          token_url: ""
    

    Notes:

    • Per oauth2 you must have either client_secret or client_secret_file.
    • I removed your comments for clarity but comments (# ...) are fine.
    • I removed your commented out list elements and replaced them with empty lists ([]). You will likely need to fix those; you're probably going to need at least one scope, for example.
    • It's a good practice to be consistent in your use of " or ' to delimit strings; I've used " in the above.
    • There are 2 ways to represents list in YAML. The JSON way and the YAML way. Somewhat awkwardly, I think you must use the JSON way to represent an empty list ([]). Again, it's good to be consistent and stick with one. The following are equivalent:

    JSON-way:

    some-list: ["a","b","c"]
    

    YAML-way:

    some-list:
    - "a"
    - "b"
    - "c"