Skip to content

Commit

Permalink
Revert "Updated stream json objects to be more parse friendly (#1010)"
Browse files Browse the repository at this point in the history
This reverts commit 6185d54
  • Loading branch information
slim-bean committed Sep 13, 2019
1 parent 6185d54 commit 7d3faff
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ lint:
########

test: all
GOGC=20 go test -p=6 ./...
go test -p=6 ./...

#########
# Clean #
Expand Down
122 changes: 80 additions & 42 deletions docs/loki/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The Loki server has the following API endpoints (_Note:_ Authentication is out of scope for this project):

- `POST /loki/api/v1/push`
- `POST /api/prom/push`

For sending log entries, expects a snappy compressed proto in the HTTP Body:

Expand All @@ -23,7 +23,7 @@ The Loki server has the following API endpoints (_Note:_ Authentication is out o

```

- `GET /loki/api/v1/query`
- `GET /api/v1/query`

For doing instant queries at a single point in time, accepts the following parameters in the query-string:

Expand Down Expand Up @@ -51,7 +51,7 @@ The Loki server has the following API endpoints (_Note:_ Authentication is out o
Examples:

```bash
$ curl -G -s "http://localhost:3100/loki/api/v1/query" --data-urlencode 'query=sum(rate({job="varlogs"}[10m])) by (level)' | jq
$ curl -G -s "http://localhost:3100/api/v1/query" --data-urlencode 'query=sum(rate({job="varlogs"}[10m])) by (level)' | jq
{
"status" : "success",
"data": {
Expand Down Expand Up @@ -88,31 +88,31 @@ The Loki server has the following API endpoints (_Note:_ Authentication is out o
```

```bash
curl -G -s "http://localhost:3100/loki/api/v1/query" --data-urlencode 'query={job="varlogs"}' | jq
curl -G -s "http://localhost:3100/api/v1/query" --data-urlencode 'query={job="varlogs"}' | jq
{
"resultType": "streams",
"result": [
{
"stream": {
"filename": "/var/hostlog/syslog",
"job": "varlogs"
},
"values": [
[
"1568234281726420425",
"foo"
],
[
"1568234269716526880",
"bar"
]
"status" : "success",
"data": {
"resultType": "streams",
"result": [
{
"labels": "{filename=\"/var/log/myproject.log\", job=\"varlogs\", level=\"info\"}",
"entries": [
{
"ts": "2019-06-06T19:25:41.972739Z",
"line": "foo"
},
{
"ts": "2019-06-06T19:25:41.972722Z",
"line": "bar"
}
]
}
]
}
]
}
```

- `GET /loki/api/v1/query_range`
- `GET /api/v1/query_range`

For doing queries over a range of time, accepts the following parameters in the query-string:

Expand Down Expand Up @@ -142,7 +142,7 @@ The Loki server has the following API endpoints (_Note:_ Authentication is out o
Examples:

```bash
$ curl -G -s "http://localhost:3100/loki/api/v1/query_range" --data-urlencode 'query=sum(rate({job="varlogs"}[10m])) by (level)' --data-urlencode 'step=300' | jq
$ curl -G -s "http://localhost:3100/api/v1/query_range" --data-urlencode 'query=sum(rate({job="varlogs"}[10m])) by (level)' --data-urlencode 'step=300' | jq
{
"status" : "success",
"data": {
Expand Down Expand Up @@ -192,31 +192,69 @@ The Loki server has the following API endpoints (_Note:_ Authentication is out o
```

```bash
curl -G -s "http://localhost:3100/loki/api/v1/query_range" --data-urlencode 'query={job="varlogs"}' | jq
curl -G -s "http://localhost:3100/api/v1/query_range" --data-urlencode 'query={job="varlogs"}' | jq
{
"resultType": "streams",
"result": [
{
"stream": {
"filename": "/var/hostlog/syslog",
"job": "varlogs"
},
"values": [
[
"1568234281726420425",
"foo"
],
[
"1568234269716526880",
"bar"
"status" : "success",
"data": {
"resultType": "streams",
"result": [
{
"labels": "{filename=\"/var/log/myproject.log\", job=\"varlogs\", level=\"info\"}",
"entries": [
{
"ts": "2019-06-06T19:25:41.972739Z",
"line": "foo"
},
{
"ts": "2019-06-06T19:25:41.972722Z",
"line": "bar"
}
]
}
]
}
}
```

- `GET /api/prom/query`

For doing queries, accepts the following parameters in the query-string:

- `query`: a [logQL query](../querying.md) (eg: `{name=~"mysql.+"}` or `{name=~"mysql.+"} |= "error"`)
- `limit`: max number of entries to return
- `start`: the start time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) or as RFC3339Nano (eg: "2006-01-02T15:04:05.999999999-07:00"). Default is always one hour ago.
- `end`: the end time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) or as RFC3339Nano (eg: "2006-01-02T15:04:05.999999999-07:00"). Default is current time.
- `direction`: `forward` or `backward`, useful when specifying a limit. Default is backward.
- `regexp`: a regex to filter the returned results

Loki needs to query the index store in order to find log streams for particular labels and the store is spread out by time,
so you need to specify the start and end labels accordingly. Querying a long time into the history will cause additional
load to the index server and make the query slower.

> This endpoint will be deprecated in the future you should use `api/v1/query_range` instead.
> You can only query for logs, it doesn't accept [queries returning metrics](../querying.md#counting-logs).
Responses looks like this:

```json
{
"streams": [
{
"labels": "{instance=\"...\", job=\"...\", namespace=\"...\"}",
"entries": [
{
"ts": "2018-06-27T05:20:28.699492635Z",
"line": "..."
},
...
]
}
},
...
]
}
```

- `GET /loki/api/v1/label`
- `GET /api/prom/label`

For doing label name queries, accepts the following parameters in the query-string:

Expand All @@ -235,7 +273,7 @@ The Loki server has the following API endpoints (_Note:_ Authentication is out o
}
```

- `GET /loki/api/v1/label/<name>/values`
- `GET /api/prom/label/<name>/values`

For doing label values queries, accepts the following parameters in the query-string:

Expand Down
35 changes: 0 additions & 35 deletions pkg/logproto/marshal.go

This file was deleted.

85 changes: 0 additions & 85 deletions pkg/logproto/marshal_test.go

This file was deleted.

4 changes: 0 additions & 4 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,9 @@ func (t *Loki) initDistributor() (err error) {
}

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

return
}

Expand Down

0 comments on commit 7d3faff

Please sign in to comment.