-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Gather aggregate per-line and per-tenant metrics for Drain patt…
…erns (#13368)
- Loading branch information
Showing
8 changed files
with
92 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,8 +1,35 @@ | ||
package drain | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
import ( | ||
"regexp" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const ( | ||
FormatLogfmt = "logfmt" | ||
FormatJSON = "json" | ||
FormatUnknown = "unknown" | ||
) | ||
|
||
var logfmtRegex = regexp.MustCompile("^(\\w+?=([^\"]\\S*?|\".+?\") )*?(\\w+?=([^\"]\\S*?|\".+?\"))+$") | ||
|
||
// DetectLogFormat guesses at how the logs are encoded based on some simple heuristics. | ||
// It only runs on the first log line when a new stream is created, so it could do some more complex parsing or regex. | ||
func DetectLogFormat(line string) string { | ||
if len(line) < 2 { | ||
return FormatUnknown | ||
} else if line[0] == '{' && line[len(line)-1] == '}' { | ||
return FormatJSON | ||
} else if logfmtRegex.MatchString(line) { | ||
return FormatLogfmt | ||
} | ||
return FormatUnknown | ||
} | ||
|
||
type Metrics struct { | ||
PatternsEvictedTotal prometheus.Counter | ||
PatternsDetectedTotal prometheus.Counter | ||
TokensPerLine prometheus.Observer | ||
StatePerLine prometheus.Observer | ||
} |
This file contains 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 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 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 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