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: add module to support InfluxDB v1.x #1703

Merged
merged 27 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b4944c6
Added module to support InfluxDB v1.x
jcracchiolo-tc Sep 30, 2023
a2783e1
Fix comment
JJCinAZ Oct 17, 2023
4347c6b
Update docs/modules/influxdb.md
JJCinAZ Oct 17, 2023
1a0f435
Merge branch 'main' into Add-InfluxDB-Module
JJCinAZ Oct 17, 2023
0c92155
Merge branch 'main' into Add-InfluxDB-Module
mdelapenya Mar 13, 2024
01b232e
chore: bump core to latest
mdelapenya Mar 13, 2024
f06cf29
chore: fix lint
mdelapenya Mar 13, 2024
3c83b6a
chore: format
mdelapenya Mar 13, 2024
26223de
chore: use t.Cleanup
mdelapenya Mar 13, 2024
13143b6
chore: use testdata
mdelapenya Mar 13, 2024
48ad86e
chore: add testable example for influxdb
mdelapenya Mar 13, 2024
011d29f
chore: add tests for withConfig
mdelapenya Mar 13, 2024
884dc18
chore: rename import
mdelapenya Mar 13, 2024
ecf6a91
chore: change usae example
mdelapenya Mar 13, 2024
f4d97c9
docs: include code snippet for musthaveconnectionurl
mdelapenya Mar 13, 2024
2513917
chore: rename function
mdelapenya Mar 13, 2024
eb64c16
chore: add to sonar
mdelapenya Mar 13, 2024
54fc82c
fix: proper order
mdelapenya Mar 13, 2024
b40dc88
Merge branch 'main' into Add-InfluxDB-Module
mdelapenya Mar 15, 2024
4b019eb
chore: mod tidy
mdelapenya Mar 15, 2024
2555d21
Merge branch 'main' into Add-InfluxDB-Module
mdelapenya Mar 18, 2024
e12d170
chore: always wait for the listening port
mdelapenya Mar 18, 2024
a65e22b
Merge branch 'main' into Add-InfluxDB-Module
mdelapenya Mar 18, 2024
ceec832
chore: remove TLS support for the moment
mdelapenya Mar 18, 2024
45586b4
Merge branch 'main' into Add-InfluxDB-Module
mdelapenya Mar 22, 2024
21eb3d1
chore: mod tidy
mdelapenya Mar 22, 2024
fe4c887
Merge branch 'main' into Add-InfluxDB-Module
mdelapenya Mar 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, elasticsearch, gcloud, inbucket, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, vault, weaviate]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, elasticsearch, gcloud, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, vault, weaviate]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ src/pip-delete-this-directory.txt
.DS_Store

TEST-*.xml

**/go.work
4 changes: 4 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
"name": "module / inbucket",
"path": "../modules/inbucket"
},
{
"name": "module / influxdb",
"path": "../modules/influxdb"
},
{
"name": "module / k3s",
"path": "../modules/k3s"
Expand Down
88 changes: 88 additions & 0 deletions docs/modules/influxdb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# InfluxDB

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

A testcontainers module for InfluxDB. This module supports v1.x of InfluxDB.

## Adding this module to your project dependencies

Please run the following command to add the InfluxDB module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/influxdb
```

## Usage example

<!--codeinclude-->
[Creating an InfluxDB container](../../modules/influxdb/examples_test.go) inside_block:runInfluxContainer
<!--/codeinclude-->

## Module Reference

The InfluxDB module exposes one entrypoint function to create the container, and this function receives two parameters:

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) {}
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the container, you can pass options in a variadic way to configure it.

!!!tip

You can find configuration information for the InfluxDB image on [Docker Hub](https://hub.docker.com/_/influxdb) and a list of possible
environment variables on [InfluxDB documentation](https://docs.influxdata.com/influxdb/v1/administration/config/).

#### Image

To use a different Docker image, you can use the `testcontainers.WithImage` option to specify the
image, E.g. `testcontainers.WithImage("influxdb:1.8.0")`. By default, the 1.8.10 image is used. Note that
`influxdb:latest` will get you a version 2 image which is not supported by this module.


{% include "../features/common_functional_options.md" %}

#### Set username, password and database name

By default, authentication is disabled and no credentials are needed to use the Influx API against the test container.
If you want to test with credentials, include the appropriate environment variables to do so.

#### Init Scripts

While the InfluxDB image will obey the `/docker-entrypoint-initdb.d` directory as is common, that directory does not
exist in the default image. Instead, you can use the `WithInitDb` option to pass a directory which will be copied to
when the container starts. Any `*.sh` or `*.iql` files in the directory will be processed by the image upon startup.
When executing these scripts, the `init-influxdb.sh` script in the image will start the InfluxDB server, run the
scripts, stop the server, and restart the server. This makes it tricky to detect the readiness of the container.
This module looks for that and adds some extra tests for readiness, but these could be fragile.

!!!important
The `WithInitDb` option receives a path to the parent directory of one named `docker-entrypoint-initdb.d`. This is
because the `docker-entrypoint-initdb.d` directory is not present in the image.

#### Custom configuration

If you need to set a custom configuration, you can use `WithConfigFile` option to pass the path to a custom configuration file.

### Container Methods

#### ConnectionUrl

This function is a simple helper to return a URL to the container, using the default `8086` port.

<!--codeinclude-->
[ConnectionUrl](../../modules/influxdb/influxdb_test.go) inside_block:influxConnectionUrl
<!--/codeinclude-->

Please check the existence of two methods: `ConnectionUrl` and `MustConnectionUrl`. The latter is used to avoid the need to handle errors,
while the former is used to return the URL and the error. `MustConnectionUrl` will panic if an error occurs.

!!!info
The `ConnectionUrl` and `MustConnectionUrl` methods only support HTTP connections at the moment.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ nav:
- modules/elasticsearch.md
- modules/gcloud.md
- modules/inbucket.md
- modules/influxdb.md
- modules/k3s.md
- modules/k6.md
- modules/kafka.md
Expand Down
5 changes: 5 additions & 0 deletions modules/influxdb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-influxdb
43 changes: 43 additions & 0 deletions modules/influxdb/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package influxdb_test

import (
"context"
"fmt"
"log"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/influxdb"
)

func ExampleRunContainer() {
// runInfluxContainer {
ctx := context.Background()

influxdbContainer, err := influxdb.RunContainer(
ctx, testcontainers.WithImage("influxdb:1.8.10"),
influxdb.WithDatabase("influx"),
influxdb.WithUsername("root"),
influxdb.WithPassword("password"),
)
if err != nil {
log.Fatalf("failed to start container: %s", err)
}

// Clean up the container
defer func() {
if err := influxdbContainer.Terminate(ctx); err != nil {
log.Fatalf("failed to terminate container: %s", err)
}
}()
// }

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

fmt.Println(state.Running)

// Output:
// true
}
66 changes: 66 additions & 0 deletions modules/influxdb/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module github.com/testcontainers/testcontainers-go/modules/influxdb

go 1.21

require (
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.29.1
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.12 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/testcontainers/testcontainers-go => ../..
Loading
Loading