Skip to content

Parse created timestamps from Prometheus Protobuf#12973

Merged
bwplotka merged 1 commit intoprometheus:mainfrom
ArthurSens:parse-created-timestamp
Oct 18, 2023
Merged

Parse created timestamps from Prometheus Protobuf#12973
bwplotka merged 1 commit intoprometheus:mainfrom
ArthurSens:parse-created-timestamp

Conversation

@ArthurSens
Copy link
Copy Markdown
Member

Another PR to make #12733 easier to review

This PR implements parsing created timestamps for the Prometheus Protobuf parser

Copy link
Copy Markdown
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Epic! One suggestion and LGTM! 💪🏽

return true
}

// CreatedTimestamp returns false because OpenMetricsParser does not support created timestamps.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// CreatedTimestamp returns false because OpenMetricsParser does not support created timestamps.
// CreatedTimestamp returns false because OpenMetricsParser does not support created timestamps (yet).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add quick issue about it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is: #12980

Comment on lines +352 to +366
var foundCT *types.Timestamp
switch p.mf.GetType() {
case dto.MetricType_COUNTER:
foundCT = p.mf.GetMetric()[p.metricPos].GetCounter().GetCreatedTimestamp()
case dto.MetricType_SUMMARY:
foundCT = p.mf.GetMetric()[p.metricPos].GetSummary().GetCreatedTimestamp()
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
foundCT = p.mf.GetMetric()[p.metricPos].GetHistogram().GetCreatedTimestamp()
default:
}
if foundCT == nil {
return false
}
*ct = *foundCT
return true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to write this so we don't have to define foundCT variable - perhaps it would be more readable?

Suggested change
var foundCT *types.Timestamp
switch p.mf.GetType() {
case dto.MetricType_COUNTER:
foundCT = p.mf.GetMetric()[p.metricPos].GetCounter().GetCreatedTimestamp()
case dto.MetricType_SUMMARY:
foundCT = p.mf.GetMetric()[p.metricPos].GetSummary().GetCreatedTimestamp()
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
foundCT = p.mf.GetMetric()[p.metricPos].GetHistogram().GetCreatedTimestamp()
default:
}
if foundCT == nil {
return false
}
*ct = *foundCT
return true
switch p.mf.GetType() {
case dto.MetricType_COUNTER:
*ct = p.mf.GetMetric()[p.metricPos].GetCounter().GetCreatedTimestamp()
case dto.MetricType_SUMMARY:
*ct = p.mf.GetMetric()[p.metricPos].GetSummary().GetCreatedTimestamp()
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
*ct = p.mf.GetMetric()[p.metricPos].GetHistogram().GetCreatedTimestamp()
}
return ct != nil

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried a few combinations without success :/

*ct = p.mf.GetMetric()[p.metricPos].GetCounter().GetCreatedTimestamp() doesn't compile with the error:

cannot use p.mf.GetMetric()[p.metricPos].GetCounter().GetCreatedTimestamp() (value of type *types.Timestamp) as types.Timestamp value in assignment

*ct = *p.mf.GetMetric()[p.metricPos].GetCounter().GetCreatedTimestamp() causes a nilpointer exception if the metric doesn't have a created timestamp set.

So far, with this extra variable was the only way I found to make it work 😕

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at how retrieving exemplars works in the protobuf parser, I don't think there are other alternatives. I can rename the variable foundCT to ctProto if you think that's more clear though!

Copy link
Copy Markdown
Member

@bwplotka bwplotka Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some pointer magic needed - it is possible I think, but let's merge simplified version then (not a biggie)

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
Copy link
Copy Markdown
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM

@bwplotka bwplotka merged commit ef8e6ae into prometheus:main Oct 18, 2023
@bboreham
Copy link
Copy Markdown
Member

Part of #6541

@ArthurSens ArthurSens deleted the parse-created-timestamp branch March 30, 2024 17:49
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.

3 participants