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

partial support expand #663

Closed
wants to merge 5 commits into from
Closed

Conversation

guidao
Copy link
Contributor

@guidao guidao commented Jan 11, 2022

Implement issue: #245

@Civil
Copy link
Member

Civil commented Jan 12, 2022

I guess as the title have "WIP" in the name it is considered to be work-in-progress (that means I won't review it in-depth).

One note, however. Current PR expect backend to have native expand handler. However I currently do not aware of any backend that implements that.

If you have your own custom backend, please consider implementing some sort of feature flags that would mark that backend implements that type of query. For example carbonapi_v3_pb have a support for Capability Message, so you should send a PR to protocols repo here adding there ExpandMsg support (also feel free to add specific data types to make it easier to use, of course if it's actually needed) and then in your PR bump a revision of protocols repo required and guard that handler with capability request (like how it's done for Victoria Metrics backend)

@Civil
Copy link
Member

Civil commented Jan 12, 2022

Alternatively it might be worth do a find request and post-process the response, if of course find message have enough data.

@guidao
Copy link
Contributor Author

guidao commented Jan 13, 2022

Thank you for your comments. I would like to implement this feature, but have some confusion and would like to ask for your help.

  1. The current pr implementation is copying most of the code of the Find function to implement a new Expand function, so I am using the MultiGlobRequest structure. So is reusing the MultiGlobRequest structure an acceptable or comparable way to do this? Or is it better to define a new similar structure?
  2. By default the find request does not get enough information, for example for the metrics (aaa.1.bbb.2 and aaa.2.bbb.3) aaa.*.bbb.* will return aaa.*.bbb.2 and aaa.*.bbb.3, it needs to return aaa.1.bbb.2 and aaa.2.bbb.3, maybe a new flag could be added to indicate whether it is Find or Expand?

@Civil
Copy link
Member

Civil commented Jan 13, 2022

structure an acceptable or comparable way to do this?

I guess in that case it is ok to use the same structure as for find.

By default the find request does not get enough information

In that case the most effective approach would be to implement that on a backend side and indeed use a different handler on a backend.

Generic approach here is also possible but it would be less effective, e.x. doing requests for each and every glob that you see and implement all that logic on carbonapi side.

Overall it might be easier to approach it from a backend side (I'm not sure what you are using - go-carbon or graphite-clickhouse or something else as a backend).

Once you have a working backend it will be easier to test your changes on carbonapi side.

@guidao guidao force-pushed the feature/expand branch 2 times, most recently from 89bbb4f to 8fc9584 Compare January 14, 2022 07:10
@guidao
Copy link
Contributor Author

guidao commented Jan 15, 2022

DeepSource execution failed, but it was not introduced by this pr. Should I fix it?

@guidao guidao changed the title WIP: partial support expand partial support expand Jan 17, 2022
@Civil
Copy link
Member

Civil commented Jan 18, 2022

About DeepSource - sometimes it provide false-positive (pointing to problems that were already there or ignoring exclusion of vendored dependencies). In that case you can leave it as-is.

However sometimes it detects something new - in that case it would be great if you'll be able to fix it before you mark the PR as ready (when it detects something new sometimes it shows all the problems that were there even in vendored deps, so unfortunately it's not very easy to read)

@guidao
Copy link
Contributor Author

guidao commented Jan 18, 2022

Got it. I will only fix the problem introduced by this pr in order to avoid too many changes.

@guidao
Copy link
Contributor Author

guidao commented Jan 19, 2022

@Civil This pr is ready, can you help to review it?

@Civil
Copy link
Member

Civil commented Jan 19, 2022

I will likely have some time reading it during the weekend and I'll try not to forget that I have it waiting for the review.

@guidao guidao closed this Mar 2, 2022
@deniszh
Copy link
Member

deniszh commented Jun 10, 2022

@guidao: Are you OK if I pick up your PR? If you have any updates - it would be great. Thanks!

@deniszh deniszh reopened this Jun 10, 2022
@@ -186,6 +186,36 @@
return &globs, stats, nil
}

