[metrics_center] Filter out host_name, load_avg and caches keys from context for MetricPoint generation (#515)
diff --git a/packages/metrics_center/CHANGELOG.md b/packages/metrics_center/CHANGELOG.md
index 396a921..3a7222a 100644
--- a/packages/metrics_center/CHANGELOG.md
+++ b/packages/metrics_center/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.0.3
+
+- Filter out host_name, load_avg and caches keys from context
+ before adding to a MetricPoint object.
+
## 1.0.2
- Updated the GoogleBenchmark parser to correctly parse new keys added
diff --git a/packages/metrics_center/lib/src/google_benchmark.dart b/packages/metrics_center/lib/src/google_benchmark.dart
index f447ce4..809f903 100644
--- a/packages/metrics_center/lib/src/google_benchmark.dart
+++ b/packages/metrics_center/lib/src/google_benchmark.dart
@@ -28,6 +28,14 @@
'big_o',
];
+// Context has some keys such as 'host_name' which need to be ignored
+// so that we can group series together
+const List<String> _kContextIgnoreKeys = <String>[
+ 'host_name',
+ 'load_avg',
+ 'caches',
+];
+
// ignore: avoid_classes_with_only_static_members
/// Parse the json result of https://github.com/google/benchmark.
class GoogleBenchmarkParser {
@@ -41,7 +49,8 @@
jsonResult['context'] as Map<String, dynamic>;
final Map<String, String> context = rawContext.map<String, String>(
(String k, dynamic v) => MapEntry<String, String>(k, v.toString()),
- );
+ )..removeWhere((String k, String v) => _kContextIgnoreKeys.contains(k));
+
final List<MetricPoint> points = <MetricPoint>[];
for (final dynamic item in jsonResult['benchmarks']) {
_parseAnItem(item as Map<String, dynamic>, points, context);
diff --git a/packages/metrics_center/pubspec.yaml b/packages/metrics_center/pubspec.yaml
index 036edd7..8e74415 100644
--- a/packages/metrics_center/pubspec.yaml
+++ b/packages/metrics_center/pubspec.yaml
@@ -1,5 +1,5 @@
name: metrics_center
-version: 1.0.2
+version: 1.0.3
description:
Support multiple performance metrics sources/formats and destinations.
repository: https://github.com/flutter/packages/tree/master/packages/metrics_center
diff --git a/packages/metrics_center/test/google_benchmark_test.dart b/packages/metrics_center/test/google_benchmark_test.dart
index 2bab97b..7dad807 100644
--- a/packages/metrics_center/test/google_benchmark_test.dart
+++ b/packages/metrics_center/test/google_benchmark_test.dart
@@ -35,5 +35,11 @@
'SkParagraphFixture/TextBigO_BigO',
],
);
+ for (final MetricPoint p in points) {
+ expect(p.tags.containsKey('host_name'), false);
+ expect(p.tags.containsKey('load_avg'), false);
+ expect(p.tags.containsKey('caches'), false);
+ expect(p.tags.containsKey('executable'), true);
+ }
});
}