Skip to content

Commit

Permalink
Update loki push path (#1049)
Browse files Browse the repository at this point in the history
This commit adds a /loki/api/v1/push endpoint to mirror the new v1 API,
and updates all references to the old push endpoint to new the one.
  • Loading branch information
joe-elliott authored and rfratto committed Sep 25, 2019
1 parent 7cb9538 commit 778c0b6
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions cmd/docker-driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The following command configure the container `grafana` to start with the loki d

```bash
docker run --log-driver=loki \
--log-opt loki-url="https://<user_id>:<password>@logs-us-west1.grafana.net/api/prom/push" \
--log-opt loki-url="https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push" \
--log-opt loki-retries=5 \
--log-opt loki-batch-size=400 \
grafana/grafana
Expand All @@ -68,7 +68,7 @@ The logging driver has configurable options, you can set them in the `daemon.jso
"debug" : true,
"log-driver": "loki",
"log-opts": {
"loki-url": "https://<user_id>:<password>@logs-us-west1.grafana.net/api/prom/push",
"loki-url": "https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push",
"loki-batch-size": "400"
}
}
Expand All @@ -90,7 +90,7 @@ services:
logging:
driver: loki
options:
loki-url: "https://<user_id>:<password>@logs-us-west1.grafana.net/api/prom/push"
loki-url: "https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push"
```
You can then deploy your stack using:
Expand Down
2 changes: 1 addition & 1 deletion cmd/promtail/promtail-docker-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ positions:
filename: /tmp/positions.yaml

clients:
- url: http://loki:3100/api/prom/push
- url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: system
Expand Down
2 changes: 1 addition & 1 deletion cmd/promtail/promtail-local-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ positions:
filename: /tmp/positions.yaml

clients:
- url: http://localhost:3100/api/prom/push
- url: http://localhost:3100/loki/api/v1/push

scrape_configs:
- job_name: system
Expand Down
2 changes: 1 addition & 1 deletion fluentd/fluent-plugin-grafana-loki/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ services:
## Configuration

### url
The url of the Loki server to send logs to. When sending data the publish path (`/api/prom/push`) will automatically be appended.
The url of the Loki server to send logs to. When sending data the publish path (`/loki/api/v1/push`) will automatically be appended.
By default the url is set to `https://logs-us-west1.grafana.net`, the url of the Grafana Labs preview (hosted Loki)[https://grafana.com/loki] service.

#### Proxy Support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path('lib', __dir__)

Gem::Specification.new do |spec|
spec.name = 'fluent-plugin-grafana-loki'
spec.version = '1.0.2'
spec.version = '1.1.0'
spec.authors = %w[woodsaj briangann]
spec.email = ['awoods@grafana.com', 'brian@grafana.com']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def write(chunk)
body = { 'streams': payload }

# add ingest path to loki url
uri = URI.parse(url + '/api/prom/push')
uri = URI.parse(url + '/loki/api/v1/push')

req = Net::HTTP::Post.new(
uri.request_uri
Expand Down
10 changes: 7 additions & 3 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ func (t *Loki) initDistributor() (err error) {
return
}

t.server.HTTP.Path("/ready").Handler(http.HandlerFunc(t.distributor.ReadinessHandler))
t.server.HTTP.Handle("/api/prom/push", middleware.Merge(
pushHandler := middleware.Merge(
t.httpAuthMiddleware,
).Wrap(http.HandlerFunc(t.distributor.PushHandler)))
).Wrap(http.HandlerFunc(t.distributor.PushHandler))

t.server.HTTP.Path("/ready").Handler(http.HandlerFunc(t.distributor.ReadinessHandler))

t.server.HTTP.Handle("/api/prom/push", pushHandler)
t.server.HTTP.Handle("/loki/api/v1/push", pushHandler)
return
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/promtail/promtail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestPromtail(t *testing.T) {
recMtx: sync.Mutex{},
t: t,
}
http.Handle("/api/prom/push", handler)
http.Handle("/loki/api/v1/push", handler)
defer func() {
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -526,7 +526,7 @@ func parsePromMetrics(t *testing.T, bytes []byte, contentType string, metricName

func buildTestConfig(t *testing.T, positionsFileName string, logDirName string) config.Config {
var clientURL flagext.URLValue
err := clientURL.Set("http://localhost:3100/api/prom/push")
err := clientURL.Set("http://localhost:3100/loki/api/v1/push")
if err != nil {
t.Fatal("Failed to parse client URL")
}
Expand Down
8 changes: 8 additions & 0 deletions production/ksonnet/loki/gateway.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
location ~ /api/prom/.* {
proxy_pass http://querier.%(namespace)s.svc.cluster.local$request_uri;
}
location = /loki/api/v1/push {
proxy_pass http://distributor.%(namespace)s.svc.cluster.local$request_uri;
}
location ~ /loki/api/.* {
proxy_pass http://querier.%(namespace)s.svc.cluster.local$request_uri;
}
}
}
||| % $._config,
Expand Down
4 changes: 2 additions & 2 deletions production/ksonnet/promtail/promtail.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ k + config + scrape_config {
promtail_config+:: {
local service_url(client) =
if std.objectHasAll(client, 'username') then
'%(scheme)s://%(username)s:%(password)s@%(hostname)s/api/prom/push' % client
'%(scheme)s://%(username)s:%(password)s@%(hostname)s/loki/api/v1/push' % client
else
'%(scheme)s://%(hostname)s/api/prom/push' % client,
'%(scheme)s://%(hostname)s/loki/api/v1/push' % client,

local client_config(client) = client + {
url: service_url(client),
Expand Down
2 changes: 1 addition & 1 deletion tools/promtail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ spec:
spec:
containers:
- args:
- -client.url=https://<instanceId>:<apiKey>@<instanceUrl>/api/prom/push
- -client.url=https://<instanceId>:<apiKey>@<instanceUrl>/loki/api/v1/push
- -config.file=/etc/promtail/promtail.yml
env:
- name: HOSTNAME
Expand Down

0 comments on commit 778c0b6

Please sign in to comment.