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

How to set the redis password field when adding the datasource via the Grafana API? #273

Open
vgoklani opened this issue Sep 14, 2022 · 1 comment

Comments

@vgoklani
Copy link

vgoklani commented Sep 14, 2022

Hey there,

I'm trying to create a new datasource via the Grafana API for redis. When calling the API, the plugin gets created, but the password field is blank, and therefore the plugin can't connect to our redis instance. I'm able to fix this manually by logging in to the Grafana web app, and manually pasting in the password.... which is incredibly annoying :)

Here's how I'm creating the schema for redis. I've also included the schema for InfluxDB, which works correctly (i.e. the password is getting set when passed via the API)

influxdb_schema = {
    "name": "InfluxDB",
    "type": "influxdb",
    "typeName": "InfluxDB",
    "url": f'http://{os.environ["influxdb_host"]}:{os.environ["influxdb_port"]}',
    "access": "proxy",
    "database": "udp",
    "isDefault": True,
    "user": os.environ["influxdb_username"],
    "password": os.environ["influxdb_password"],
}

redis_schema = {
    "name": "Redis",
    "type": "redis-datasource",
    "typeName": "Redis",
    "url": f'redis://{os.environ["redis_host"]}:{os.environ["redis_port"]}',
    "access": "proxy",
    "database": "",
    "isDefault": False,
    "user": "",
    "password": os.environ["redis_password"],
}

I then just make the REST call:

response = self._session.post(url=f"https://{self._root_url}/grafana/api/datasources", data=json.dumps(schema),)

The password gets set for InfluxDB, but not for redis. Should I be using a different parameter for the redis_schema, is password not the correct parameter? And yes, the environment variables are all defined.

My redis instance is running via docker-compose:

redis0:
  restart: always
  image: redislabs/redistimeseries:latest
  ports:
    - "127.0.0.1:6379:6379"
  volumes:
    - ${OPT_DOCKER_DIRECTORY}/data/redis0:/data
  mem_limit: 32768m
  env_file:
    - ./environment
  container_name: redis0
  healthcheck:
    test: ["CMD", "redis-cli", "ping"]
    interval: 120s
    timeout: 5s
    retries: 3
    start_period: 15s
  command: ["redis-server", "--port 6379", "--appendonly yes", "--appendfsync everysec", "--appendfilename appendonly.aof", "--dbfilename redis.rdb", "--save 600 1 300 10 60 100", "--dir /data", "--protected-mode yes", "--bind 0.0.0.0", "--requirepass ${REDIS_PASSWORD}", "--loadmodule /usr/lib/redis/modules/redistimeseries.so", "RETENTION_POLICY 0", "DUPLICATE_POLICY SUM"]

Thanks!

@mikhail-vl
Copy link
Contributor

@vgoklani Redis's password is a part of the secureJsonData and should be set accordingly in the API request.

apiVersion: 1

datasources:
  - name: Redis
    type: redis-datasource
    access: proxy
    orgId: 1
    isDefault: true
    version: 1
    url: redis://host.docker.internal:6379
    jsonData:
      client: standalone
      poolSize: 5
      timeout: 10
      pingInterval: 0
      pipelineWindow: 0
    editable: true
    secureJsonData:
      password: $PASSWORD

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

No branches or pull requests

2 participants