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

Add InfluxDB v2 support #3669

Merged

Conversation

raminqaf
Copy link
Contributor

@raminqaf raminqaf commented Jan 7, 2021

This PR fixes #3670

Every item on this list will require judgement by the Testcontainers core maintainers. Exceptions will sometimes be possible; items with should are more likely to be negotiable than those items with must.

Default docker image

  • Should be a Docker Hub official image, or published by a reputable source (ideally the company or organisation that officially supports the technology)
  • Should have a verifiable open source Dockerfile and a way to view the history of changes
  • MUST show general good practices regarding container image tagging - e.g. we do not use latest tags, and we do not use tags that may be mutated in the future
  • MUST be legal for Testcontainers developers and Testcontainers users to pull and use. Mechanisms exist to allow EULA acceptance to be signalled, but images that can be used without a licence are greatly preferred.

Module dependencies

  • The module should use as few dependencies as possible,
  • Regarding libraries, either:
    • they should be compileOnly if they are likely to already be on the classpath for users' tests (e.g. client libraries or drivers)
    • they can be implementation (and thus transitive dependencies) if they are very unlikely to conflict with users' dependencies.
  • If client libraries are used to test or use the module, these MUST be legal for Testcontainers developers and Testcontainers users to download and use.

API (e.g. MyModuleContainer class)

  • Favour doing the right thing, and least surprising thing, by default
  • Ensure that method and parameter names are easy to understand. Many users will ignore documentation, so IDE-based substitutes (autocompletion and Javadocs) should be intuitive.
  • The module's public API should only handle standard JDK data types and MUST not expose data types that come from compileOnly dependencies. This is to reduce the risk of compatibility problems with future versions of third party libraries.

Documentation

  • Every module MUST have a dedicated documentation page containing:
    • A high level overview
    • A usage example
    • If appropriate, basic API documentation or further usage guidelines
    • Dependency information
    • Acknowledgements, if appropriate
  • Consider that many users will not read the documentation pages - even if the first person to add it to a project does, people reading/updating the code in the future may not. Try and avoid the need for critical knowledge that is only present in documentation.

@rnorth
Copy link
Member

rnorth commented Jan 10, 2021

Thanks for the contribution @raminqaf

I think one thing we need to be really careful about is the breaking-change nature of this. Is there no way at all to make the InfluxDBContainer be compatible with both v1.x and v2.x of InfluxDB?

We need to avoid a situation where an upgrade of Testcontainers prevents people from being able to run their existing tests that rely on InfluxDB v1.x.

@raminqaf
Copy link
Contributor Author

@rnorth unfortunately not. Another way to add support for InfluxDB 2.x and keep the 1.x supported is to add a new and sperated module like influxDB2.

@rnorth
Copy link
Member

rnorth commented Jan 10, 2021

What if we kept it in the same module, but have a InfluxDBContainerV2 class? We could also rename the current class to InfluxDBContainerV1 and have a @Deprecated class InfluxDBContainer extends InfluxDBContainerV1 to maintain binary compatibility.

@raminqaf
Copy link
Contributor Author

@rnorth Sounds good to me! I will add your suggestions and push them to the PR.

@raminqaf
Copy link
Contributor Author

@rnorth any updates on this PR?

@vcvitaly
Copy link
Contributor

I had a quick read and everything is ok at the first glance 👀

@raminqaf
Copy link
Contributor Author

@vektory79 Thanks!
Would be could if we could merge this. Since we are using the code in our project. I would like to have it from testcontainers dependency, rather than having it in our project directly 😉 @rnorth @kiview @bsideup

@gjemp
Copy link

gjemp commented Mar 23, 2021

hi,
some updates should be done

influxdbV2ClientVersion = '1.14.0'

there is 2.0.0 out.

the example about v2 is a bit missleading i think cause the default for pure v2 s now token based . The user and password is only for the v1=>v2 upgraded instances.

@raminqaf
Copy link
Contributor Author

raminqaf commented Mar 28, 2021

hi,
some updates should be done

influxdbV2ClientVersion = '1.14.0'

there is 2.0.0 out.

the example about v2 is a bit missleading i think cause the default for pure v2 s now token based . The user and password is only for the v1=>v2 upgraded instances.

Thanks for the comment and your feedback on the PR. By the time I created this PR the version was 1.14.0 but I will update it to the newest one. The authentication and setup of the InfluxDB could be done either through username and password or through the token. As you can see on the InfluxDB Docker setup page. And according to the setup flags documentation the username and password are still valid arguments to do the authentication. Besides you can use these credentials to log in, during debug mode, to the dashboard and query the data.

@gjemp
Copy link

gjemp commented Mar 29, 2021

Thanks for the comment and your feedback on the PR. By the time I created this PR the version was 1.14.0 but I will update it to the newest one. The authentication and setup of the InfluxDB could be done either through username and password or through the token. As you can see on the InfluxDB Docker setup page. And according to the setup flags documentation the username and password are still valid arguments to do the authentication. Besides you can use these credentials to log in, during debug mode, to the dashboard and query the data.

Thanks for update. Any idea when we get the review done ? Would really like to have the update as release.

@raminqaf
Copy link
Contributor Author

Thanks for the comment and your feedback on the PR. By the time I created this PR the version was 1.14.0 but I will update it to the newest one. The authentication and setup of the InfluxDB could be done either through username and password or through the token. As you can see on the InfluxDB Docker setup page. And according to the setup flags documentation the username and password are still valid arguments to do the authentication. Besides you can use these credentials to log in, during debug mode, to the dashboard and query the data.

Thanks for update. Any idea when we get the review done ? Would really like to have the update as release.

Unfortunately not. In order to merge the PR, one of the three reviewers (@rnorth @bsideup @bsideup) should approved the PR first.

@raminqaf raminqaf requested review from kiview and removed request for kiview August 23, 2022 14:15
@raminqaf
Copy link
Contributor Author

raminqaf commented Sep 9, 2022

@kiview Is this good to merge?

Copy link
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

@raminqaf thanks once again! I just noticed some important changes that we should address before merge.

