question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pushing logs to hosted Loki results in "no credentials provided" error.

See original GitHub issue

I use Grafana cloud which provides hosted Loki. The current setup logs to a file and Promtail push the logs to Loki. The Promtail configuration for Loki accepts a URL that has the username and password along with the URL. The format of the URL is: https://9xxx:<my_api_key>=@logs-prod-us-central1.grafana.net/api/prom/push. I was trying the appender to replace the promtail configuration. The appender configuration looks like:

<appender name="LOKI" class="com.github.loki4j.logback.LokiApacheHttpAppender">
    <encoder class="com.github.loki4j.logback.JsonEncoder">
        <label>
            <pattern>host=${HOSTNAME},level=%level</pattern>
            <pairSeparator>,</pairSeparator>
            <keyValueSeparator>=</keyValueSeparator>
            <nopex>true</nopex>
        </label>
        <staticLabels>false</staticLabels>
    </encoder>
    <url>https://9xxx:<my_api_key>=@logs-prod-us-central1.grafana.net/api/prom/push</url>
    <connectionTimeoutMs>30000</connectionTimeoutMs>
    <requestTimeoutMs>5000</requestTimeoutMs>
</appender>

I get this error with the above configuration:

12:45:02,845 |-ERROR in com.github.loki4j.logback.LokiApacheHttpAppender[LOKI] - Loki responded with non-success status 401 on Batch #2d7ce8a75e8 (13 records). Error: {"status": "error", "error": "no credentials provided"}

Does the appender support pushing logs to hosted Loki?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nehaevcommented, Jan 4, 2021

@deepu-james The final release is expected to be out within one or two weeks. Meanwhile you can try pre-release version 1.0.0-rc1. The configuration changed significantly, and I need to update docs before releasing the whole thing. But given the configuration you’ve provided in this issue, you can rewrite it as the following (omitting some defaults):

    <appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
        <http class="com.github.loki4j.logback.ApacheHttpSender">
            <url>https://logs-prod-us-central1.grafana.net/loki/api/v1</url>
            <auth>
                <username>your_username</username>
                <password>your_api_token</password>
            </auth>
        </http>
        <format>
            <label>
                <pattern>host=${HOSTNAME},level=%level</pattern>
            </label>
        </format>
    </appender>

If you encounter any issues, feel free to report!

1reaction
nehaevcommented, Dec 15, 2020

Thanks for reporting! I haven’t checked if appenders can push logs to Grafana Cloud. This could require some additional configs for HttpClient. I’ll investigate this and update the issue with the results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trailing / in storage_config.s3 results in ... - GitHub
Send some logs using /api/prom/push. Expected behavior. Trailing slash is detected and not used in object key generation, so no error occurs.
Read more >
Configuration | Grafana Loki documentation
The result is the value for every config object in the Loki config struct, which is very large… Many values will not be...
Read more >
Logging in Kubernetes with Loki and the PLG stack
Use the PLG (Promtail, Loki, Grafana) log stack to discover, transform, ... Promtail can attach labels to logs before pushing them to Loki....
Read more >
Loki Distributed with S3 backend - Timestamp and Grafana ...
For the loki I am able to figure out the issue. In the sample Loki configuration on the official website, it is mentioned...
Read more >
How To Deploy Grafana Loki and Save Data to MinIO
Install and configure Loki, Promtail, Grafana and MinIO to quickly get started working with log data.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found