-
Notifications
You must be signed in to change notification settings - Fork 635
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
Add support for RFC 2579 DateAndTime #322
Conversation
@@ -130,6 +137,8 @@ func metricType(t string) (string, bool) { | |||
return "IpAddr", true | |||
case "PhysAddress48", "DisplayString", "Float", "Double": | |||
return t, true | |||
case "DateAndTime": |
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.
Are you certain that's the only way to do datetime? Maybe call it RFC2579DateAndTime or something?
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.
This comes from the definition in the MIB/RFC.
DateAndTime ::= TEXTUAL-CONVENTION
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.
Ah, good.
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.
The textual convention is what we use for these, so this is fine.
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.
The readme needs an update for the new type
collector.go
Outdated
// No time zone included, assume UTC. | ||
tz = time.UTC | ||
case 11: | ||
// Extract the timezone from hte last 3 bytes. |
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.
the
collector.go
Outdated
return 0 | ||
} | ||
if err != nil { | ||
log.Debugf("unable to parse DateAndTime %q", v) |
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.
Can you log the error?
collector.go
Outdated
v = pdu.Value.([]byte) | ||
default: | ||
log.Debugf("invalid DateAndTime type %v", pduType) | ||
return 0 |
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.
Should we really be returning 0 here?
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.
I was debating how to do error handling here. The function that uses this, pduToSamples
, doesn't really have any error handling.
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.
We can either fail the scrape, or return nothing for this metric and log. Returning bad data is not a good option imho.
generator/tree.go
Outdated
@@ -115,6 +115,13 @@ func prepareTree(nodes *Node) map[string]*Node { | |||
} | |||
}) | |||
|
|||
// Convert RFC 2579 DateAndTime textual conversion to type. | |||
walkNode(nodes, func(n *Node) { |
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.
This and the previous two walks should really be combined
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.
I saw this, and was wondering why we did walkNode over more than once. I can refactor.
3459c18
to
e041e60
Compare
generator/README.md
Outdated
@@ -105,6 +105,7 @@ modules: | |||
# gauge: An integer with type gauge. | |||
# counter: An integer with type counter. | |||
# OctetString: A bit string, rendered as 0xff34. | |||
# DateAndTime: An RFC 2579 DateAndTime byte sequence. |
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.
I'd mention that UTC is presumed if the tz is missing.
e041e60
to
bd94ce9
Compare
You need unittests for both the collector and generator changes. |
d583f85
to
8a031d0
Compare
@brian-brazil Yup, tests were why I left it WIP. |
generator/FORMAT.md
Outdated
@@ -25,6 +26,10 @@ module_name: | |||
# as a label value on that gauge. | |||
|
|||
# A metric that's part of a table, and thus has labels. |
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.
This isn't part of a table. You don't need to change this file.
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.
I was thinking it would be worth having an example in the FORMAT file. Don't care either way.
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.
The format file is more the general structure, the various types are over in the readme.
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.
Got it, removed.
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.
The types used to be in here, but they got moved when the type override was added. I'd prefer not to having to maintain two lists of types, as it's more likely they'll get out of sync.
8a031d0
to
01e327b
Compare
Extract a UNIX timestamp from RFC 2579 DateAndTime textual conversions. * Add support to the generator. * Add support to the collector. * Update snmp.yml with new DateAndTime metrics. Signed-off-by: Ben Kochie <[email protected]>
Signed-off-by: Ben Kochie <[email protected]>
Signed-off-by: Ben Kochie <[email protected]>
Signed-off-by: Ben Kochie <[email protected]>
01e327b
to
64ccfdc
Compare
Extract a UNIX timestamp from RFC 2579 DateAndTime textual conversions.
Fixes: #321
Signed-off-by: Ben Kochie [email protected]