-
-
Notifications
You must be signed in to change notification settings - Fork 247
Add InfluxDB module #1130
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
base: main
Are you sure you want to change the base?
Add InfluxDB module #1130
Conversation
✅ Deploy Preview for testcontainers-node ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thanks @mdodsworth, could you please also add some docs? Please follow the template from other modules |
| }, | ||
| "devDependencies": { | ||
| "@influxdata/influxdb-client": "^1.35.0", | ||
| "axios": "^1.7.9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now use node's built-in HTTP client in the core and other modules, let's do the same here so we don't add a lot of unnecessary dependencies
| afterEach(async () => { | ||
| if (container) { | ||
| await container.stop(); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use Typescript's await using syntax so the container is automatically stopped after each test
| constructor(image: string) { | ||
| super(image); | ||
| // Determine version from image tag (default to v2 if unknown) | ||
| this.isVersion2 = this.isInfluxDB2(this.imageName.tag ?? "latest"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ?? "latest" is not needed, the ImageName constructor will automatically set the tag to latest if one is not provided
|
|
||
| public override async start(): Promise<StartedInfluxDBContainer> { | ||
| // Re-evaluate version based on the final image tag | ||
| this.isVersion2 = this.isInfluxDB2(this.imageName.tag ?? "latest"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it need to be re-evaluated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. Will remove
|
|
||
| private isInfluxDB2(tag: string): boolean { | ||
| if (tag === "latest") { | ||
| return true; // Assume latest is v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this module work for InfluxDB v3? If so I'd change the naming of this logic to be either v1 or > v1, instead of v1 or v2 or ...
| // Parse version number | ||
| const versionMatch = tag.match(/^(\d+)(?:\.(\d+))?/); | ||
| if (versionMatch) { | ||
| const majorVersion = parseInt(versionMatch[1], 10); | ||
| return majorVersion >= 2; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the compare-versions library which we use in other modules for this, e.g.
| if (satisfies(this.imageName.tag, "<7.4.0")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran a quick check and it looks like compare-versions doesn't handle non-semver tags like 1.8-alpine (it throws).
describe("compare-versions non-semver handling", () => {
it("should throw when provided a non-semver InfluxDB 1.x tag", () => {
expect(() => satisfies("1.8-alpine", ">=2.0.0")).toThrow(/Invalid argument/);
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cristianrgreco giving this a bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @mdodsworth I didn't realise this was blocking the other changes.
Good catch! Then yes please the implementation as it is
|
|
||
| return `${this.getUrl()}?${params.toString()}`; | ||
| } else { | ||
| // InfluxDB 1.x connection string format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether it would be better to have an InfluxDBContainer interface, and have v1 and vX implementations instead of almost every method having an if/else. Perhaps for the future, maybe if v3 also has incompatibilities
Tried to follow the java implementation on features and version support.