-
-
Notifications
You must be signed in to change notification settings - Fork 339
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
[Feature] Add Support for Historical Data Points #986
base: master
Are you sure you want to change the base?
[Feature] Add Support for Historical Data Points #986
Conversation
Initial implementation to support historical data points by having a new flag `addHistoricalMetrics` at the job config level
// Include the timestamp to avoid genuine duplicates!? At this point we have all the metrics to be exposed under the `/metrics` endpoint so | ||
// we aren't able to tell if some of the metrics are present because the `addHistoricalMetrics` is set to `true`!? | ||
metricKey := fmt.Sprintf("%s-%d-%d", *metric.Name, prom_model.LabelsToSignature(metric.Labels), metric.Timestamp.Unix()) |
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.
Is it safe to include the timestamp to remove "real" duplicates?
pkg/job/discovery.go
Outdated
previousIdx := -1 | ||
previousID := "" | ||
for _, metricDataResult := range data { | ||
idx := findGetMetricDataByID(getMetricDatas, *metricDataResult.ID) | ||
// TODO: This logic needs to be guarded by a feature flag! Also, remember to add compatibility in the client v2 | ||
if idx == -1 { | ||
logger.Warn("GetMetricData returned unknown metric ID", "metric_id", *metricDataResult.ID) | ||
if addHistoricalMetrics { | ||
// Use the previousIdx to make a copy | ||
if previousIdx != -1 && previousID == *metricDataResult.ID { | ||
// Create a new CloudwatchData object | ||
newData := *getMetricDatas[previousIdx] | ||
newData.GetMetricDataPoint = metricDataResult.Datapoint | ||
newData.GetMetricDataTimestamps = metricDataResult.Timestamp | ||
|
||
getMetricDatas = append(getMetricDatas, &newData) | ||
} else { | ||
logger.Warn("GetMetricData returned unknown metric ID", "metric_id", *metricDataResult.ID) | ||
} | ||
} else { | ||
logger.Warn("GetMetricData returned unknown metric ID", "metric_id", *metricDataResult.ID) | ||
} | ||
continue | ||
} | ||
getMetricDatas[idx].GetMetricDataPoint = metricDataResult.Datapoint | ||
getMetricDatas[idx].GetMetricDataTimestamps = metricDataResult.Timestamp | ||
getMetricDatas[idx].MetricID = nil // mark as processed | ||
previousIdx = idx | ||
previousID = *metricDataResult.ID |
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 is the first attempt but I'm not keen on using the "order" in which the data is retrieved to achieve this. I'm planning to go over this section again and use a hashmap/dictionary to make this logic independent from the order the getMetricDatas has (I believe timestamp descending if I recall correctly)
@@ -33,6 +33,7 @@ type JobLevelMetricFields struct { | |||
Delay int64 `yaml:"delay"` | |||
NilToZero *bool `yaml:"nilToZero"` | |||
AddCloudwatchTimestamp *bool `yaml:"addCloudwatchTimestamp"` | |||
AddHistoricalMetrics *bool `yaml:"addHistoricalMetrics"` |
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 new flag to allow this behaviour is only supported at the job level. I'll do some testing first but it might be a good idea to support it even at the metric level.
I'm planning to make more changes but marking this PR as ready for review to get early feedback |
Love the idea of it :) |
I'm using this from our environment. Works nice |
This would also drastically reduce costs for people who are currently looking to get metrics in a 1 minute resolution ( |
@ecktom no any issue yet. seems it works well. |
Apologies for the delays on this one. I'm planning to spend some time next weekend refreshing this with the latest from master. I hope the rebase is not too painful 😢 |
…oints_issue_985 # Conflicts: # pkg/clients/cloudwatch/client.go # pkg/clients/cloudwatch/v1/client.go # pkg/clients/cloudwatch/v2/client.go # pkg/clients/v2/cache_test.go # pkg/job/discovery.go # pkg/model/model.go
I completed the rebase locally a while back but I can see that there are more changes lol. Let's see if can get to a "safe" place this week 😭 |
@luismy would be highly appreciated if you can give it another shot. We also tried to get it rebased but were stuck in some segfaults which we couldn't get right |
👋 as the main person who's been driving a lot of the conflicts here I'm sorry @luismy. I honestly didn't realize this existed for so long but I'm "done" enough with the The latest refactors split a lot of
Let me know what you think and if you could use a hand with conflict resolution. |
Initial implementation to support historical data points by having a new flag
addHistoricalMetrics
at the job config levelRelated to #985
Pending tasks