protected String encodeBatch(List<RequestMetric> batch) {
        // TODO: calculate capacity more accurately
        StringBuilder sb = new StringBuilder(512 * batch.size());
        for (Iterator<RequestMetric> iterator = batch.iterator(); iterator.hasNext();) {
            RequestMetric metric = iterator.next();

            // Series name, followed by comma
            sb.append(options.getSeriesName()).append(",");

            // Default tags, comma delimited
            for (Entry<String, String> entry : defaultTags.entrySet()) {
                write(entry.getKey(), entry.getValue(), sb);
            }

            // Metric tags/metadata, comma delimited, space at end.
            // Apparently performance is better if we sort this alphabetically:
            //  https://docs.influxdata.com/influxdb/v2.3/write-data/best-practices/optimize-writes/#sort-tags-by-key
            write("apiId", quote(metric.getApiId()), sb);
            write("apiOrgId", quote(metric.getApiOrgId()), sb);
            write("apiVersion", quote(metric.getApiVersion()), sb);
            write("clientId", quote(metric.getClientId()), sb);
            write("clientOrgId", quote(metric.getClientOrgId()), sb);
            write("clientVersion", quote(metric.getClientVersion()), sb);
            write("contractId", quote(metric.getContractId()), sb);
            write("planId", quote(metric.getPlanId()), sb);
            write("user", quote(metric.getUser()), sb);

            sb.deleteCharAt(sb.length() - 1);
            sb.append(' ');

            // Data/variables, comma delimited, space at end.
            write("requestStart", dateToLong(metric.getRequestStart()), sb);
            write("requestEnd", dateToLong(metric.getRequestEnd()), sb);
            write("apiStart", dateToLong(metric.getApiStart()), sb);
            write("apiEnd", dateToLong(metric.getApiEnd()), sb);
            write("url", quote(metric.getUrl()), sb);
            write("resource", quote(metric.getResource()), sb);
            write("method", quote(metric.getMethod()), sb);
            write("responseCode", Integer.toString(metric.getResponseCode()), sb);
            write("responseMessage", quote(metric.getResponseMessage()), sb);
            write("failureCode", Integer.toString(metric.getFailureCode()), sb);
            write("failureReason", quote(metric.getFailureReason()), sb);
            write("error", Boolean.toString(metric.isError()), sb);
            write("errorMessage", quote(metric.getErrorMessage()), sb);

            sb.deleteCharAt(sb.length() - 1);
            sb.append(' ');

            sb.append(System.currentTimeMillis());

            if (iterator.hasNext()) {
                sb.append("\n");
            }
        }

        return sb.toString();
    }
Constructor.
@param config plugin configuration options
gateway/engine/influxdb/src/main/java/io/apiman/gateway/engine/influxdb/InfluxDbMetrics.java