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

feat(inputs.opensearch_query): Add opensearch_query input plugin #12393

Merged
merged 45 commits into from
Feb 2, 2023

Conversation

NullOranje
Copy link
Contributor

Required for all PRs

This plugin queries endpoints to obtain metrics from data stored in an OpenSearch cluster. The code is largely an update of the existing inputs.elasticsearch_query plugin.

The library in that plugin is incompatible with OpenSearch (and, in fact, all Elastic clusters >= 7.0.0). To resolve the issue, I made the following changes:

Future work should look at removing the deprecated olivere/elastic library.

@telegraf-tiger telegraf-tiger bot added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Dec 13, 2022
Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Thanks for putting this up! I have two high-level concerns:

  1. why does this need to be a second plugin?
  2. most of this is copy and paste from inputs.elasticsearch_query. I'd rather not have this much duplication. how much of this could be handled with a config variable or if not abstracted into the common folder?

I have done a very quick first pass through the PR as well, I realize some of these things already exist in the current plugin, but I'd like to clean up anything new that comes in.


## OpenSearch Support

This plugins is tested against OpenSearch 2.4.0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to test this against 1.3 to ensure some backwards compat before we accept this in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add testing for this. I wasn't worried about it since the 1.3.x line is currently maintenance-only, and will be EOL December 31, 2023.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks - I know someone is going to try and ask if it is supported so I'd rather find out now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested it against 1.3.7, and it ran fine. I've add this container to the test suite.

plugins/inputs/opensearch_query/README.md Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/README.md Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/README.md Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query_test.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query_test.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/aggregation_query.go Outdated Show resolved Hide resolved
@powersj
Copy link
Contributor

powersj commented Dec 14, 2022

CircleCI Pipeline — Could not find a usable config.yml, you may have revoked the CircleCI OAuth app.

I recently had a chat with CircleCI about this error. It is usually due to you having a CirlceCI account with an expired GitHub oauth. To resolve this, you need to log back into CircleCI with your usename/password if that is how you log in or if you use GitHub log, re-create your oauth/relogin with github.

That should regenerate your token and then allow you to push a commit or close and reopen this PR and tests should run.

I know the error message doesn't line up, and I have suggested them changing that, but that is what causes this error. And we do need tests to run :)

@NullOranje
Copy link
Contributor Author

Thanks for putting this up! I have two high-level concerns:

1. why does this need to be a second plugin?

As I'm sure you're aware, Elasticsearch and Opensearch are divergent products. The existing plugin supports old versions of ES, and (1) I didn't want to break workflows for existing users, and (2) I wanted there to be a clean spot to capture the delta.

2. most of this is copy and paste from inputs.elasticsearch_query. I'd rather not have this much duplication. how much of this could be handled with a config variable or if not abstracted into the common folder?

The existing elasticsearch_query plugin doesn't support ES 7.10.2, which is what OpenSearch is based on. I used the olivere/elastic library for a quick win, since it already implements the structs for ES, but I would like to eventually move away from those, since the author has deprecated the library.

This submission was intended to be an in-kind update for OS. I have more updates I want to put forward, such as support for multi-field aggregations that aren't implemented in the existing elasticsearch_query plugin.

@powersj
Copy link
Contributor

powersj commented Dec 15, 2022

I used the olivere/elastic library for a quick win,

I appreciate this and I can understand how from your perspective this gives users what they need quickly. As a maintainer though, I now have to support two plugins that are nearly identical.

I recognize the possible need for a second plugin, see my comment in #11345, as well as the need to change the underlying client library, see #12099.

Ideally I would prefer us try to use the existing plugin and add an option for what version or interface we are connecting to as proposed in #12099 (this was for the elasticsearch input, but applies here as well). If that truly is not possible, then a new plugin using the supported library would be the next best option.

@NullOranje
Copy link
Contributor Author

Thanks for the links to the issues. I certainly understand the drive to not maintain two separate plugins, given their similarity. My thought on this, though, is that the similarity will diverge over time. Elastic already makes big API changes between major versions, and they've been especially hostile towards Opensearch, for obvious reasons.

I'm not sure what the best course of action here is. Looking at the opensearch-project/opensearch-go library again, I think I refactor to eliminate the need for olivere/elastic. The painful part of this is handling the output, which is where olivere excelled. Given the limited scope of the responses, it might not be too bad.

Would it make sense then to try and have two separate plugins? I know having an API selection option would be appealing, but given the ever increasing divergence, I think we'd eventually end up maintaining two plugins under one package anyway.

@powersj
Copy link
Contributor

powersj commented Dec 15, 2022

Would it make sense then to try and have two separate plugins? I know having an API selection option would be appealing, but given the ever increasing divergence, I think we'd eventually end up maintaining two plugins under one package anyway.

Given your comments about the diverging of the two products it does sound like having two plugins does make sense. I would still want to see it using the new, supported library though.

Thanks!

go.sum Show resolved Hide resolved
plugins/inputs/opensearch_query/README.md Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/README.md Outdated Show resolved Hide resolved
plugins/inputs/all/opensearch_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/aggregation_parser.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/aggregation_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/opensearch_query.go Outdated Show resolved Hide resolved
@NullOranje
Copy link
Contributor Author

Thanks for the feedback. I've left a couple questions in-line to hopefully tie up the loose ends on this PR.

Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

There are still a few comments open and I think the test here is not sufficient...

Comment on lines 661 to 669
err = o.Gather(&acc)
if (len(acc.Errors) > 0) && !tt.wantQueryResErr {
for _, err = range acc.Errors {
t.Errorf("OpensearchQuery.Gather() error: %v, wantQueryResErr %v", err, tt.wantQueryResErr)
}
return
}

require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm what if we tt.wantQueryResErr but do not get any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Easy. You rewrite the test to properly check.

(len(acc.Errors) > 0) != tt.wantQueryResErr should fix that

Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for your work to make this fly @NullOranje!

@srebhan srebhan requested a review from powersj February 1, 2023 17:02
@srebhan srebhan assigned powersj and unassigned srebhan Feb 1, 2023
@srebhan
Copy link
Contributor

srebhan commented Feb 1, 2023

@powersj there has been some significant changes, so please take a look again!

Co-authored-by: Sven Rebhan <36194019+srebhan@users.noreply.github.com>
Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Hi! We are almost there, just two questions hopefully easy :)

plugins/inputs/opensearch_query/opensearch_query.go Outdated Show resolved Hide resolved
plugins/inputs/opensearch_query/README.md Outdated Show resolved Hide resolved
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Feb 2, 2023

@powersj
Copy link
Contributor

powersj commented Feb 2, 2023

Thank you for driving this!

@powersj powersj merged commit d35bd06 into influxdata:master Feb 2, 2023
@NullOranje
Copy link
Contributor Author

My pleasure. Looking forward to putting it to use!

@srebhan srebhan added this to the v1.26.0 milestone Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants