Skip to content
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

Logically separate out parser to its own package for import of metric, event, and service check message parsing #2839

Conversation

schahal
Copy link

@schahal schahal commented Dec 31, 2018

What does this PR do?

Moves the parser logic into its own sub-dogstatsd package and makes the following functions exportable:

  • NextMessage(packet *[]byte) (message []byte)
  • ParseServiceCheckMessage(message []byte, defaultHostname string) (*metrics.ServiceCheck, error)
  • ParseEventMessage(message []byte, defaultHostname string) (*metrics.Event, error)
  • ParseMetricMessage(message []byte, namespace string, defaultHostname string) (*metrics.MetricSample, error)

...which are called by the dogstatsd server.

Motivation

Mainly, so we can call the parsing functions without having to pull in the server/listener weight. It can also be advantageous in the future should there be different implementations of the dogstatsd server: it'd be able to call the same underlying parsing funcs without duplicating code.

Also, the separation also seems cleaner/logical for hopefully improved maintainability.

Additional Notes

Please note, I did not update releasenotes (per contribution guidelines) as there is no change to the end-server, just code layout. In case I should, please let me know and I'll update the PR.

Go Test Results

server_test.go

[~/go/src/github.com/DataDog/datadog-agent/pkg/dogstatsd] $ go test
Error: Dogstatsd: error parsing metrics: invalid metric value for "daemon1:666:777|g"
Error: Dogstatsd: error parsing service check: invalid field number for "_sc|agen.down"
Error: Dogstatsd: error parsing event: Invalid event message format: empty 'title' or 'text' field
PASS
ok  	github.com/DataDog/datadog-agent/pkg/dogstatsd	0.365s

parser_test.go

[~/go/src/github.com/DataDog/datadog-agent/pkg/dogstatsd] $ cd parser/ && go test
PASS
ok  	github.com/DataDog/datadog-agent/pkg/dogstatsd/parser	0.008s

… metric, event, and service check message parsing
@schahal schahal requested a review from a team as a code owner December 31, 2018 14:31
@olivielpeau
Copy link
Member

Hi @schahal, thanks for opening this PR, and sorry we failed to respond earlier.

I see the related issue on telegraf has been closed, so I don't know if your PR is still something you'd want to see merged. In addition, a few things were refactored/moved in the dogstatsd package since you opened your PR so I don't think it'll be easy to rebase and update. So I'll go ahead and close your PR, but if this something you're still interested in feel free to follow up here, thanks!

@olivielpeau olivielpeau closed this Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants