-
Notifications
You must be signed in to change notification settings - Fork 128
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
Escaping issue with tag values #718
Comments
Hi @oliverrahner, Thank you for using our client and reaching out with your issue. To help us better understand and address the problem related to the Furthermore, if you have any improvements or fixes in mind, we encourage you to contribute. We welcome Pull Requests from our community and are always ready to review and integrate useful submissions. Thank you in advance for your cooperation and contribution. We look forward to resolving this together. Best Regards |
This test should contain it all: package de.dke.data.agrirouter.metricspump;
import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.InfluxDBClientOptions;
import com.influxdb.client.domain.WritePrecision;
import okhttp3.OkHttpClient;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
public class InfluxBugTest {
private final String influxUrl = "http://localhost:8086";
private final char[] influxToken = "6c751cea-e8dc-408a-be01-49d1fbbb02a3".toCharArray();
private final String influxOrg = "org";
private final String influxBucket = "test";
@Measurement(name = "metrics")
private class Metric {
@Column
private String id = "";
@Column(tag = true, name = "account.companyName")
private String companyName = "";
@Column(tag = true, name = "account.contactFirstName")
private String firstName = "";
@Column(tag = true, name = "account.contactLastName")
private String lastName = "";
@Column(timestamp = true)
private Instant createdOn = Instant.now();
}
@Test
void triggerInfluxBug() {
Metric metric = new Metric();
metric.id = "1";
metric.companyName = "\\";
metric.firstName = "\\";
metric.lastName = "\\";
metric.createdOn = Instant.now();
var okHttpClient = new OkHttpClient.Builder()
.readTimeout(1, TimeUnit.MINUTES);
var options = InfluxDBClientOptions.builder()
.url(influxUrl)
.authenticateToken(influxToken)
.okHttpClient(okHttpClient)
.org(influxOrg)
.bucket(influxBucket)
.build();
var influxDBClient = InfluxDBClientFactory.create(options);
if (!influxDBClient.ping()) {
throw new RuntimeException("Could not connect to InfluxDB");
}
influxDBClient.getWriteApiBlocking().writeMeasurement(WritePrecision.MS, metric);
}
} The exception is:
|
This issue occurs in our case because a user has entered specific meta data fields as just
\
.According to the Influx docs,
\
does not need to be escaped, but may be.In our case, however, the backslash is followed with a comma, because it is at the end of the tag value, followed by another tag value, leading to messed up interpretation of the whole record.
In my opinion, the safest way to handle this is to always escape backslashes.
Steps to reproduce:
List the minimal actions needed to reproduce the behavior.
List<>
with at least one tag containing just a backslash\
client.getWriteApiBlocking().writeMeasurements(WriteParameters.DEFAULT_WRITE_PRECISION, myList);
Expected behavior:
Data would be inserted correctly.
Actual behavior:
Influx returns:
HTTP status code: 400; Message: unable to parse 'metrics,account.companyName=\,account.contactCity=\ [...]
Specifications:
The text was updated successfully, but these errors were encountered: