Search code examples
docker-composegrafana-loki

How do I write a valid Vector Loki Configuration


I'm trying to write a vector.toml file for a loki sink but keep getting this error

ERROR vector::topology: Configuration error. error=Sink "loki": invalid format

If I leave out the labels block it complains that the section is required as indicated in the documentation.

Here is my vector.toml

# Set global options
data_dir = "/var/lib/vector"

# Vector's API (disabled by default)
# Enable and try it out with the `vector top` command
[api]
enabled = false
# address = ":8686"

[sources.docker]
type = "docker_logs"
docker_host = "unix:///var/run/docker.sock"

[sinks.loki]
type = "loki"
inputs = [ "docker" ] 
endpoint = "loki:3100" 
compression = "none"

  [sinks.loki.labels]
  forwarder = "vector"
  event = "{{ event_field }}"
  key = "value"
  "\"{{ event_field }}\"" = "{{ another_event_field }}"

  [sinks.loki.encoding]
  codec = "json"

Here is my docker-compose.yml

version: "3.9"

networks:
  appnet:
    external: true

services:
  vector:
    image: timberio/vector:nightly-debian
    container_name: vector
    hostname: vector
    restart: always
    environment: 
      - DOCKER_HOST="unix:///var/run/docker.sock"
    ports:
      - '8383:8383'
    volumes:
      - ./vector.toml:/etc/vector/vector.toml:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - appnet

edit: I made the changes suggested below but got these errors:

2022-06-07T09:40:00.995020Z ERROR vector::topology::builder: msg="Healthcheck: Failed Reason." error=A non-successful status returned: 503 Service Unavailable component_kind="sink" component_type="loki" component_id=loki component_name=loki 2022-06-07T09:46:47.105846Z WARN sink{component_kind="sink" component_id=loki component_type=loki component_name=loki}:request{request_id=83}: vector::sinks::util::retries: Retrying after error. error=Server responded with an error: 500 Internal Server Error 2022-06-07T09:46:47.225056Z INFO vector::internal_events::docker_logs: Stopped watching for container logs. container_id=721d72a4bc751721703828ff79e275e357f490445de51bc70781a5f0bbdd0a01 2022-06-07T09:46:48.111371Z ERROR sink{component_kind="sink" component_id=loki component_type=loki component_name=loki}:request{request_id=83}:http: vector::internal_events::http_client: HTTP error. error=error trying to connect: tcp connect error: Connection refused (os error 111) error_type="request_failed" stage="processing" 2022-06-07T09:46:48.111559Z WARN sink{component_kind="sink" component_id=loki component_type=loki component_name=loki}:request{request_id=83}: vector::sinks::util::retries: Retrying after error. error=Failed to make HTTP(S) request: Failed to make HTTP(S) request: error trying to connect: tcp connect error: Connection refused (os error 111)

Here is my loki docker-compose.yml config:

version: '2.4'

networks:
  appnet:
    external: true

volumes:
  loki_data:

services:
  loki:
    container_name: loki
    hostname: loki
    image: grafana/loki:latest
    restart: always
    networks:
      - appnet
    ports:
      - 3100:3100
    volumes:
      - type: bind
        source: /etc/localtime
        target: /etc/localtime
      - type: volume
        source: loki_data
        target: /data
      - type: bind
        source: ./config/s3-loki-bolt-conf.yml
        target: /etc/loki/local-config.yaml
    command: -config.file=/etc/loki/local-config.yaml
    mem_limit: 3g

Solution

  • It looks like it found loki: somewhere it was not expecting it. Having a look at your TOML and the Vector.dev reference (https://vector.dev/docs/reference/configuration/sinks/loki/),under [sinks.loki] I would try changing your endpoint from

    endpoint = "loki:3100"

    to:

    endpoint = "http://loki:3100"