javainfluxdbjava-17influxdb-2flux-influxdb

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


Helllo all,

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;
    }
}

Solution

  • This morning, I just found an alternative solution that gives me the exact result I expected. I must have been tired last week not to have seen it:

    List<Bucket> buckets = influxClient.getBucketsApi().findBucketsByOrgName("test");
    

    To what's-his-name, who gave me a -1 without knowing how long I'd been looking for a solution > you're very helpful, thanks !

    To all the others > Have a nice day :)

    Thierry