This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Kv parser #307
Closed
Closed
Kv parser #307
Changes from 15 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
bbc73f8
contribute key value parser from observiq
a6b45c2
document delimiter param
076fafd
make tidy
b87a269
Merge branch 'main' into kv-parser
8219978
rebase
eba64cd
tidy
22c34e2
Merge branch 'open-telemetry-main' into kv-parser
e00181d
tidy
8f00220
do not support bytes
5ee14c7
make pair delimiter a configuration option, default to whitespace
580ce6b
simplify tests and test new pair delimiter option
373286c
remove benchmark, not required
427d6ce
handle single quoted values
0857bf7
fail if delimiter and pair delimiter are identical
2c6ae2f
finish remaining test coverage
0b0f8bf
Give recombine timeout test a more margin for error (#355)
djaglowski 45c9011
Bump github.com/onsi/gomega from 1.17.0 to 1.18.0 in /internal/tools …
dependabot[bot] 7559b93
Change log level for missing file case (#357)
djaglowski 2a8dbeb
Bump k8s.io/client-go from 0.23.2 to 0.23.3 (#358)
dependabot[bot] d386a36
Bump github.com/onsi/gomega from 1.18.0 to 1.18.1 in /internal/tools …
dependabot[bot] 4cecafa
Bump go.opentelemetry.io/collector from 0.42.0 to 0.43.1 (#361)
dependabot[bot] f25b106
Bump github.com/golangci/golangci-lint in /internal/tools (#362)
dependabot[bot] f6a5ca2
Bump go.opentelemetry.io/collector from 0.43.1 to 0.44.0 (#365)
dependabot[bot] fcea3af
Remove agent.WithConfigFiles (#374)
djaglowski 3df09ff
file_input should not attempt to track lost files on windows (#366)
djaglowski 1f8bd51
Remove the Dockerfile (#381)
djaglowski 44270c1
Remove version package (#382)
djaglowski c929bb9
Bump go.uber.org/zap from 1.20.0 to 1.21.0 (#384)
dependabot[bot] e039b7c
Remove .dockerignore file (#385)
djaglowski 77b222e
Remove plugins (#377)
djaglowski a9f0162
Syslog input as wrapper (#376)
djaglowski fd0fe16
Make operator.Builder.Build return one operator (#386)
djaglowski 48d725b
Remove 'stanza_input' operator and related logger wrapper (#389)
djaglowski 43a325c
Remove notion of operator namespaces (#387)
djaglowski ee764be
Remove BuildContext (#393)
djaglowski 1cb0229
Merge agent package into pipeline package (#395)
djaglowski a60a77d
Tidy up operator testdata files (#398)
djaglowski 8453fbc
Remove 'builtin' directory layer in operator packages (#400)
djaglowski bc0b94b
Bump go.opentelemetry.io/collector from 0.44.0 to 0.45.0 (#407)
dependabot[bot] 8cb8712
Update changelog in preparation for release v0.25.0 (#402)
djaglowski 5e83f90
Update dependencies and related tooling (#409)
djaglowski b3e4572
change attributes (#401)
chaitanyaphalak 78eb238
Remove write_to setting (#412)
djaglowski c118cd6
change resources (#411)
chaitanyaphalak 312f08c
fix iteration (#413)
rockb1017 248eda3
Correctly parse timestamps from 1970 (#417)
djaglowski e99ae1f
Update changelog ahead of v0.26.0 release (#418)
djaglowski 07cef82
Bump github.com/securego/gosec/v2 in /internal/tools (#419)
dependabot[bot] 8bd9504
feat(operator/recombine): do not combine logs before first_entry matc…
sumo-drosiek 6dace5c
Bump go.opentelemetry.io/collector from 0.45.0 to 0.46.0 (#422)
dependabot[bot] 8064c5b
Update dependencies (#426)
djaglowski b3a8528
Add support for parsing multiline csv records (#425)
djaglowski 13688f4
Update changelog ahead of v0.27.0 release (#427)
djaglowski 48c8d7d
Update CHANGELOG.md (#432)
djaglowski e92a761
Remove unused tools (#435)
djaglowski 547e79e
Remove notion of a default timestamp (#436)
djaglowski f054b8f
Bump gonum to resolve iteration issue in Go 1.18 (#437)
djaglowski 3a4af2e
Revert version of syslog-go (#438)
djaglowski fd465dc
Bump github.com/stretchr/testify from 1.7.0 to 1.7.1 (#444)
dependabot[bot] a798d75
Bump github.com/golangci/golangci-lint in /internal/tools (#442)
dependabot[bot] b59ffe9
fix(helpers/multiline): fix force flushing with multiline (#434)
sumo-drosiek 5f623db
Fix typo in recombine operator docs (#452)
djaglowski ac38b6d
Remove '$' from field syntax (#364)
djaglowski 636ffc5
Update attribute names used by file_input, to match semantic conventi…
djaglowski 5774206
Remove restructure operator (#371)
djaglowski 28dd828
Remove metadata operator (#429)
djaglowski ecefbe3
Add ObservedTimestamp to entry (#370)
djaglowski 7bf6948
Add prefixes to many examples in documentation (#453)
djaglowski 90e31d9
Provide a dedicated mechanism for parsing logger name (#397)
djaglowski 104d1b9
Enforce maximum SD-NAME length of 32, per RFC5424 (#439)
djaglowski b3803d7
Update Changelog ahead of major set of breaking changes (#430)
djaglowski 97c3b23
tidy
7f8d2e7
newline
3af7827
remove default value for empty string. remove TODO, it is okay to rep…
585f1a0
doc feadback
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 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,178 @@ | ||
## `key_value_parser` operator | ||
|
||
The `key_value_parser` operator parses the string-type field selected by `parse_from` into key value pairs. All values are of type string. | ||
|
||
### Configuration Fields | ||
|
||
| Field | Default | Description | | ||
| --- | --- | --- | | ||
| `id` | `key_value_parser` | A unique identifier for the operator | | ||
| `delimiter` | `=` | The delimiter used for splitting a value into a key value pair | | ||
| `pair_delimiter` | | The delimiter used for seperating key value pairs, defaults to whitespace | | ||
| `output` | Next in pipeline | The connected operator(s) that will receive all outbound entries | | ||
| `parse_from` | $ | A [field](/docs/types/field.md) that indicates the field to be parsed into key value pairs | | ||
| `parse_to` | $ | A [field](/docs/types/field.md) that indicates the field to be parsed as into key value pairs | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The library technically still interprets |
||
| `preserve_to` | | Preserves the unparsed value at the specified [field](/docs/types/field.md) | | ||
| `on_error` | `send` | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md) | | ||
| `if` | | An [expression](/docs/types/expression.md) that, when set, will be evaluated to determine whether this operator should be used for the given entry. This allows you to do easy conditional parsing without branching logic with routers. | | ||
| `timestamp` | `nil` | An optional [timestamp](/docs/types/timestamp.md) block which will parse a timestamp field before passing the entry to the output operator | | ||
| `severity` | `nil` | An optional [severity](/docs/types/severity.md) block which will parse a severity field before passing the entry to the output operator | | ||
|
||
|
||
### Example Configurations | ||
|
||
#### Parse the field `message` into key value pairs | ||
|
||
Configuration: | ||
```yaml | ||
- type: key_value_parser | ||
parse_from: message | ||
``` | ||
|
||
<table> | ||
<tr><td> Input body </td> <td> Output body </td></tr> | ||
<tr> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "", | ||
"body": { | ||
"message": "name=stanza" | ||
} | ||
} | ||
``` | ||
|
||
</td> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "", | ||
"body": { | ||
"name": "stanza" | ||
} | ||
} | ||
``` | ||
|
||
</td> | ||
</tr> | ||
</table> | ||
|
||
#### Parse the field `message` into key value pairs, using a non default delimiter | ||
|
||
Configuration: | ||
```yaml | ||
- type: key_value_parser | ||
parse_from: message | ||
delimiter: ":" | ||
``` | ||
|
||
<table> | ||
<tr><td> Input body </td> <td> Output body </td></tr> | ||
<tr> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "", | ||
"body": { | ||
"message": "name:stanza" | ||
} | ||
} | ||
``` | ||
|
||
</td> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "", | ||
"body": { | ||
"name": "stanza" | ||
} | ||
} | ||
``` | ||
|
||
#### Parse the field `message` into key value pairs, using a non default pair delimiter | ||
|
||
Configuration: | ||
```yaml | ||
- type: key_value_parser | ||
parse_from: message | ||
pair_delimiter: "!" | ||
``` | ||
|
||
<table> | ||
<tr><td> Input body </td> <td> Output body </td></tr> | ||
<tr> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "", | ||
"body": { | ||
"message": "name=stanza ! org=otel ! group=dev" | ||
} | ||
} | ||
``` | ||
|
||
</td> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "", | ||
"body": { | ||
"name": "stanza", | ||
"org": "otel", | ||
"group": "dev" | ||
} | ||
} | ||
``` | ||
|
||
</td> | ||
</tr> | ||
</table> | ||
|
||
#### Parse the field `message` as key value pairs, and parse the timestamp | ||
|
||
Configuration: | ||
```yaml | ||
- type: key_value_parser | ||
parse_from: message | ||
timestamp: | ||
parse_from: seconds_since_epoch | ||
layout_type: epoch | ||
layout: s | ||
``` | ||
|
||
<table> | ||
<tr><td> Input body </td> <td> Output body </td></tr> | ||
<tr> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "", | ||
"body": { | ||
"message": "name=stanza seconds_since_epoch=1136214245" | ||
} | ||
} | ||
``` | ||
|
||
</td> | ||
<td> | ||
|
||
```json | ||
{ | ||
"timestamp": "2006-01-02T15:04:05-07:00", | ||
"body": { | ||
"name": "stanza" | ||
} | ||
} | ||
``` | ||
|
||
</td> | ||
</tr> | ||
</table> |
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package keyvalue | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/open-telemetry/opentelemetry-log-collection/entry" | ||
"github.com/open-telemetry/opentelemetry-log-collection/operator/helper" | ||
"github.com/open-telemetry/opentelemetry-log-collection/operator/helper/operatortest" | ||
) | ||
|
||
func TestKVParserConfig(t *testing.T) { | ||
cases := []operatortest.ConfigUnmarshalTest{ | ||
{ | ||
Name: "default", | ||
Expect: defaultCfg(), | ||
}, | ||
{ | ||
Name: "parse_from_simple", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
cfg.ParseFrom = entry.NewBodyField("from") | ||
return cfg | ||
}(), | ||
}, | ||
{ | ||
Name: "parse_to_simple", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
cfg.ParseTo = entry.NewBodyField("log") | ||
return cfg | ||
}(), | ||
}, | ||
{ | ||
Name: "on_error_drop", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
cfg.OnError = "drop" | ||
return cfg | ||
}(), | ||
}, | ||
{ | ||
Name: "timestamp", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
parseField := entry.NewBodyField("timestamp_field") | ||
newTime := helper.TimeParser{ | ||
LayoutType: "strptime", | ||
Layout: "%Y-%m-%d", | ||
ParseFrom: &parseField, | ||
} | ||
cfg.TimeParser = &newTime | ||
return cfg | ||
}(), | ||
}, | ||
{ | ||
Name: "severity", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
parseField := entry.NewBodyField("severity_field") | ||
severityField := helper.NewSeverityParserConfig() | ||
severityField.ParseFrom = &parseField | ||
mapping := map[interface{}]interface{}{ | ||
"critical": "5xx", | ||
"error": "4xx", | ||
"info": "3xx", | ||
"debug": "2xx", | ||
} | ||
severityField.Mapping = mapping | ||
cfg.SeverityParserConfig = &severityField | ||
return cfg | ||
}(), | ||
}, | ||
{ | ||
Name: "preserve_to", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
preserve := entry.NewBodyField("aField") | ||
cfg.PreserveTo = &preserve | ||
return cfg | ||
}(), | ||
}, | ||
{ | ||
Name: "delimiter", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
cfg.Delimiter = ";" | ||
return cfg | ||
}(), | ||
}, | ||
{ | ||
Name: "pair_delimiter", | ||
Expect: func() *KVParserConfig { | ||
cfg := defaultCfg() | ||
cfg.PairDelimiter = ";" | ||
return cfg | ||
}(), | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
tc.Run(t, defaultCfg()) | ||
}) | ||
} | ||
} | ||
|
||
func defaultCfg() *KVParserConfig { | ||
return NewKVParserConfig("key_value_parser") | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: To be consistent with other docs, can you add punctuation to the descriptions.