Skip to content

Commit

Permalink
Addressing comment by @alorlea: add accessors, use them in inherited …
Browse files Browse the repository at this point in the history
…class. This is cleaner.
  • Loading branch information
Mitchell Perilstein committed Sep 6, 2017
1 parent 1586ca4 commit 13ed8cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

import java.util.concurrent.TimeUnit;

import com.izettle.metrics.influxdb.data.InfluxDbWriteObject;
import com.izettle.metrics.influxdb.utils.InfluxDbWriteObjectSerializer;

/**
* Passthrough to ultimately select a different style of serializer: grouped fields on one influxdb protocol line,
* instead of one field per protocol line.
*/
public class GroupedInfluxDbHttpSender extends InfluxDbHttpSender {
private final String groupMeasurement;

public GroupedInfluxDbHttpSender(String protocol, String hostname, int port, String database, String authString,
TimeUnit timePrecision, int connectTimeout, int readTimeout, String measurementPrefix, String measurement) throws Exception {
super(protocol, hostname, port, database, authString, timePrecision, connectTimeout, readTimeout, measurementPrefix, measurement,
true);
TimeUnit timePrecision, int connectTimeout, int readTimeout, String measurementPrefix, String groupMeasurement) throws Exception {
super(protocol, hostname, port, database, authString, timePrecision, connectTimeout, readTimeout, measurementPrefix);
this.groupMeasurement = groupMeasurement;
}

@Override
public int writeData() throws Exception {
InfluxDbWriteObjectSerializer serializer = this.getSerializer();
InfluxDbWriteObject writeObject = this.getWriteObject();
String linestr = serializer.getGroupedLineProtocolString(writeObject, groupMeasurement);
final byte[] line = linestr.getBytes(UTF_8);
return super.writeData(line);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,10 @@ abstract class InfluxDbBaseSender implements InfluxDbSender {
static final Charset UTF_8 = StandardCharsets.UTF_8;
private final InfluxDbWriteObject influxDbWriteObject;
private final InfluxDbWriteObjectSerializer influxDbWriteObjectSerializer;
private final boolean groupedFields;
private final String measurement;

InfluxDbBaseSender(final String database, final TimeUnit timePrecision, final String measurementPrefix) {
this.influxDbWriteObject = new InfluxDbWriteObject(database, timePrecision);
this.influxDbWriteObjectSerializer = new InfluxDbWriteObjectSerializer(measurementPrefix);
this.groupedFields = false;
this.measurement = null;
}

InfluxDbBaseSender(final String database, final TimeUnit timePrecision, final String measurementPrefix,
final String measurement, final boolean groupedFields) {
this.influxDbWriteObject = new InfluxDbWriteObject(database, timePrecision);
this.influxDbWriteObjectSerializer = new InfluxDbWriteObjectSerializer(measurementPrefix);
this.groupedFields = groupedFields;
this.measurement = measurement;
}

@Override
Expand All @@ -53,9 +41,7 @@ public void appendPoints(InfluxDbPoint point) {

@Override
public int writeData() throws Exception {
String linestr = this.groupedFields
? influxDbWriteObjectSerializer.getGroupedLineProtocolString(influxDbWriteObject,measurement)
: influxDbWriteObjectSerializer.getLineProtocolString(influxDbWriteObject);
String linestr = influxDbWriteObjectSerializer.getLineProtocolString(influxDbWriteObject);
final byte[] line = linestr.getBytes(UTF_8);

return writeData(line);
Expand All @@ -74,4 +60,12 @@ public void setTags(Map<String, String> tags) {
public Map<String, String> getTags() {
return influxDbWriteObject.getTags();
}

protected InfluxDbWriteObject getWriteObject() {
return this.influxDbWriteObject;
}

protected InfluxDbWriteObjectSerializer getSerializer() {
return this.influxDbWriteObjectSerializer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ public class InfluxDbHttpSender extends InfluxDbBaseSender {
* @param timePrecision the time precision of the metrics
* @param connectTimeout the connect timeout
* @param connectTimeout the read timeout
* @param measurement common measurement for grouped fields case
* @throws Exception exception while creating the influxDb sender(MalformedURLException)
*/
public InfluxDbHttpSender(
final String protocol, final String hostname, final int port, final String database, final String authString,
final TimeUnit timePrecision, final int connectTimeout, final int readTimeout, final String measurementPrefix,
String measurement, final boolean groupedFields)
final TimeUnit timePrecision, final int connectTimeout, final int readTimeout, final String measurementPrefix)
throws Exception {
super(database, timePrecision, measurementPrefix, measurement, groupedFields);
super(database, timePrecision, measurementPrefix);

String endpoint = new URL(protocol, hostname, port, "/write").toString();
String queryDb = String.format("db=%s", URLEncoder.encode(database, "UTF-8"));
Expand All @@ -55,14 +53,6 @@ public InfluxDbHttpSender(
this.readTimeout = readTimeout;
}

public InfluxDbHttpSender(
final String protocol, final String hostname, final int port, final String database, final String authString,
final TimeUnit timePrecision, final int connectTimeout, final int readTimeout, final String measurementPrefix)
throws Exception {
this(protocol, hostname, port, database, authString, timePrecision, connectTimeout, readTimeout,
measurementPrefix, null, false);
}

@Deprecated
public InfluxDbHttpSender(
final String protocol, final String hostname, final int port, final String database, final String authString,
Expand Down

0 comments on commit 13ed8cb

Please sign in to comment.