Skip to content

Add support for InfluxDB 2 and InfluxDB 3 Core #3831

Description

@linghengqian

The documentation at https://github.com/google/cadvisor/blob/master/docs%2Fstorage%2Finfluxdb.md only supports InfluxDB 1. For InfluxDB 2 and InfluxDB 3, there is no concept of a password, only a token. A token cannot be used directly as a password.

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
@Testcontainers
class InfluxQlTest {
    @Container
    private final GenericContainer<?> container = new GenericContainer<>("influxdb:3.3.0-core")
            .withCommand("influxdb3 serve --node-id local01 --object-store file --data-dir /home/influxdb3/.influxdb3")
            .withExposedPorts(8181);
    @Test
    void test() throws Exception {
        HttpResponse<String> response = HttpClient.newHttpClient().send(
                HttpRequest.newBuilder()
                        .uri(new URI("http://%s:%d/api/v3/configure/token/admin".formatted(container.getHost(), container.getMappedPort(8181))))
                        .POST(HttpRequest.BodyPublishers.noBody())
                        .header("Accept", "application/json")
                        .header("Content-Type", "application/json")
                        .build(),
                HttpResponse.BodyHandlers.ofString()
        );
        String token = new ObjectMapper().readTree(response.body()).get("token").asText();
    }
}

Support for InfluxDB 2 and InfluxDB 3 core requires some additional compatibility handling. This is because it's clearly impossible to connect to InfluxDB 2 or InfluxDB 3 Core using an InfluxDB 1 client. See #2843 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions