kairosdb / kairosdb-client

Java Client for KairosDB
65 stars 67 forks source link

bug1 #81

Closed 15116303251 closed 8 months ago

15116303251 commented 5 years ago

image

这是3.0.0 版本测试复杂数据类型的用例,添加的时候直接返回400

jsabin commented 5 years ago

I need more information. If you are using a custom type you need to make sure that you added the type to the KairosDB server.

otrebor1979 commented 5 years ago

It seems I'm having the same problem. I'm trying to push via JAVA a sample metric taken from documentation's examples. Her is my code (portion):

HttpClient client = new HttpClient(url);
client.registerCustomDataType("complex", ComplexNumber.class); // "complex" is the group type
MetricBuilder metricBuilder = MetricBuilder.getInstance();
Metric metric = metricBuilder.addMetric("metric1", "complex-number");  // "complex-number" is the registered type
metric.addTag("host", "myHost");
metric.addDataPoint(System.currentTimeMillis(), new ComplexNumber(2.3, 3.4));
metric.addDataPoint(System.currentTimeMillis(), new ComplexNumber(1.1, 5));
client.pushMetrics(metricBuilder);

[...]

class ComplexNumber {
    private double real;
    private double imaginary;
    public ComplexNumber(double real, double imaginary) {
        this.real = real;
        this.imaginary = imaginary;
    }
}

And this is the error a get:

UnexpectedResponseException{request=Request{uri=http://localhost:6080/api/v1/datapoints, method=POST, headers={Content-Type=[application/json; charset=UTF-8]}, bodySource=org.kairosdb.client.HttpClient$StringBodySource@2ddc8ecb, followRedirects=false}, statusCode=400, statusMessage=Bad Request, headers={Access-Control-Allow-Origin=[*], Content-Type=[application/json], Transfer-Encoding=[chunked], Server=[Jetty(8.1.16.v20140903)]}}
    at org.kairosdb.client.response.DefaultJsonResponseHandler.handle(DefaultJsonResponseHandler.java:100)
    at org.kairosdb.client.HttpClient.execute(HttpClient.java:330)
    at org.kairosdb.client.HttpClient.postData(HttpClient.java:290)
    at org.kairosdb.client.HttpClient.pushMetrics(HttpClient.java:253)

P.S.: I'm using KairosDB v1.2.2.

brianhks commented 8 months ago

This is likely due to the server not having the type registered in the config file. You will need to provide a plugin jar that has the type in it and load it in a module. See the comments in the kairosdb.conf file for further information.