Skip to content

Commit 0ca3df2

Browse files
authored
Merge pull request #120 from retronym/topic/influx-client-bump-and-migrate-java-version
2 parents 12ab908 + 5581395 commit 0ca3df2

File tree

3 files changed

+15
-34
lines changed

3 files changed

+15
-34
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ lazy val infrastructure = addJmh(project).settings(
3939
autoScalaLibrary := false,
4040
crossPaths := false,
4141
libraryDependencies ++= Seq(
42-
"org.influxdb" % "influxdb-java" % "2.5", // TODO update to 2.6 when released for fix for https://github.com/influxdata/influxdb-java/issues/269
42+
"org.influxdb" % "influxdb-java" % "2.21",
4343
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.6.0.201612231935-r",
4444
"com.google.guava" % "guava" % "21.0",
4545
"org.apache.commons" % "commons-lang3" % "3.5",

infrastructure/src/main/java/scala/bench/DataMigrator.java

+13-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.influxdb.dto.Point;
66
import org.influxdb.dto.Query;
77
import org.influxdb.dto.QueryResult;
8+
import org.influxdb.impl.TimeUtil;
89

910
import java.time.Instant;
1011
import java.util.*;
@@ -31,39 +32,32 @@ public static void main(String[] args) {
3132
//time written
3233
//---- -------
3334
//0 14076
34-
String oldMeasure = "result_backup_20210519";
35+
String oldMeasure = "result_backup_20210525";
3536
String newMeasure = "result";
36-
3737
QueryResult queryResult = influxDB.query(new Query("select * from " + oldMeasure + " group by *", "scala_benchmark"));
3838
for (QueryResult.Result result : queryResult.getResults()) {
3939
for (QueryResult.Series series : result.getSeries()) {
40-
List<String> newFieldNames = new ArrayList<>(series.getColumns());
41-
int javaVersionIndex = newFieldNames.indexOf(JAVA_VERSION_TAG_NAME);
42-
newFieldNames.remove(javaVersionIndex);
43-
assert (newFieldNames.get(0).equals("time"));
44-
newFieldNames.remove(0);
4540
Point.Builder builder = Point.measurement(newMeasure);
4641
Map<String, String> newTags = new HashMap<>(series.getTags());
42+
String javaVersion = newTags.get(JAVA_VERSION_TAG_NAME);
43+
if (javaVersion.equals("1.8.0_131-b11")) {
44+
newTags.put(JAVA_VERSION_TAG_NAME, "1.8.0_131");
45+
}
46+
47+
assert (series.getValues().size() == 1);
4748
List<Object> newValues = new ArrayList<>(series.getValues().get(0));
48-
Object removed = newValues.remove(javaVersionIndex);
49-
String time = (String) newValues.remove(0);
50-
newTags.put(JAVA_VERSION_TAG_NAME, (String) removed);
51-
newTags.entrySet().removeIf(x -> x.getValue() == null || x.getValue().equals(""));
5249
builder.tag(newTags);
50+
51+
List<String> newFieldNames = new ArrayList<>(series.getColumns());
5352
LinkedHashMap<String, Object> newFieldsMap = new LinkedHashMap<>();
5453
assert (newFieldNames.size() == newValues.size());
5554
for (int i = 0; i < newFieldNames.size(); i++) {
5655
String fieldName = newFieldNames.get(i);
57-
boolean isLong = fieldName.equals("sampleCount");
58-
if (isLong) {
59-
newFieldsMap.put(fieldName, ((Number) newValues.get(i)).longValue());
60-
} else {
61-
newFieldsMap.put(fieldName, newValues.get(i));
62-
}
56+
newFieldsMap.put(fieldName, newValues.get(i));
6357
}
6458
builder.fields(newFieldsMap);
65-
Instant parse = Instant.parse(time);
66-
builder.time(parse.toEpochMilli(), TimeUnit.MILLISECONDS);
59+
long epochMillis = (long) newValues.remove(0) / 1000L / 1000L;
60+
builder.time(epochMillis, TimeUnit.MILLISECONDS);
6761
Point point = builder.build();
6862
batchPoints.point(point);
6963
}

infrastructure/src/main/java/scala/bench/Database.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,7 @@ public static InfluxDB connectDb() {
3030
client.connectTimeout(10, TimeUnit.SECONDS);
3131
client.readTimeout(120, TimeUnit.SECONDS);
3232
client.writeTimeout(120, TimeUnit.SECONDS);
33-
34-
// workaround https://github.com/influxdata/influxdb-java/issues/268
35-
client.addNetworkInterceptor(chain -> {
36-
HttpUrl.Builder fixedUrl = chain.request().url().newBuilder().encodedPath("/influx/" + chain.request().url().encodedPath().replaceFirst("/influxdb", ""));
37-
return chain.proceed(chain.request().newBuilder().url(fixedUrl.build()).build());
38-
});
39-
40-
client.authenticator((route, response) -> {
41-
String credential = Credentials.basic(influxUser, influxPassword);
42-
return response.request().newBuilder()
43-
.header("Authorization", credential)
44-
.build();
45-
});
46-
InfluxDB influxDB = InfluxDBFactory.connect(influxUrl, influxUser, influxPassword, client);
33+
InfluxDB influxDB = InfluxDBFactory.connect(influxUrl, influxUser, influxPassword, client, InfluxDB.ResponseFormat.MSGPACK);
4734
// influxDB.setLogLevel(InfluxDB.LogLevel.FULL);
4835
return influxDB;
4936
}

0 commit comments

Comments
 (0)