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

Query Sample Statistics #4708

Merged
merged 7 commits into from
Apr 7, 2022

Conversation

alanprot
Copy link
Member

@alanprot alanprot commented Apr 6, 2022

This PR brings the functionality implemented on prometheus/prometheus#10369 to cortex.

In order to do so, cortex now cache the per step statistics on the results cache and extract/merge to fulfill the request.

What this PR does:

Which issue(s) this PR fixes:
Bring prometheus feature implemented prometheus/prometheus#10369 to cortex.

Fixes partially: #4630

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@alanprot alanprot changed the title Feature/samples stats Query Samples Statistics Apr 6, 2022
@alanprot alanprot changed the title Query Samples Statistics Query Sample Statistics Apr 6, 2022
result.Samples.TotalQueryableSamples += output[key].Value
}

if !hasStats {
Copy link
Member

Choose a reason for hiding this comment

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

We can move this check right after the above for loop right?

@@ -380,6 +395,46 @@ func (s *SampleStream) MarshalJSON() ([]byte, error) {
return json.Marshal(stream)
}

// statsMerge merge the stats from 2 responses
Copy link
Member

Choose a reason for hiding this comment

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

It can merge more than 2 responses right?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

},
},
{
name: "[stats] Merging of samples where there is complete overlap.",
Copy link
Member

Choose a reason for hiding this comment

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

I think it will be good idea to add some test cases to show the merge function works with more than 2 series.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -92,6 +93,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.DurationVar(&cfg.QueryIngestersWithin, "querier.query-ingesters-within", 0, "Maximum lookback beyond which queries are not sent to ingester. 0 means all queries are sent to ingester.")
f.BoolVar(&cfg.QueryStoreForLabels, "querier.query-store-for-labels-enabled", false, "Query long-term store for series, label values and label names APIs. Works only with blocks engine.")
f.BoolVar(&cfg.AtModifierEnabled, "querier.at-modifier-enabled", false, "Enable the @ modifier in PromQL.")
f.BoolVar(&cfg.EnablePerStepStats, "querier.per-step-stats-enabled", false, "Enable returning samples stats per steps in PromQL.")
Copy link
Member

Choose a reason for hiding this comment

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

The description of the flag is a bit weird, the stats is not returned in PromQL, but PromQL response. Or maybe just "query response".

@alanprot alanprot merged commit 34a541f into cortexproject:master Apr 7, 2022
qinxx108 pushed a commit to qinxx108/cortex that referenced this pull request Apr 7, 2022
* Implementing stats on results_cache

* Fix TestResultsCacheRecent

* adding some comments

* Update Changelog

* Add test case with 3 responses

* address feedback

* Doc update

Signed-off-by: Yijie Qin <[email protected]>
alanprot pushed a commit that referenced this pull request May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants