Skip to content

feat(influxdb): support for influxdbv2 #3072

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 4 commits into from
Apr 24, 2025

Conversation

xBlaz3kx
Copy link
Contributor

Feature

What does this PR do?

I added a WithV2Env option to the InfluxDB module to setup the V2 instance correctly according to their confguration guidelines. Added tests for changes and updated docs/examples for setting up a V2 instance.

Why is it important?

Lack of documentation on how to setup V2 instances and prettified the workaround with a neater solution (custom options with configuration for V2).

Related issues

	ctx := context.Background()

	username := "username"
	password := "password"
	org := "org"
	bucket := "bucket"
	authEnabled := true
	token := "influxdbv2token"

	influxdbContainer, err := influxdb.Run(ctx,
		"influxdb:2.7.11",
		influxdb.WithV2Env(influxdb.InfluxDBV2Config{
			Username:    &username,
			Password:    &password,
			Org:         org,
			Bucket:      bucket,
			Token:       &token,
			AuthEnabled: &authEnabled,
		}),
	)
	defer func() {
		if err := testcontainers.TerminateContainer(influxdbContainer); err != nil {
			log.Printf("failed to terminate container: %s", err)
		}
	}()
	if err != nil {
		log.Printf("failed to start container: %s", err)
		return
	}
	// }

	state, err := influxdbContainer.State(ctx)
	if err != nil {
		log.Printf("failed to get container state: %s", err)
		return
	}

	fmt.Println(state.Running)
	// Output:
	// true

	// Query the InfluxDB API to verify the setup
	url, err := influxdbContainer.ConnectionUrl(ctx)
	if err != nil {
		log.Printf("failed to get host: %s", err)
		return
	}

	// Initialize a new InfluxDB client
	client := influxdb2.NewClientWithOptions(url, token, influxdb2.DefaultOptions())
	defer client.Close()

	// Get the bucket
	influxBucket, err := client.BucketsAPI().FindBucketByName(ctx, bucket)
	if err != nil {
		log.Printf("failed to get bucket: %s", err)
		return
	}

	log.Printf("Got bucket: %s", influxBucket.Name)

@xBlaz3kx xBlaz3kx requested a review from a team as a code owner March 31, 2025 20:18
Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 568c0d5
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/680a25f50e43ef000881dc8a
😎 Deploy Preview https://deploy-preview-3072--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@xBlaz3kx xBlaz3kx changed the title Feat/influxdb v2 opts feat: Influxdb v2 opts and documentation update Mar 31, 2025
@xBlaz3kx xBlaz3kx changed the title feat: Influxdb v2 opts and documentation update feat: support for influxdbv2 Mar 31, 2025
Copy link
Contributor

@stevenh stevenh 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 the PR, a few suggestions and clarifying question

Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

Left a few comments. I do not have a strong opinion on the Nil Vs zero values discussion, as I see the value in separating required Vs optional values using pointers.

We are usually setting zero values, in general, without complains for our users, so I'd say we are fine not using pointers, checking the zero value was not set (booleans raising hands atm 😄 )

@@ -7,6 +7,7 @@ import (
"testing"
"time"

influxdb2 "github.com/influxdata/influxdb-client-go/v2"
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: for consistency with the v1 import

Suggested change
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
influxclient2 "github.com/influxdata/influxdb-client-go/v2"

@xBlaz3kx xBlaz3kx force-pushed the feat/influxdb_v2_opts branch from a7980d8 to e88aa32 Compare April 7, 2025 20:51
Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Updated with clarification of previous asks, hopefully this makes sense.

Having thought about this more, the big config struct is an antipattern to functional options, sorry for not spotting this earlier, see comments for details.

@xBlaz3kx xBlaz3kx force-pushed the feat/influxdb_v2_opts branch from e88aa32 to d2dddf3 Compare April 13, 2025 13:20
@xBlaz3kx xBlaz3kx force-pushed the feat/influxdb_v2_opts branch from d2dddf3 to 1194362 Compare April 13, 2025 13:34
@mdelapenya mdelapenya changed the title feat: support for influxdbv2 feat(influxdb): support for influxdbv2 Apr 24, 2025
@mdelapenya mdelapenya self-assigned this Apr 24, 2025
@mdelapenya mdelapenya added the enhancement New feature or request label Apr 24, 2025
* main:
  feat(postgres): add WithOrderedInitScripts for Postgres testcontainers (testcontainers#3121)
  feat(redis): add TLS support (testcontainers#3115)
  feat: add Docker Model Runner module (testcontainers#3106)
  feat: add toxiproxy module (testcontainers#3092)
  chore(ci): run core tests on Testcontainers Cloud (testcontainers#3117)
  deps(aerospike): replace core module in go.mod (testcontainers#3116)
  chore(deps): bump golang.org/x/net from 0.36.0 to 0.38.0 in /modules and /examples (testcontainers#3114)
  chore(ci): revert codeql improvements for CI resiliency (testcontainers#3112)
  docs(socat): add missing version marker for new options (testcontainers#3111)
  deps: use pinned dependencies on GH actions (testcontainers#3110)
  chore(deps): bump jinja2 from 3.1.5 to 3.1.6 (testcontainers#3109)
  chore(ci): reduce GH runners usage by calling codeql in the lint stage (testcontainers#3108)
  deps(ci): use python 3.13 on Netlify deployments (testcontainers#3107)
@mdelapenya
Copy link
Member

@xBlaz3kx I added a commit on top of yours, if you approve, I'm merging this PR, thanks!

@xBlaz3kx
Copy link
Contributor Author

Sounds good!

@mdelapenya
Copy link
Member

@stevenh all good with this one?

@mdelapenya mdelapenya requested a review from stevenh April 24, 2025 12:23
Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

LGTM

@mdelapenya mdelapenya merged commit b395520 into testcontainers:main Apr 24, 2025
16 checks passed
@xBlaz3kx xBlaz3kx deleted the feat/influxdb_v2_opts branch April 24, 2025 13:10
mdelapenya added a commit to georgespalding/testcontainers-go that referenced this pull request Apr 25, 2025
* main:
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3119)
  chore(deps): bump github.com/magiconair/properties from 1.8.9 to 1.8.10 (testcontainers#3118)
  chore(ci): exclude more files for a full-blown build (testcontainers#3122)
  feat(influxdb): support for influxdbv2 (testcontainers#3072)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support for InfluxDB v2
3 participants