func (c *ClientProtoV3Group) Expand(ctx context.Context, request *protov3.MultiGlobRequest) (*protov3.MultiGlobResponse, *types.Stats, merry.Error) {
logger := c.logger.With(zap.String("type", "expand"), zap.Strings("request", request.Metrics))

Check failure

Code scanning / CodeQL

Log entries created from user input

This log write receives unsanitized user input from [here](1).
@@ -255,6 +258,79 @@
return &r, stats, nil
}

func (c *GraphiteGroup) Expand(ctx context.Context, request *protov3.MultiGlobRequest) (*protov3.MultiGlobResponse, *types.Stats, merry.Error) {
logger := c.logger.With(zap.String("type", "expand"), zap.Strings("request", request.Metrics))

Check failure

Code scanning / CodeQL

Log entries created from user input

This log write receives unsanitized user input from [here](1).
@@ -494,6 +494,115 @@
return &r, stats, nil
}

func (c *PrometheusGroup) Expand(ctx context.Context, request *protov3.MultiGlobRequest) (*protov3.MultiGlobResponse, *types.Stats, merry.Error) {
logger := c.logger.With(zap.String("type", "expand"), zap.Strings("request", request.Metrics))

Check failure

Code scanning / CodeQL

Log entries created from user input

This log write receives unsanitized user input from [here](1).
@guidao
Copy link
Contributor Author

guidao commented Jun 13, 2022

@guidao: Are you OK if I pick up your PR? If you have any updates - it would be great. Thanks!

Please feel free to do so. We solved this problem using other means, so there is nothing new in this PR.

@deniszh
Copy link
Member

deniszh commented Dec 16, 2022

FYI here: IMO this approach is very flexible and gives ability to override expand in every backend but IMO it's a bit overkill, I'll create separate PR similar to bookingcom/carbonapi#449 - which will just implement separate encoder for expand results, but results will be collected by same call as find does. IMO that should be good enough implementation.

@Civil
Copy link
Member

Civil commented Dec 16, 2022

Thanks. Yeah, as it seems not a lot of people need it, it doesn't need to be especially efficient if that would take too much time to implement.

@deniszh
Copy link
Member

deniszh commented Dec 16, 2022

It has some usecases, like grafana/grafana#33694 - but not widely used, no.

@deniszh
Copy link
Member

deniszh commented Dec 22, 2022

Closed in the favor of #748

@deniszh deniszh closed this Dec 22, 2022
@guidao
Copy link
Contributor Author

guidao commented Dec 23, 2022

FYI here: IMO this approach is very flexible and gives ability to override expand in every backend but IMO it's a bit overkill, I'll create separate PR similar to bookingcom/carbonapi#449 - which will just implement separate encoder for expand results, but results will be collected by same call as find does. IMO that should be good enough implementation.

It's been a bit long and my memory is a bit fuzzy, I remember I also tried to implement Expend through the Find interface. But there was some semantics that could not be covered. Does it support expand(*.servers.*.cpu) in this way?

@deniszh
Copy link
Member

deniszh commented Dec 23, 2022

@guidao : well, in graphite-web it's implemented in exactly that way - just another wrapper around same results which find returns. Could you please elaborate why it should have different semantics and how exactly expand(*.servers.*.cpu) should be supported?

@deniszh
Copy link
Member

deniszh commented Dec 23, 2022

PS: you probably mean grafana/grafana#33694 ? I implemented having exact that use case in mind: find?query=*.servers.*.cpu will return cpu, expand?query=*.servers.*.cpu will return full names.

@guidao
Copy link
Contributor Author

guidao commented Dec 24, 2022

PS: you probably mean grafana/grafana#33694 ? I implemented having exact that use case in mind: find?query=*.servers.*.cpu will return cpu, expand?query=*.servers.*.cpu will return full names.

Good, I also think the new PR is better.

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.

None yet

3 participants