-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Update /loki/api/v1/push
to use the v1 json format
#1145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4134705
First pass adding v1 support to push
joe-elliott 01c42b6
Added tests
joe-elliott a0b9ab6
Updated docs
joe-elliott 766c069
Restore fluentd gemspec to previous endpoint and configuration
joe-elliott 1902d59
Added deprecated push endpoint docs
joe-elliott d75b971
Fixed linting errors
joe-elliott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package unmarshal | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/grafana/loki/pkg/logproto" | ||
) | ||
|
||
// DecodePushRequest directly decodes json to a logproto.PushRequest | ||
func DecodePushRequest(b io.Reader, r *logproto.PushRequest) error { | ||
return json.NewDecoder(b).Decode(r) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package unmarshal | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/loki/pkg/logproto" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// covers requests to /api/prom/push | ||
var pushTests = []struct { | ||
expected []*logproto.Stream | ||
actual string | ||
}{ | ||
{ | ||
[]*logproto.Stream{ | ||
{ | ||
Entries: []logproto.Entry{ | ||
{ | ||
Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:22.380001319Z"), | ||
Line: "super line", | ||
}, | ||
}, | ||
Labels: `{test="test"}`, | ||
}, | ||
}, | ||
`{ | ||
"streams":[ | ||
{ | ||
"labels":"{test=\"test\"}", | ||
"entries":[ | ||
{ | ||
"ts": "2019-09-13T18:32:22.380001319Z", | ||
"line": "super line" | ||
} | ||
] | ||
} | ||
] | ||
}`, | ||
}, | ||
} | ||
|
||
func Test_DecodePushRequest(t *testing.T) { | ||
|
||
for i, pushTest := range pushTests { | ||
var actual logproto.PushRequest | ||
closer := ioutil.NopCloser(strings.NewReader(pushTest.actual)) | ||
|
||
err := DecodePushRequest(closer, &actual) | ||
require.NoError(t, err) | ||
|
||
require.Equalf(t, pushTest.expected, actual.Streams, "Push Test %d failed", i) | ||
} | ||
} | ||
|
||
func mustParse(l string, t string) time.Time { | ||
ret, err := time.Parse(l, t) | ||
if err != nil { | ||
log.Fatalf("Failed to parse %s", t) | ||
} | ||
|
||
return ret | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package unmarshal | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/grafana/loki/pkg/loghttp" | ||
|
||
"github.com/grafana/loki/pkg/logproto" | ||
) | ||
|
||
// DecodePushRequest directly decodes json to a logproto.PushRequest | ||
func DecodePushRequest(b io.Reader, r *logproto.PushRequest) error { | ||
var request loghttp.PushRequest | ||
|
||
err := json.NewDecoder(b).Decode(&request) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
*r = NewPushRequest(request) | ||
|
||
return nil | ||
} | ||
|
||
// NewPushRequest constructs a logproto.PushRequest from a PushRequest | ||
func NewPushRequest(r loghttp.PushRequest) logproto.PushRequest { | ||
ret := logproto.PushRequest{ | ||
Streams: make([]*logproto.Stream, len(r.Streams)), | ||
} | ||
|
||
for i, s := range r.Streams { | ||
ret.Streams[i] = NewStream(s) | ||
} | ||
|
||
return ret | ||
} | ||
|
||
// NewStream constructs a logproto.Stream from a Stream | ||
func NewStream(s *loghttp.Stream) *logproto.Stream { | ||
ret := &logproto.Stream{ | ||
Entries: make([]logproto.Entry, len(s.Entries)), | ||
Labels: s.Labels.String(), | ||
} | ||
|
||
for i, e := range s.Entries { | ||
ret.Entries[i] = NewEntry(e) | ||
} | ||
|
||
return ret | ||
} | ||
|
||
// NewEntry constructs a logproto.Entry from a Entry | ||
func NewEntry(e loghttp.Entry) logproto.Entry { | ||
return logproto.Entry{ | ||
Timestamp: e.Timestamp, | ||
Line: e.Line, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package unmarshal | ||
|
||
import ( | ||
"io/ioutil" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/loki/pkg/logproto" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// covers requests to /loki/api/v1/push | ||
var pushTests = []struct { | ||
expected []*logproto.Stream | ||
actual string | ||
}{ | ||
{ | ||
[]*logproto.Stream{ | ||
{ | ||
Entries: []logproto.Entry{ | ||
{ | ||
Timestamp: time.Unix(0, 123456789012345), | ||
Line: "super line", | ||
}, | ||
}, | ||
Labels: `{test="test"}`, | ||
}, | ||
}, | ||
`{ | ||
"streams": [ | ||
{ | ||
"stream": { | ||
"test": "test" | ||
}, | ||
"values":[ | ||
[ "123456789012345", "super line" ] | ||
] | ||
} | ||
] | ||
}`, | ||
}, | ||
} | ||
|
||
func Test_DecodePushRequest(t *testing.T) { | ||
|
||
for i, pushTest := range pushTests { | ||
var actual logproto.PushRequest | ||
closer := ioutil.NopCloser(strings.NewReader(pushTest.actual)) | ||
|
||
err := DecodePushRequest(closer, &actual) | ||
require.NoError(t, err) | ||
|
||
require.Equalf(t, pushTest.expected, actual.Streams, "Push Test %d failed", i) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.