Comment on lines 65 to 73
try (
final InfluxDBContainer influxDBContainer = new InfluxDBContainer(InfluxDBTestUtils.INFLUXDB_V2_TEST_IMAGE)
) {
influxDBContainer
.withUsername(USERNAME)
.withPassword(PASSWORD)
.withOrganization(ORG)
.withBucket(BUCKET)
.withRetention(RETENTION);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try (
final InfluxDBContainer influxDBContainer = new InfluxDBContainer(InfluxDBTestUtils.INFLUXDB_V2_TEST_IMAGE)
) {
influxDBContainer
.withUsername(USERNAME)
.withPassword(PASSWORD)
.withOrganization(ORG)
.withBucket(BUCKET)
.withRetention(RETENTION);
try (
final InfluxDBContainer influxDBContainer = new InfluxDBContainer(InfluxDBTestUtils.INFLUXDB_V2_TEST_IMAGE)
.withUsername(USERNAME)
.withPassword(PASSWORD)
.withOrganization(ORG)
.withBucket(BUCKET)
.withRetention(RETENTION);
) {

In the following example you will find a snippet to create an InfluxDB client using the official Java client:

<!--codeinclude-->
[InfluxDBTestUtils.getInfluxDBClient()](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java)
Copy link
Member

Choose a reason for hiding this comment

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

same here about use the code that is required

Running a `InfluxDBContainer` as a stand-in for InfluxDB in a test:

<!--codeinclude-->
[InfluxDBContainerV1Test](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java)
Copy link
Member

Choose a reason for hiding this comment

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

same here about use the code that is required

In the following example you will find a snippet to create an InfluxDB client using the official Java client:

<!--codeinclude-->
[InfluxDBContainer.getNewInfluxDB()](../../../modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainer.java)
Copy link
Member

Choose a reason for hiding this comment

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

same here about use the code that is required

Copy link
Member

Choose a reason for hiding this comment

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

missing the block here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✅

*/
public String getUrl() {
return "http://" + getHost() + ":" + getLivenessCheckPort();
return "http://" + this.getHost() + ":" + this.getMappedPort(INFLUXDB_PORT);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return "http://" + this.getHost() + ":" + this.getMappedPort(INFLUXDB_PORT);
return "http://" + getHost() + ":" + getMappedPort(INFLUXDB_PORT);

public InfluxDB getNewInfluxDB() {
InfluxDB influxDB = InfluxDBFactory.connect(getUrl(), username, password);
influxDB.setDatabase(database);
final InfluxDB influxDB = InfluxDBFactory.connect(this.getUrl(), this.username, this.password);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final InfluxDB influxDB = InfluxDBFactory.connect(this.getUrl(), this.username, this.password);
final InfluxDB influxDB = InfluxDBFactory.connect(getUrl(), this.username, this.password);

*/
public class InfluxDBContainer<SELF extends InfluxDBContainer<SELF>> extends GenericContainer<SELF> {
public class InfluxDBContainer extends GenericContainer<InfluxDBContainer> {
Copy link
Member

Choose a reason for hiding this comment

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

for compatibility, we need to rollback this change. We can apply it again in version 2.x

Comment on lines +90 to +91
this.isAtLeastMajorVersion2 =
new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("2.0.0");
Copy link
Member

Choose a reason for hiding this comment

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

@kiview I wonder if we can remove this check and use the version provided via ENV here. In order to do this we need to make a dockerClient.inspectImageCmd(image) at the configure method. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

@eddumelendez I think I would prefer your suggested approach. It is still not a super strong indicator for custom images, but I believe more explicit than the tag version.

Copy link
Member

Choose a reason for hiding this comment

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

I will leave it as is for now. I think we need to think about how to address them for custom images.

Running a `InfluxDBContainer` as a stand-in for InfluxDB in a test:

<!--codeinclude-->
[InfluxDBContainerTest](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

this one is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@raminqaf
Copy link
Contributor Author

@eddumelendez Thanks for the review! I added all of them!

@eddumelendez
Copy link
Member

It's failing because of

Error: eckstyle] [ERROR] /home/runner/work/testcontainers-java/testcontainers-java/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java:32:5: 'VARIABLE_DEF' should be separated from previous line. [EmptyLineSeparator]
Error: eckstyle] [ERROR] /home/runner/work/testcontainers-java/testcontainers-java/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java:4:62: Using a static member import should be avoided - org.testcontainers.containers.InfluxDBTestUtils.createInfluxDBWithUrl. [AvoidStaticImport]

You can reproduce it locally by running ./gradlew :influxdb:checkstyleMain :influxdb:checkstyleTest

Copy link
Member

@eddumelendez eddumelendez left a comment

Choose a reason for hiding this comment

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

thanks a lot for your patience @raminqaf ! I think we are just polishing the docs now and from my side LGTM.

@raminqaf
Copy link
Contributor Author

@eddumelendez I added all the reviews and the checkstyle checks!

eddumelendez
eddumelendez previously approved these changes Nov 8, 2022
kiview
kiview previously approved these changes Nov 14, 2022
Comment on lines +90 to +91
this.isAtLeastMajorVersion2 =
new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("2.0.0");
Copy link
Member

Choose a reason for hiding this comment

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

@eddumelendez I think I would prefer your suggested approach. It is still not a super strong indicator for custom images, but I believe more explicit than the tag version.

@eddumelendez eddumelendez dismissed stale reviews from kiview and themself via 627a01c November 15, 2022 17:31
@eddumelendez eddumelendez added this to the next milestone Nov 15, 2022
@eddumelendez eddumelendez merged commit e3ec7d4 into testcontainers:main Nov 15, 2022
@eddumelendez
Copy link
Member

thank you so much for your contribution and all work you've done, @raminqaf ! This is now in main branch and will be available in next version.

@raminqaf raminqaf deleted the feature/influxdb-v2-test-container branch November 28, 2022 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support of InfluxDB v2.x.x +
8 participants