Github user uce commented on a diff in the pull request: https://github.com/apache/flink/pull/3128#discussion_r97315450 --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/metrics/dump/MetricDumpSerialization.java --- @@ -64,122 +80,148 @@ private MetricDumpSerialization() { * @param gauges gauges to serialize * @param histograms histograms to serialize * @return byte array containing the serialized metrics - * @throws IOException */ - public byte[] serialize( + public MetricSerializationResult serialize( Map<Counter, Tuple2<QueryScopeInfo, String>> counters, Map<Gauge<?>, Tuple2<QueryScopeInfo, String>> gauges, Map<Histogram, Tuple2<QueryScopeInfo, String>> histograms, - Map<Meter, Tuple2<QueryScopeInfo, String>> meters) throws IOException { - - baos.reset(); - dos.writeInt(counters.size()); - dos.writeInt(gauges.size()); - dos.writeInt(histograms.size()); - dos.writeInt(meters.size()); + Map<Meter, Tuple2<QueryScopeInfo, String>> meters) { + + buffer.clear(); + int numCounters = 0; for (Map.Entry<Counter, Tuple2<QueryScopeInfo, String>> entry : counters.entrySet()) { - serializeMetricInfo(dos, entry.getValue().f0); - serializeString(dos, entry.getValue().f1); - serializeCounter(dos, entry.getKey()); + try { + serializeCounter(buffer, entry.getValue().f0, entry.getValue().f1, entry.getKey()); + numCounters++; + } catch (Exception e) { + LOG.warn("Failed to serialize counter.", e); + } } + int numGauges = 0; for (Map.Entry<Gauge<?>, Tuple2<QueryScopeInfo, String>> entry : gauges.entrySet()) { - serializeMetricInfo(dos, entry.getValue().f0); - serializeString(dos, entry.getValue().f1); - serializeGauge(dos, entry.getKey()); + try { + serializeGauge(buffer, entry.getValue().f0, entry.getValue().f1, entry.getKey()); + numGauges++; + } catch (Exception e) { + LOG.warn("Failed to serialize gauge.", e); + } } + int numHistograms = 0; for (Map.Entry<Histogram, Tuple2<QueryScopeInfo, String>> entry : histograms.entrySet()) { - serializeMetricInfo(dos, entry.getValue().f0); - serializeString(dos, entry.getValue().f1); - serializeHistogram(dos, entry.getKey()); + try { + serializeHistogram(buffer, entry.getValue().f0, entry.getValue().f1, entry.getKey()); + numHistograms++; + } catch (Exception e) { + LOG.warn("Failed to serialize histogram.", e); + } } + int numMeters = 0; for (Map.Entry<Meter, Tuple2<QueryScopeInfo, String>> entry : meters.entrySet()) { - serializeMetricInfo(dos, entry.getValue().f0); - serializeString(dos, entry.getValue().f1); - serializeMeter(dos, entry.getKey()); + try { + serializeMeter(buffer, entry.getValue().f0, entry.getValue().f1, entry.getKey()); + numMeters++; + } catch (Exception e) { + LOG.warn("Failed to serialize meter.", e); + } } - return baos.toByteArray(); + return new MetricSerializationResult(buffer.getCopyOfBuffer(), numCounters, numGauges, numMeters, numHistograms); --- End diff -- Empty line before return?
--- 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. ---