Giter Club home page Giter Club logo

aliyun-tsdb-java-sdk's Introduction

Aliyun TSDB SDK for Java

Master Build codecov Maven Central

The Aliyun TSDB SDK for Java enables Java developers to easily work with Aliyun TSDB, compatible OpenTSDB protocol. You can get started in minutes using Maven.

Requirements

  • Java 1.6 or later
  • Maven

Install

The recommended way to use the Aliyun TSDB SDK for Java in your project is to consume it from Maven. Import as follows:

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>hitsdb-client</artifactId>
    <version>0.3.8</version>
</dependency>

See the Setup section of the SDK Reference for more information about installing the SDK through other means.

Build

Once you check out the code from GitHub, you can build it using Maven. Use the following command to build:

mvn clean install -DskipTests

aliyun-tsdb-java-sdk's People

Contributors

alibaba-oss avatar asdf2014 avatar caszhou avatar changrui82 avatar cuiyuan avatar dependabot[bot] avatar hujianhong avatar huyafanlw avatar johnnyjie avatar laplacedemon avatar lightingwalker avatar uni51563 avatar vancepym avatar xiaowing avatar yafanrichard avatar zhang-jingwang avatar zhulongcheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aliyun-tsdb-java-sdk's Issues

数据写入失败,没有触发回调接口

我使用的版本是 0.0.13
我使用以下配置去创建tsdbconfig

listenBatchPut(new BatchPutDetailsCallback() {
                @Override
                public void response(String address, List<Point> points, DetailsResult result) {
                    System.out.println(result);
                }
            })

当我使用异步写入接口,写入数据到TSDB数据库时,由于发送point不符合规范,写入失败,但是这个回调接口并没有触发。

authentication credential didn't work for the secondary TSDB cluster when using HAPolicy

Version information

  • SDK version
    0.3.5

  • TSDB engine version
    v2.6.13

Bug description
when both primary cluster and secondary cluster need credential,
authentication credential didn't work for the secondary TSDB cluster when using HAPolicy.

Reproduce case

  1. set the correct authentication credential for TSDBConfig, as well as a HAPolcy. like the following code
HAPolicy policy = HAPolicy.addSecondaryCluster(readHost, readPort)
                .setRetryRule(HAPolicy.RetryRule.SecondaryPreferred)
                .setRetryTimes(0)
                .build();

        TSDBConfig config = TSDBConfig
                .address(writeHost, writePort)
                .basicAuth(writerUsername, tsdbWritePassword)
                .httpConnectionLiveTime(1800)
                .batchPutSize(50)
                .batchPutRetryCount(3)
                .multiFieldBatchPutConsumerThreadCount(2)
                .addHAPolicy(policy)
                .config();
  1. initialize the TSDBClient object
  2. write data to TSDB cluster with the TSDBClient object
  3. query the data just written with the TSDBClient object

Expected behavior
both write and read succeeded

BatchPutIgnoreErrorsCallback not triggered

Version information

  • SDK version
    v0.3.3

  • TSDB engine version
    2.6.7

Bug description

  1. Register a BatchPutIgnoreErrorsCallback
  2. Write data via async put with some invalid tagvalue(not allowed character contained) on purpuse

Additional context

User's debug info showed as follows

image

image

image

image

image

查询接口不支持指定useCalendar和timezone

由于TSDB查询的时间范围有两种方式,一种是基于模的方式,一种是基于日历的方式,客户端中提供的查询Query不能指定useCalendar和timezone,这样的话在downsample的时候取得的结果都是根据UTC时间进行降采样的。我想得到的结果是北京时区的采样点,请问应该怎么做?
举个例子,我想查询北京时间6月22号到6月23号这一天的总和,如果不指定useCalendar和timezone的话,得到的结果点是北京时间6月22号8点-北京时间6月23号8点之间的总和,并不能达到我要的结果
image

Thread bursting when the TSDB client object creation failed

Version information

  • SDK version
    v0.3.3

  • TSDB engine version
    (none)

Bug description
Thread bursting when the TSDB client object creation failed. As a result, it would cause OOM

output as follows

at first, the active thread number: 2
the current active thread number: 152
the current active thread number: 302
the current active thread number: 452
the current active thread number: 602
the current active thread number: 752
the current active thread number: 902
the current active thread number: 1052
the current active thread number: 1202
the current active thread number: 1352
the current active thread number: 1502
the current active thread number: 1652
the current active thread number: 1802
the current active thread number: 1952
the current active thread number: 2102
the current active thread number: 2252
the current active thread number: 2402
the current active thread number: 2552
the current active thread number: 2702
the current active thread number: 2852
the current active thread number: 3002
the current active thread number: 3152
the current active thread number: 3302
the current active thread number: 3452
the current active thread number: 3602
the current active thread number: 3752
the current active thread number: 3902
the current active thread number: 4052
Exception in thread "pool-1357-thread-1" java.lang.OutOfMemoryError: unable to create new native thread

Reproduce case
Codes to reproduce the behavior:

public static void testTSDBClientFailure() {
        System.out.printf("at first, the active thread number: %d\n", Thread.activeCount());

        int i = 0;
        while (true) {
            i++;
            try {
                TSDB client = TSDBClientFactory.connect("127.0.0.1", 50010);     // it's an unreachable address
                if (client != null) {
                    System.out.printf("TSDB Client initialized");
                }
            } catch (Exception hex) {
                ;;
            }

            if (i % 50 == 0) {
                System.out.printf("the current active thread number: %d\n", Thread.activeCount());
            }
            try {
                Thread.sleep(50);
            } catch (Exception ex) {
                ;;
            }
        }

    }

opentsdb中配置加入tsd.http.request.enable_chunked后报错

使用批量操作test示例,报错如下:
org.apache.http.ConnectionClosedException: Connection closed
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.endOfInput(HttpAsyncRequestExecutor.java:347)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:261)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
at java.lang.Thread.run(Thread.java:748)

是代码中httpasyncclient连接netty还需要配置内容么

多值模型string field value cannot by empty

用到了TSDB的多值模型,其中一个field写入字符串类型的数据,写入的是空字符串"",报如下错误
Exception in thread "main" java.lang.IllegalArgumentException: String field value can't be empty
at com.aliyun.hitsdb.client.value.request.MultiFieldPoint.checkPoint(MultiFieldPoint.java:224)
at com.aliyun.hitsdb.client.value.request.MultiFieldPoint$MetricBuilder.build(MultiFieldPoint.java:134)
at com.aliyun.hitsdb.client.value.request.MultiFieldPoint$MetricBuilder.build(MultiFieldPoint.java:123)

BUG:太过频繁写入hitsdb

问题:
我使用异步写入接口,发现写入hitsdb的速度有些过于快了,但是每次调用hitsdb 的put接口所包含的points很少,尽管我已经将参数 batchPutTimeLimit 调到10s,但是似乎一点改变也没有,依然每秒20次以上调用hitsdb的put接口,而每次调用包含的points length都很少。

原因:
我发现作者似乎意外的搞错了nano的单位
查看 com.aliyun.hitsdb.client.consumer.BatchPutRunnable 类 的 run方法

long batchPutTimeLimitNano = batchPutTimeLimit*1000l;

这里应该改成

long batchPutTimeLimitNano = batchPutTimeLimit*1000000L;

使用0.2.7版本SDK向开启了鉴权的TSDB实例异步写入数据时,认证失败引发死循环

  • SDK version: 0.2.7

  • TSDB Engine version: 2.5.13

  • reproduce case

    BatchPutDetailsCallback cb = new BatchPutDetailsCallback() {
            @Override
            public void response(String address, List<Point> input, DetailsResult details) {;;}
    
            @Override
            public void failed(String address, List<Point> input, Exception ex) {;;}
        };
    
    TSDBConfig config = TSDBConfig
                .address("127.0.0.1", 3242)
                .basicAuth("tsdbuser", "aaabbbccc")    //user not exist 
                .batchPutBufferSize(20000)
                .batchPutConsumerThreadCount(4)
                .batchPutSize(500)
                .batchPutTimeLimit(100)
                .httpConnectionPool(256)
                .httpConnectTimeout(30)
                .ioThreadCount(4)
                .listenBatchPut(cb)
                .config();
    
        tsdb = TSDBClientFactory.connect(config);
    
        for (int i = 0; i < 2000; i++) {
            Point p = Point.metric("fake_metric").tag("tagk", "tagv")
                    .timestamp(System.currentTimeMillis()).value(i).build();
            tsdb.put(p);
        }
  • bug behavior

    infinite loop. and print the following log repeatlly

    [WARN][com.aliyun.hitsdb.client.callback.http.BatchPutHttpResponseCallback] retry put data!

