Skip to content

Commit

Permalink
fix(promtail): Fix cri tags extra new lines. (#7997)
Browse files Browse the repository at this point in the history
  • Loading branch information
kavirajk authored Dec 23, 2022
1 parent 92fca94 commit d5b68c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [7804](https://github.com/grafana/loki/pull/7804) **sandeepsukhani**: Use grpc for communicating with compactor for query time filtering of data requested for deletion.
* [7817](https://github.com/grafana/loki/pull/7817) **kavirajk**: fix(memcached): panic on send on closed channel.
* [7916](https://github.com/grafana/loki/pull/7916) **ssncferreira**: Add `doc-generator` tool to generate configuration flags documentation.
* [7997](https://github.com/grafana/loki/pull/7997) **kavirajk**: fix(promtail): Fix cri tags extra new lines when joining partial lines

##### Fixes

Expand Down Expand Up @@ -53,7 +54,7 @@

#### Jsonnet

#### Build
#### Build

* [7938](https://github.com/grafana/loki/pull/7938) **ssncferreira**: Add DroneCI pipeline step to validate configuration flags documentation generation.

Expand Down
4 changes: 2 additions & 2 deletions clients/pkg/logentry/stages/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *cri) Run(entry chan Entry) chan Entry {
if len(c.partialLines) >= c.maxPartialLines {
// Merge existing partialLines
newPartialLine := e.Line
e.Line = strings.Join(c.partialLines, "\n")
e.Line = strings.Join(c.partialLines, "")
level.Warn(c.base.logger).Log("msg", "cri stage: partial lines upperbound exceeded. merging it to single line", "threshold", MaxPartialLinesSize)
c.partialLines = c.partialLines[:0]
c.partialLines = append(c.partialLines, newPartialLine)
Expand All @@ -73,7 +73,7 @@ func (c *cri) Run(entry chan Entry) chan Entry {
}
if len(c.partialLines) > 0 {
c.partialLines = append(c.partialLines, e.Line)
e.Line = strings.Join(c.partialLines, "\n")
e.Line = strings.Join(c.partialLines, "")
c.partialLines = c.partialLines[:0]
}
return e, false
Expand Down
33 changes: 8 additions & 25 deletions clients/pkg/logentry/stages/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,50 +107,33 @@ func TestCRI_tags(t *testing.T) {
{
name: "tag P",
lines: []string{
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 1",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 2",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 1 ",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 2 ",
"2019-05-07T18:57:55.904275087+00:00 stdout F log finished",
"2019-05-07T18:57:55.904275087+00:00 stdout F another full log",
},
expected: []string{
"partial line 1\npartial line 2\nlog finished",
"partial line 1 partial line 2 log finished",
"another full log",
},
},
{
name: "tag P exceeding MaxPartialLinesSize lines",
lines: []string{
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 1",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 2",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 1 ",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 2 ",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 3",
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 4", // this exceeds the `MaxPartialLinesSize` of 3
"2019-05-07T18:57:50.904275087+00:00 stdout P partial line 4 ", // this exceeds the `MaxPartialLinesSize` of 3
"2019-05-07T18:57:55.904275087+00:00 stdout F log finished",
"2019-05-07T18:57:55.904275087+00:00 stdout F another full log",
},
maxPartialLines: 3,
expected: []string{
"partial line 1\npartial line 2\npartial line 3",
"partial line 4\nlog finished",
"partial line 1 partial line 2 partial line 3",
"partial line 4 log finished",
"another full log",
},
},
{
name: "panic",
lines: []string{
"2019-05-07T18:57:50.904275087+00:00 stdout P panic: I'm pannicing",
"2019-05-07T18:57:50.904275087+00:00 stdout P ",
"2019-05-07T18:57:50.904275087+00:00 stdout P goroutine 1 [running]:",
"2019-05-07T18:57:55.904275087+00:00 stdout P main.main()",
"2019-05-07T18:57:55.904275087+00:00 stdout F /home/kavirajk/src/go-play/main.go:11 +0x27",
},
expected: []string{
`panic: I'm pannicing
goroutine 1 [running]:
main.main()
/home/kavirajk/src/go-play/main.go:11 +0x27`,
},
},
}

for _, tt := range cases {
Expand Down

0 comments on commit d5b68c0

Please sign in to comment.