wu-sheng commented on a change in pull request #6495:
URL: https://github.com/apache/skywalking/pull/6495#discussion_r589142106



##########
File path: 
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/SampleFamily.java
##########
@@ -477,10 +447,74 @@ static RunningContext instance() {
                 .build();
         }
 
-        MeterEntity meterEntity;
+        private Map<MeterEntity, Sample[]> meterSamples = new HashMap<>();
 
         private HistogramType histogramType;
 
         private TimeUnit defaultHistogramBucketUnit;
     }
+
+    private static class InternalOps {
+
+        private static Sample[] left(List<Sample> samples, List<String> 
labelKeys) {
+            return samples.stream().map(s -> {
+                ImmutableMap<String, String> ll = ImmutableMap.<String, 
String>builder()
+                    .putAll(Maps.filterKeys(s.labels, key -> 
!labelKeys.contains(key)))
+                    .build();
+                return s.toBuilder().labels(ll).build();
+            }).toArray(Sample[]::new);
+        }
+
+        private static String dim(List<Sample> samples, List<String> 
labelKeys) {
+            String name = labelKeys.stream()
+                                   .map(k -> 
samples.get(0).labels.getOrDefault(k, ""))
+                                   .collect(Collectors.joining("."));
+            return CharMatcher.is('.').trimFrom(name);
+        }
+
+        private static MeterEntity buildMeterEntity(List<Sample> samples,
+                                                    EntityDescription 
entityDescription) {
+            switch (entityDescription.getScopeType()) {
+                case SERVICE:
+                    return MeterEntity.newService(InternalOps.dim(samples, 
entityDescription.getServiceKeys()));
+                case SERVICE_INSTANCE:
+                    return MeterEntity.newServiceInstance(
+                        InternalOps.dim(samples, 
entityDescription.getServiceKeys()),
+                        InternalOps.dim(samples, 
entityDescription.getInstanceKeys())
+                    );
+                case ENDPOINT:
+                    return MeterEntity.newEndpoint(
+                        InternalOps.dim(samples, 
entityDescription.getServiceKeys()),
+                        InternalOps.dim(samples, 
entityDescription.getEndpointKeys())
+                    );
+            }
+            return null;

Review comment:
       I prefer to throw exception here, rather than facing unexpected NPE one 
day.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to