UI Visualization Custom Metrics Provider

I’m currently attempting to setup a custom metrics provider, according to [this](https:///usr/local/bin/consul agent -config-file=/etc/consul/config.json -config-dir=/etc/consul/consul.d -pid-file=/var/run/consul/consul.pid ) documentation, the custom options to pass to the provider are entered in the metrics_provider_options_json option.

I have a json configuration instead of HCL (its easier to auto generate with my pipeline), when using a literal json object for the config in this manner, I get a go error as its apparently looking for a string, not a map which is what you get when you parse json in go without a struct (map[string]interface). If I provide an escaped json string, I get a parsing error.

Has anyone configured this option with a json configuration instead of hcl successfully? if so, what format does it truly expect metrics_provider_options_json to be in? I’m trying to avoid having one hcl configuration file and the rest be json.

Hi @reskin89, I quickly tested this by starting a agent with JSON config file containing ui_config.metrics_provider_options_json stanza, and I’m not able to reproduce these same errors.

Here’s the steps I followed.

  1. JSON encode the metrics provider options.

    $ cat <<EOF | jq '. | tostring'                
      "foo": "bar"
  2. Create an agent config file with the escaped JSON as the value of metrics_provider_options_json.

      "node_name": "test",
      "ui_config": {
        "enabled": true,
        "metrics_provider": "prometheus",
        "metrics_provider_options_json": "{\"foo\":\"bar\"}"
  3. Start the agent.

    $ consul agent -dev -config-file=config.json
     ==> Starting Consul agent...
           Version: '1.11.1'
           Node ID: '42550925-59d4-30d2-3513-8c689b50fc90'
         Node name: 'test'
        Datacenter: 'dc1' (Segment: '<all>')
            Server: true (Bootstrap: false)
       Client Addr: [] (HTTP: 8500, HTTPS: -1, gRPC: 8502, DNS: 8600)
      Cluster Addr: (LAN: 8301, WAN: 8302)
           Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false
     ==> Log data will now stream in as it occurs:

I realize this probably isn’t representative of your environment. Would you mind sharing what Consul version you attempted this with, and perhaps the steps one could follow to replicate the errors you’re seeing so that I can better assist?