#3831·cadvisor

Add support for InfluxDB 2 and InfluxDB 3 Core

Author: linghengqianCreated Jan 29, 2026Updated Aug 21, 2026

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.

java
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 https://github.com/google/cadvisor/issues/2843 .