To migrate logs from Stackdriver (now part of Google Cloud Operations Suite) to Grafana Loki, there is no direct export feature available. Instead, you need to set up a log shipping pipeline that collects logs from your environment and forwards them to Loki.
Recommended approach
Use a log collector like Fluentd or Promtail running in your Kubernetes cluster or environment:
- Fluentd or Promtail collects logs from your Kubernetes nodes, containers, or other sources.
- Configure Fluentd with the loki output plugin or Promtail to send logs directly to your Loki instance.
- This approach bypasses Stackdriver as a source; instead, you collect logs directly from the source rather than exporting from Stackdriver.
Why this approach?
- Stackdriver does not currently support exporting logs directly to Loki.
- Exporting logs into Cloud Storage or Pub/Sub and then importing is complex and increases latency.
- Using Fluentd or Promtail leverages established log shipping techniques with native Loki support.
Steps overview
- Install Fluentd or Promtail using Kubernetes DaemonSet or on your nodes.
- Configure the log collector to read logs from standard sources (e.g., container stdout).
- Set the output to Loki's HTTP API or gRPC endpoint.
- Verify logs are appearing in Grafana Loki.
Additional tips
- Consider cost implications: Stackdriver charges for logs ingestion; collecting logs directly with Fluentd may be more cost-effective.
- Ensure proper log format for Loki (labels and fields) for efficient querying.
- Use Loki's documentation for Fluentd or Promtail configuration examples.
References