However, if we add the the following code into the TSDBConfig initialization, the bug wouldn't happen.

TSDBConfig config = TSDBConfig
                .address("127.0.0.1", 3242)
                .basicAuth("tsdbuser", "aaabbbccc")    //user not exist 
                .batchPutBufferSize(20000)
                .batchPutConsumerThreadCount(4)
                .batchPutRetryCount(1)                          // one line code which changes the behavior
                .batchPutSize(500)
                .batchPutTimeLimit(100)
                .httpConnectionPool(256)
                .httpConnectTimeout(30)
                .ioThreadCount(4)
                .listenBatchPut(cb)
                .config();

大量Fixed-Cycle-Close-Connection线程TIMED_WAITING导致故障

`Fixed-Cycle-Close-Connection - priority:5 - threadId:0x00007fbf60035800 - nativeId:0x30b - state:TIMED_WAITING
stackTrace:
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)

  • parking to wait for <0x00000000b33365c8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)`

写入数据丢失

hi,目前我们的写入量大概相当于200个/s。出现了问题:没有报错,但是opentsdb数据量本来有140万,查询才有20多万,其他数据丢失了。
.listenBatchPut(new BatchPutCallback() {
@OverRide
public void response(String arg0, List arg1, Result arg2) {
if (arg2 != null) {
logger.info("tsd sync callback. " + arg2.toString());
}
}
}).config(); // 构造HiTSDBConfig对象
return HiTSDBClientFactory.connect(config);

——————————————————————————————————————

如上代码打出的日志为:
[2019-02-28 00:00:05,479] [I/O dispatcher 3] [INFO] [opentsdb] [////] - [tsd sync callback. {}]

unexpected IllegalStateException thrown from TSDB#multiFieldPut(Collection<MultiFieldPoint>, AbstractMultiFieldBatchPutCallback)

Version information

  • SDK version
    0.3.5

Bug description
The following exception thrown when writing data with TSDB#multiFieldPut(Collection<MultiFieldPoint>, AbstractMultiFieldBatchPutCallback) continously.

Request cannot be executed; I/O reactor status: STOPPED

Exception stacktrace (Optional)

java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED
at org.apache.http.util.Asserts.check(Asserts.java:46)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.ensureRunning(CloseableHttpAsyncClientBase.java:90)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:123)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:75)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:108)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:92)
at com.aliyun.hitsdb.client.http.HttpClient.executeCallback(HttpClient.java:325)
at com.aliyun.hitsdb.client.http.HttpClient.postToAddress(HttpClient.java:408)
at com.aliyun.hitsdb.client.consumer.PointsCollectionPutRunnable.sendHttpRequest(PointsCollectionPutRunnable.java:139)
at com.aliyun.hitsdb.client.consumer.PointsCollectionPutRunnable.run(PointsCollectionPutRunnable.java:72)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
at java.lang.Thread.run(Thread.java:852)

is it possible to shade the common dependency of the hitsdb-client?

比如项目中如果引用了某个库且该库依赖于 org.apache.httpcomponents.httpcore-4.4.11,但是当前的hitsdb-client 依赖于 4.4.6

这种情况下 在创建客户端时就会报错:

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:53)
    at org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:57)
    at org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:47)
    at org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionFactory.<init>(ManagedNHttpClientConnectionFactory.java:75)
    at org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionFactory.<init>(ManagedNHttpClientConnectionFactory.java:83)
    at org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionFactory.<clinit>(ManagedNHttpClientConnectionFactory.java:64)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingNHttpClientConnectionManager.java:581)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.<init>(PoolingNHttpClientConnectionManager.java:165)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.<init>(PoolingNHttpClientConnectionManager.java:149)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.<init>(PoolingNHttpClientConnectionManager.java:121)
    at com.aliyun.hitsdb.client.http.HttpClientFactory.createHttpClient(HttpClientFactory.java:135)
    at com.aliyun.hitsdb.client.TSDBClient.<init>(TSDBClient.java:70)
    at com.aliyun.hitsdb.client.TSDBClientFactory.connect(TSDBClientFactory.java:14)

虽然可以通过 exclusion 来解决这样的问题,但是用户体验是比较差的。最好是能在这种情况下,不要报错。这个 Issue 就希望讨论下是不是可以将 TSDB SDK 的依赖进行 shaded ,以便于跟用户其它部分的依赖相隔离。

