Skip to content

feat: adds support for group-by queries on the backend #1244

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

Merged
merged 3 commits into from
Jul 13, 2022
Merged

Conversation

petethepig
Copy link
Collaborator

@petethepig petethepig commented Jul 11, 2022

To test:

# to create data
curl -X POST --data 'foo;bar;baz 100' 'http://localhost:4040/ingest?name=0-app%7Bfoo%3D%22bar%22%7D'
curl -X POST --data 'foo;bar;baz 100' 'http://localhost:4040/ingest?name=0-app%7Bfoo%3D%22baz%22%7D'

# then to get the data
curl 'http://localhost:4040/render?from=now-1m&until=now&query=0-app&groupBy=foo&format=json' | jq .groups

@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2022

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
webapp/public/assets/app.js 480.86 KB (+0.01% 🔺) 9.7 s (+0.01% 🔺) 2 s (+3.72% 🔺) 11.7 s

@codecov
Copy link

codecov bot commented Jul 11, 2022

Codecov Report

Merging #1244 (45c8f3b) into main (1c5a9d2) will decrease coverage by 0.21%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #1244      +/-   ##
==========================================
- Coverage   69.87%   69.66%   -0.20%     
==========================================
  Files         104      110       +6     
  Lines        3401     3579     +178     
  Branches      893      953      +60     
==========================================
+ Hits         2376     2493     +117     
- Misses       1022     1083      +61     
  Partials        3        3              
Impacted Files Coverage Δ
webapp/javascript/services/render.ts 30.56% <0.00%> (ø)
...egraph/src/FlameGraph/FlameGraphComponent/color.ts 79.13% <0.00%> (-1.77%) ⬇️
packages/pyroscope-flamegraph/src/format/format.ts 68.43% <0.00%> (-1.04%) ⬇️
webapp/javascript/components/Sidebar.tsx 87.81% <0.00%> (-0.29%) ⬇️
webapp/javascript/ui/Sidebar.tsx 92.31% <0.00%> (-0.19%) ⬇️
...avascript/components/AppSelector/SelectorModal.tsx 88.24% <0.00%> (-0.13%) ⬇️
packages/pyroscope-models/src/index.ts 100.00% <0.00%> (ø)
webapp/javascript/ui/LoadingSpinner.tsx 100.00% <0.00%> (ø)
packages/pyroscope-models/src/profile.ts 91.67% <0.00%> (ø)
packages/pyroscope-models/src/flamebearer.ts 60.72% <0.00%> (ø)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c5a9d2...45c8f3b. Read the comment docs.

@Rperry2174
Copy link
Contributor

Rperry2174 commented Jul 12, 2022

also works with rideshare example:

curl 'http://localhost:4040/render?from=now-1m&until=now&query=ride-sharing-app.cpu%7B%7D&groupBy=region&format=json'  | jq .groups

fyi it didn't work for me without a time range not sure if thats intentional or not

nvm makes sense since its render endpoint

@petethepig petethepig requested review from kolesnikovae and eh-am and removed request for kolesnikovae July 12, 2022 08:07
Comment on lines +24 to +25
// TODO: make this a part of the query
GroupBy string
Copy link
Collaborator

@kolesnikovae kolesnikovae Jul 12, 2022

Choose a reason for hiding this comment

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

Maybe we should make this a slice, like in the most of query languages. I anticipate that many users will find this useful. Another very handy operator is without, which makes query engine to ignore the specified labels. I'm not sure if we need this (and, especially, in the first version), just a note.

Also, I wonder if we're still going to maintain similarity to PromQL. I think that it may make sense to go our own way. Otherwise, we should follow their semantics (e.g there group by is an aggregation operator and does slightly different things).

Copy link
Collaborator Author

@petethepig petethepig Jul 12, 2022

Choose a reason for hiding this comment

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

Good points. Will make it a slice in the future, it should be backward-compatible with the HTTP API (e.g groupBy=foo,bar. Same with without, (e.g groupBy=!foo).

Eventually we might add it to flameQL too. I think it's too early for these decisions tho. At this point my goal with this current design is to make it so that we can add all these additional features in the future, but not to actually add them.

@@ -39,6 +39,7 @@ export async function renderSingle(
z.object({ timeline: TimelineSchema })
)
.merge(z.object({ telemetry: z.object({}).passthrough().optional() }))
.merge(z.object({ groups: z.object({}) }))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be optional no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that's a good question. I'm not super sure. I made backend always return something for groups. Is there some other considerations I should be aware of? E.g is this relevant for flamegraph.com?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not relevant for flamegraph.com, it only runs here/cloud.

@@ -108,7 +112,16 @@ func (s *Storage) Get(ctx context.Context, gi *GetInput) (*GetOutput, error) {
aggregationType = averageAggregationType
}

timelineKey := "*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does a * group mean?

Copy link
Collaborator Author

@petethepig petethepig Jul 12, 2022

Choose a reason for hiding this comment

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

It's for the case when there's no value for a certain key:value pair. E.g if somebody ingested data at app{foo="bar"}, and you're grouping by baz. in this example baz is empty, so the data written to app{foo="bar"} becomes *.

When data is present, e.g when data is written to app{baz="bazz"}, it goes into bazz bucket.

Ideally we should come up with something better than * I think.

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.

4 participants