Why does the InfluxDBClient.getBucketsApi().findBuckets() API method always return an empty list of buckets?

theirman
Fri, 22 Mar 2024 08:34:35 +0000
InfluxDB 2

Hello

I have an InfluxDB 2.7 OSS server on which I store feed distribution data for several geographical sites (organization) with several farms (bucket).

One of my use cases is to provide all the consumption data for a geographical site, which requires a Flux query across several buckets.

As I haven’t found a method for this type of query, I use the InfluxDBClient.getBucketsApi().findBuckets() method to retrieve the list of buckets, query them one by one and then aggregate the results.

However, on the same InfluxDB connection, with a valid token of type all-access, I manage to retrieve a bucket from the findBucketByName method, but the findBuckets method systematically returns an empty list of buckets.

The equivalent curl query works :

curl 'https://my.server.url:8086/api/v2/buckets?org=test' \
     --header "Authorization: Token myAllAccessToken" \
     --header "Accept: application/json" \
     --header "Content-Type: application/json"

What could be the reason for this malfunction? Below is the code for my test method. If I’m not completely clear, don’t hesitate to ask me questions.

Thanks for your reply

Thierry

public static List<Bucket> getBuckets(String url, String org, String token)
{
    InfluxDBClientOptions options = InfluxDBClientOptions.builder()
                                                         .url( url )
                                                         .org( org )
                                                         .authenticateToken( token.toCharArray() )
                                                         .build();

    try (InfluxDBClient influxClient = InfluxDBClientFactory.create(options))
    {
        List<Bucket> buckets = influxClient.getBucketsApi().findBuckets();

                    // --- only for tests ---
                    for(Bucket b:buckets)
                        System.out.println(b.getName());

                    Bucket tasks        = influxClient.getBucketsApi().findBucketByName("_tasks");
                    Bucket monitoring   = influxClient.getBucketsApi().findBucketByName("_monitoring");
                    Bucket test         = influxClient.getBucketsApi().findBucketByName("test");

                    System.out.println(tasks.getName());
                    System.out.println(monitoring.getName());
                    System.out.println(test.getName());
                    // --------------------

        return buckets;
    }
}

4 posts - 2 participants