使用多值模型接口查询最新值时, 传入的未设置tupleFormat的LastPointQuery对象会触发NullPointerException

  • 现象

    使用多值模型接口TSDB#multiFieldQueryLast()查询最新值时, 传入的未设置tupleFormat的LastPointQuery对象会触发NullPointerException。

  • SDK版本: 0.2.6

  • 最小复现示例

    LastPointSubQuery lastPointSubQuery = LastPointSubQuery.builder(Metric, Fields, Tags).build();
    
    LastPointQuery query = LastPointQuery.builder()
                .sub(lastPointSubQuery)
                .timestamp(System.currentTimeMillis())
                .backScan(-1)
                .msResolution(false)
                .build();
    System.out.printf(String.format("query: %s\n", query.toJSON()));
    try {
        List<MultiFieldQueryLastResult> queryResults = tsdb.multiFieldQueryLast(query);
    }catch (Exception e){
        System.err.println(e.getMessage());
    }

it is ambiguous to throw a HttpServerNotSupportException when the TSDB server actually returns a BAD_REQUEST response

The SDK handles the HTTP Status in the following way

    public ResultResponse(int statusCode) {
        super();
        this.statusCode = statusCode;
        if (statusCode >= 200 && statusCode < 300) {
            if(statusCode == 204){
                this.httpStatus = HttpStatus.ServerSuccessNoContent;
            } else {
                this.httpStatus = HttpStatus.ServerSuccess;
            }
        } else if (statusCode >= 400 && statusCode < 500) {
            if (statusCode == 401) {
                this.httpStatus = HttpStatus.ServerUnauthorized;
            } else {
                this.httpStatus = HttpStatus.ServerNotSupport;
            }
        } else if (statusCode >= 500 && statusCode < 600) {
            this.httpStatus = HttpStatus.ServerError;
        } else {
            this.httpStatus = HttpStatus.UnKnow;
        }
    }

However, for the 400(Bad Request) status, it is meaningful to the application because it is often returned when the TSDB server encountered some invalid request. Application should be notified under those circumstances. HttpServerNotSupportException is too ambiguous.

BUG: Point类中tag值的字符校验不允许加号(+)的问题

我在使用该SDK保存point时,其中有一个tag(arrive_time)值是ISO-8601格式时间字符串,但是报异常提示加号字符是非法的,我不明白为什么在 Point 类的 checkChar 方法中将加号字符排除掉了?是基于什么考虑需要排除加号字符?还是因为遗漏了该字符?

官方可否考虑允许加号(+)字符呢?

以下是异常提示内容:
java.lang.IllegalArgumentException: There is an invalid character in tagvalue. the tag is + <arrive_time:2018-08-04T21:01:16.000+08:00> , the char is '+'
at com.aliyun.hitsdb.client.value.request.Point.checkPoint(Point.java:364)
at com.aliyun.hitsdb.client.value.request.Point$MetricBuilder.build(Point.java:179)
at com.aliyun.hitsdb.client.value.request.Point$MetricBuilder.build(Point.java:161)

重试线程与写入线程是否可以隔离

服务端异常时,SDK写失败后会重试,由于服务端异常,重试也未必能成功,继续重试,重试放大导致了线程数飙升。
评估下能否将重试逻辑放到单独的线程池中,避免服务端异常导致客户端流量无限放大,占用过多的线程资源。

it is necessary to remove the dependency to javafx

javafx.util.Pair is used in the sdk implementation. however, there is no reason for the sdk to depend on it.
the dependency on it might cause a runtime error because the javafx.util are only included in Oracle JDK and we cannot require the user deploy OracleJDK.

the runtime error is java.lang.ClassNotFoundException: javafx.util.Pair

package com.aliyun.hitsdb.client;

import com.aliyun.hitsdb.client.http.HttpClient;
import javafx.util.Pair;

public class HAPolicy {
    ....
}
package com.aliyun.hitsdb.client.value.response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.aliyun.hitsdb.client.value.request.ByteArrayValue;
import com.aliyun.hitsdb.client.value.request.ComplexValue;
import com.aliyun.hitsdb.client.value.request.GeoPointValue;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class MultiFieldQueryValuesSerializer implements ObjectSerializer, ObjectDeserializer {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.