wankai123 commented on a change in pull request #6495: URL: https://github.com/apache/skywalking/pull/6495#discussion_r589188413
########## File path: oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/EntityDescription/InstanceEntityDescription.java ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.meter.analyzer.dsl.EntityDescription; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.skywalking.oap.server.core.analysis.meter.ScopeType; + +public class InstanceEntityDescription implements EntityDescription { Review comment: done ########## 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: done ---------------------------------------------------------------- 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]
