Logically separate out parser to its own package for import of metric, event, and service check message parsing #2839
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.
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
parser_test.go