Github user dbrinegar commented on a diff in the pull request: https://github.com/apache/flink/pull/4188#discussion_r124366697 --- Diff: flink-metrics/flink-metrics-statsd/src/main/java/org/apache/flink/metrics/statsd/StatsDReporter.java --- @@ -179,41 +254,130 @@ private String prefix(String ... names) { } } - private void send(final String name, final String value) { + private String buildStatsdLine(final String name, final String value, final String tags) { + Double number; try { - String formatted = String.format("%s:%s|g", name, value); - byte[] data = formatted.getBytes(StandardCharsets.UTF_8); - socket.send(new DatagramPacket(data, data.length, this.address)); + number = Double.parseDouble(value); + } + catch (NumberFormatException e) { + // quietly skip values like "n/a" + return ""; } - catch (IOException e) { - LOG.error("unable to send packet to statsd at '{}:{}'", address.getHostName(), address.getPort()); + if (number >= 0.) { + return String.format("%s:%s|g%s", name, value, tags != null ? tags : ""); + } else { + // quietly skip "unknowns" like lowWaterMark:-9223372036854775808, or JVM.Memory.NonHeap.Max:-1, or NaN + return ""; } } - @Override - public String filterCharacters(String input) { + private void send(final String name, final String value, final String tags) { + String formatted = buildStatsdLine(name, value, tags); + if (formatted.length() > 0) { + try { + byte[] data = formatted.getBytes(StandardCharsets.UTF_8); + socket.send(new DatagramPacket(data, data.length, this.address)); + } + catch (IOException e) { + LOG.error("unable to send packet to statsd at '{}:{}'", address.getHostName(), address.getPort()); + } + } + } + + /** + * dogstatsd names should: start with letter, uses ascii alphanumerics and underscore, separated by periods. + * Collapse runs of invalid characters into an underscore. Discard invalid prefix and suffix. + * Eg: ":::metric:::name:::" -> "metric_name" + */ + + private boolean isValidStatsdChar(char c) { + return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c == '_'); --- End diff -- Yeah that's a fair point. The thought here is to take an extremely limited set to maximize compatibility with collectors and timeseries databases, to avoid translation. I think if one were to make a compatibliity table you might find a few extra punctuation type characters, but I couldn't see how they changed the significance or meaning of the metrics, so landed on picking one commonly accepted non-period delimiter. The underbar is also guidance from datadog, for best practice with their systems. The metrics from Flink are super clean this way. Flink metric names seem to always be alpha and dots, the tag names are all alpha and underscore (eg `task_id`), so looks quite natural for the tag values to be alphanumeric + underscore. But yeah, is an arbitrary choice.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---