-
Notifications
You must be signed in to change notification settings - Fork 1k
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
InfluxDB 2.0 API support #1974
Comments
Looks like this is already being worked on: #1423 |
It looks like 2.0 is still beta according to the docs. That doesn't mean we can't support it, necessarily, but we don't want to put something out there that claims to be stable when the integration isn't a final version yet. |
Yes, that makes sense. In the meantime, I can help with testing or anything else that may be needed to prepare. |
@bednar Without having a look at all the code, can we make the distinction between Influx 1 and 2 fully transparent to the user, i.e. can Micrometer somehow check for v2 support via some API endpoint and just use it and fall back on v1 otherwise? Supposing this is not possible, we could introduce an Only if the other configuration options differ substantially between Influx 1 and 2 would I consider a separate |
Hi @jkschneider, We could do distinction via configuration. If user sets the Micrometer required parameters:
and validation of @Override
default Validated<?> validate() {
return checkAll(this,
c -> StepRegistryConfig.validate(c),
checkRequired("uri", Influx2Config::uri),
checkOneOf(
checkRequired("db", Influx2Config::bucket)
.andThen(checkRequired("consistency", Influx2Config::token))),
checkRequired("bucket", Influx2Config::bucket)
.andThen(checkRequired("org", Influx2Config::org))
.andThen(checkRequired("token", Influx2Config::token))),
);
} Documentation could looks like: What do you think? It is an acceptable approach? Regards |
@bednar It seems that conceptually
Returning then to |
@jkschneider thanks for response. We could use If we want to store metrics into v2, this configuration is invalid:
Will we use a default values for
Yes, we can use HEAD instead GET. |
Influx 2 requires you to establish an org on
Influx 1.x supported JWT tokens (i.e. |
@jkschneider thanks for explanation. One more question...
Where will do this validation? In the |
Good question, and I thought about this a bit too. I think it would have to be in the first Which brings up another point... We should probably introduce a config to allow for the user to manually select API version as a fallback in case they do something like inject an |
Ok, it sounds good.
Ok. I will prepare a second PR that will improve existing |
Sorry I am late to respond to this thread but would it be possible to keep the two different registries, and have an additional delegating one which does the 'detection' of which version to use? (Though it makes perfect sense for them both to share the code regarding line protocol like in the PR) In my deployments I will know the version ahead of time and would just like to the v2 directly, and fail if there is an issue. Then again I am still pretty inexperienced so I will trust your judgement but just wanted to voice my thoughts once. |
I've prepare a draft PR #2113 which introduce a support of InfluxDB v2 in the It is not finished but I think it is a good start point to discuss. |
#2113 is ready to review |
It would be great to have this support in Micrometer. I am using InfluxDB Cloud as I'm working on a pet project and don't want the cost or hassle of hosting my own Influx DB instance. |
I've prepared an example how to use a current version of Spring Boot to sent metrics into the InfluxDB v2. We had to use a custom Custom HttpSenderpackage io.micrometer.boot2.samples;
import io.micrometer.boot2.samples.components.PersonController;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.OkHttpSender;
import io.micrometer.influx.InfluxConfig;
import io.micrometer.influx.InfluxMeterRegistry;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(scanBasePackageClasses = PersonController.class)
@EnableScheduling
public class InfluxSample {
public static void main(String[] args) {
new SpringApplicationBuilder(InfluxSample.class).profiles("influx").run(args);
}
@Value("${management.metrics.export.influx.org}")
private String org;
@Value("${management.metrics.export.influx.bucket}")
private String bucket;
@Value("${management.metrics.export.influx.token}")
private String token;
@Bean
public InfluxMeterRegistry influxMeterRegistry(InfluxConfig influxConfig, Clock clock) {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(chain -> {
Request original = chain.request();
// skip others than write
if (!original.url().pathSegments().contains("write")) {
return chain.proceed(original);
}
HttpUrl url = original.url()
.newBuilder()
.removePathSegment(0)
.addEncodedPathSegments("api/v2/write")
.removeAllQueryParameters("db")
.removeAllQueryParameters("consistency")
.addQueryParameter("org", org)
.addQueryParameter("bucket", bucket)
.build();
Request request = original.newBuilder()
.url(url)
.header("Authorization", "Token " + token)
.build();
return chain.proceed(request);
});
return InfluxMeterRegistry.builder(influxConfig)
.clock(clock)
.httpClient(new OkHttpSender(httpClient.build()))
.build();
}
} Application configurationmanagement.metrics.export:
influx:
enabled: true
step: PT10S
readTimeout: PT30S
batchSize: 20000
uri: "http://localhost:9999"
org: "my-org"
bucket: "my-bucket"
token: "my-token"
|
Seems InfluxDB v2 has been released. https://docs.influxdata.com/influxdb/v2.0/reference/release-notes/influxdb/ 🎉 |
Hi guys, is there any update? I wonder why this issue is closed :| |
The issue is not closed. I've just added it to the 1.7 milestone, which is our upcoming feature release. |
This is available in the latest 1.7.0-SNAPSHOT builds. Please feel free to try it out and leave any feedback. We'll have a 1.7 milestone release out soon. |
Hi guys, are there any examples of configs? management:
metrics:
export:
influx:
enabled: true
step: PT0.5S
readTimeout: PT30S
batchSize: 20000
uri: http://localhost:8086
org: org
bucket: test-bucket
token: token It doesn't work for me:
It doesn't work when i change deps:
|
@vadim-hleif you will have to make an @Bean
InfluxConfig influxConfig() {
return new InfluxConfig() {
@Override
public String get(String key) {
return null;
}
@Override
public Duration step() {
return Duration.ofSeconds(20);
}
@Override
public String org() {
return "org";
}
@Override
public String bucket() {
return "metrics";
}
@Override
public String token() {
return "my-token";
}
};
} |
This is included in Micrometer 1.7.0-M1 and Spring Boot support has been updated to handle the new properties in Spring Boot 2.5.0-M3. Please try it out and let us know any feedback on it. |
Looks like the 'direct' api for 1.x will not work with 2.0.
Thankfully the changes seem pretty small, for comparison 1.x write api and 2.x write api
The body remains the same (line protocol), only major change I believe is for auth (though user + password is probably also possible), instead of
db
query param there isorg
andbucket
.There is also an official java client library, though I am not sure if micrometer needs all the functionality it provides.
Sorry if there is already something in place to configure micrometer so it works with influxdb 2.0 (directly), but I did not find it.
The text was updated successfully, but these errors were encountered: