Conversation
glinton
left a comment
There was a problem hiding this comment.
Reviewing specifically for the plugin dev framework
| @@ -0,0 +1,106 @@ | |||
|
|
|||
There was a problem hiding this comment.
Slim this file down by removing comments and default values. See other example.
telegraf.conf
Outdated
| @@ -0,0 +1,104 @@ | |||
|
|
|||
There was a problem hiding this comment.
Remove this file entirely, no need to have a global telegraf.conf
| entrypoint: | ||
| - /telegraf | ||
| - --config | ||
| - /telegraf.conf No newline at end of file |
There was a problem hiding this comment.
Nitpick: add newline at the end of this and json_a.log
| ragel -Z -G2 $^ -o $@ | ||
|
|
||
| .PHONY: deps telegraf install test test-windows lint vet test-all package clean docker-image fmtcheck uint64 | ||
| static: |
There was a problem hiding this comment.
This may cause a merge conflict when we merge #4324 unless you merged that branch into yours.
There was a problem hiding this comment.
What I do when I need to have parts from another commit/branch is either cherry-pick that commit or make the change to the shared file, and just not commit the changes to that file from my new branch.
513ec70 to
7fa27f4
Compare
plugins/parsers/registry.go
Outdated
| return parser, err | ||
| } | ||
|
|
||
| func NewGrokParser(metricName string, |
There was a problem hiding this comment.
Similar to a comment on 4351, lets not export this function.
danielnelson
left a comment
There was a problem hiding this comment.
In addition to the comments, we should also update logparser to use the new grok parser internally.
internal/config/config.go
Outdated
| delete(tbl.Fields, "patterns") | ||
| delete(tbl.Fields, "custom_patterns") | ||
| delete(tbl.Fields, "custom_pattern_files") | ||
| delete(tbl.Fields, "timezone") |
There was a problem hiding this comment.
Since these all are at plugin level now, lets prefix them with grok_
plugins/inputs/reader/reader.go
Outdated
| ## Each data format has its own unique set of configuration options, read | ||
| ## more about them here: | ||
| ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md | ||
| data_format = "" |
There was a problem hiding this comment.
Use 2 space indention in the sample config, make sure to update the README as well. You can generate the config for the readme with telegraf -usage reader.
plugins/inputs/reader/reader.go
Outdated
| func (r *Reader) refreshFilePaths() { | ||
| var allFiles []string | ||
| for _, filepath := range r.Filepaths { | ||
| g, err := globpath.Compile(filepath) |
There was a problem hiding this comment.
I would compile only once and store the result on the Reader struct. Since we don't have a constructor function yet, I would probably check if the value on the struct is nil and if so compile.
There was a problem hiding this comment.
My thought was that if people want to specify a directory via some globpath, then this will check for any new files added there during runtime
plugins/inputs/reader/reader.go
Outdated
| for _, filepath := range r.Filepaths { | ||
| g, err := globpath.Compile(filepath) | ||
| if err != nil { | ||
| log.Printf("E! Error Glob %s failed to compile, %s", filepath, err) |
There was a problem hiding this comment.
This error should probably stop the input since it indicates a user error, if any glob fails return the error up and out of Gather.
plugins/inputs/reader/reader.go
Outdated
| func (r *Reader) readMetric(filename string) ([]telegraf.Metric, error) { | ||
| fileContents, err := ioutil.ReadFile(filename) | ||
| if err != nil { | ||
| log.Printf("E! File could not be opened: %v", filename) |
There was a problem hiding this comment.
Error should be along the lines of "File could not be read" for accuracy, but also this error should be returned instead of logged. In general it is not safe to do anything with the return value if an error occurs.
plugins/inputs/reader/reader.go
Outdated
| log.Printf("E! Metric could not be parsed from: %v, on line %v", k, i) | ||
| continue | ||
| } | ||
| acc.AddFields(m.Name(), m.Fields(), m.Tags()) |
There was a problem hiding this comment.
Also add the m.Time().
plugins/inputs/reader/reader_test.go
Outdated
| assert.Equal(t, 2, len(acc.Metrics)) | ||
| } | ||
|
|
||
| func getPluginDir() string { |
There was a problem hiding this comment.
I think the cwd is actually guaranteed by go test to be the directory containing the test file.
There was a problem hiding this comment.
Check if this is required and if not remove.
plugins/parsers/grok/influx-patterns
Outdated
| @@ -0,0 +1,73 @@ | |||
| # Captures are a slightly modified version of logstash "grok" patterns, with | |||
There was a problem hiding this comment.
I feel like I should know this, but... any idea why we need this file when we have influx_patterns.go?
There was a problem hiding this comment.
I wasn't sure if it was something relevant. I was under the impression that it was simply the text from influx_patterns.go. I think it can be removed.
There was a problem hiding this comment.
Go ahead and remove this.
| NamedPatterns []string | ||
| CustomPatterns string | ||
| CustomPatternFiles []string | ||
| Measurement string |
There was a problem hiding this comment.
Let's remove Measurement, we already have name_override which does the same thing.
| @@ -0,0 +1,19 @@ | |||
| package grok | |||
There was a problem hiding this comment.
Needs more tests, probably easiest to just bring over all tests from grok_test.go
| grok_custom_pattern_files = [] | ||
|
|
||
| ## Custom patterns can also be defined here. Put one pattern per line. | ||
| grok_custom_patterns = ''' |
There was a problem hiding this comment.
I think we need a closing ''' for this below.
| return err | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
It looks like we are removing l.parsers, I think this is good but also remove the reflect bit above 156:175 and the field from the LogParserPlugin struct.
plugins/inputs/reader/reader.go
Outdated
| ) | ||
|
|
||
| type Reader struct { | ||
| Filepaths []string `toml:"files"` |
There was a problem hiding this comment.
Call this Files, if its good enough for the config its good enough for the struct, and it will be less confusing.
plugins/inputs/reader/reader.go
Outdated
| FromBeginning bool | ||
| parser parsers.Parser | ||
|
|
||
| Filenames []string |
There was a problem hiding this comment.
Make this a unexported field with a lowercase letter, otherwise you can set this from the config file which is undesired.
plugins/inputs/reader/reader.go
Outdated
| for _, filepath := range r.Filepaths { | ||
| g, err := globpath.Compile(filepath) | ||
| if err != nil { | ||
| return fmt.Errorf("E! Error Glob: %v could not be compiled, %s", filepath, err) |
There was a problem hiding this comment.
Similar to my comment on the json parser, since this is an error don't include E! and try to shorten: could not compile glob %q: %v
plugins/parsers/grok/parser.go
Outdated
| } | ||
|
|
||
| func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) { | ||
| lines := strings.Split(string(buf), "\n") |
There was a problem hiding this comment.
Use bufio.Scanner so that line splitting will work on files with DOS line endings.
plugins/parsers/grok/parser.go
Outdated
| CustomPatterns string | ||
| CustomPatternFiles []string | ||
| Measurement string | ||
| MetricName string |
There was a problem hiding this comment.
Keep this named Measurement.
plugins/parsers/grok/influx-patterns
Outdated
| @@ -0,0 +1,73 @@ | |||
| # Captures are a slightly modified version of logstash "grok" patterns, with | |||
There was a problem hiding this comment.
Go ahead and remove this.
| "ignored_string": "hello, world!" | ||
| }, | ||
| "another_list": [4] | ||
| } No newline at end of file |
There was a problem hiding this comment.
Add end of line for this file, also fix the indention.
plugins/inputs/reader/reader_test.go
Outdated
| assert.Equal(t, 2, len(acc.Metrics)) | ||
| } | ||
|
|
||
| func getPluginDir() string { |
There was a problem hiding this comment.
Check if this is required and if not remove.
closes #3479
closes #3883
Required for all PRs: