pg-yang commented on code in PR #9622: URL: https://github.com/apache/skywalking/pull/9622#discussion_r973197571
########## oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/vservice/VirtualCacheProcessor.java: ########## @@ -0,0 +1,158 @@ +/* + * 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.server.analyzer.provider.trace.parser.listener.vservice; + +import com.google.gson.Gson; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.skywalking.apm.network.common.v3.KeyStringValuePair; +import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject; +import org.apache.skywalking.apm.network.language.agent.v3.SpanLayer; +import org.apache.skywalking.apm.network.language.agent.v3.SpanObject; +import org.apache.skywalking.oap.server.analyzer.provider.AnalyzerModuleConfig; +import org.apache.skywalking.oap.server.analyzer.provider.trace.parser.SpanTags; +import org.apache.skywalking.oap.server.core.analysis.IDManager; +import org.apache.skywalking.oap.server.core.analysis.Layer; +import org.apache.skywalking.oap.server.core.analysis.TimeBucket; +import org.apache.skywalking.oap.server.core.config.NamingControl; +import org.apache.skywalking.oap.server.core.source.ServiceMeta; +import org.apache.skywalking.oap.server.core.source.Source; +import org.apache.skywalking.oap.server.core.source.VirtualCacheRead; +import org.apache.skywalking.oap.server.core.source.VirtualCacheSlowRead; +import org.apache.skywalking.oap.server.core.source.VirtualCacheSlowWrite; +import org.apache.skywalking.oap.server.core.source.VirtualCacheWrite; +import org.apache.skywalking.oap.server.library.util.StringUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +@Slf4j +@RequiredArgsConstructor +public class VirtualCacheProcessor implements VirtualServiceProcessor { + + private final NamingControl namingControl; + + private final AnalyzerModuleConfig config; + + private final List<Source> sourceList = new ArrayList<>(); + + @Override + public void prepareVSIfNecessary(SpanObject span, SegmentObject segmentObject) { + if (span.getSpanLayer() != SpanLayer.Cache) { + return; + } + Map<String, String> tags = span.getTagsList().stream() + .collect(Collectors.toMap(KeyStringValuePair::getKey, KeyStringValuePair::getValue)); + if (!(tags.containsKey(SpanTags.CACHE_KEY) && tags.containsKey(SpanTags.CACHE_OP) && tags.containsKey(SpanTags.CACHE_CMD) && tags.containsKey(SpanTags.CACHE_TYPE))) { + return; + } + String cacheType = tags.get(SpanTags.CACHE_TYPE).toLowerCase(); + String peer = span.getPeer(); + // peer is blank if it's a local span + if (StringUtil.isBlank(peer)) { + peer = tags.get(SpanTags.CACHE_TYPE) + "-local"; + } + long timeBucket = TimeBucket.getMinuteTimeBucket(span.getStartTime()); + String serviceName = namingControl.formatServiceName(peer); + int latency = (int) (span.getEndTime() - span.getStartTime()); + if (latency > 0) { + log.info("latency data : {}", new Gson().toJson(span)); + } + sourceList.add(parseServiceMeta(serviceName, timeBucket)); + String op = tags.get(SpanTags.CACHE_OP); + if ("write".equals(op)) { + sourceList.add(parseWriteMetrics(span, latency, serviceName, timeBucket)); + if (latency > config.getCacheWriteLatencyThresholdsAndWatcher().getThreshold(cacheType)) { + sourceList.add(parseSlowWrite(segmentObject, latency, serviceName, span, tags)); + } + } else if ("read".equals(op)) { + sourceList.add(parseReadMetrics(span, latency, serviceName, timeBucket)); + if (latency > config.getCacheReadLatencyThresholdsAndWatcher().getThreshold(cacheType)) { + sourceList.add(parseSlowRead(segmentObject, latency, serviceName, span, tags)); + } + } else { + log.warn("Illegal tag value :{} for 'cache.op' , only write/read would be accepted", op); Review Comment: I log this warning message when client send a span which contains op tag , but the value isn't read/write . After all , we only analyze read/write operation , And could not guarantee every plugin is correct , I think . ########## test/e2e-v2/cases/meter/meter-cases.yaml: ########## @@ -31,4 +31,50 @@ curl -s -XPOST http://${sender_host}:${sender_9093}/sendBatchMetrics > /dev/null; sleep 10; swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics linear --name=batch_test --instance-name=test-instance --service-name=test-service |yq e 'to_entries' - - expected: expected/metrics-has-value.yml \ No newline at end of file + expected: expected/metrics-has-value.yml + # virtual cache + - query: | + swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics linear --name=cache_read_resp_time --service-id=R3VhdmFDYWNoZS1sb2NhbA==.0 | yq e 'to_entries' - + expected: expected/metrics-has-value0.yml + - query: | + swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics linear --name=cache_read_sla --service-id=R3VhdmFDYWNoZS1sb2NhbA==.0 | yq e 'to_entries' - + expected: expected/metrics-has-value.yml + - query: | + swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics linear --name=cache_read_cpm --service-id=R3VhdmFDYWNoZS1sb2NhbA==.0 | yq e 'to_entries' - + expected: expected/metrics-has-value.yml + - query: | + swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql metrics multiple-linear --name=cache_read_percentile --service-id=R3VhdmFDYWNoZS1sb2NhbA==.0 | yq e 'to_entries | with(.[] ; .value=(.value | to_entries))' - + expected: expected/metrics-has-value-percentile.yml Review Comment: I think `Test ` should as possible as complete. In order to inspect a project ,`Test` should cover all code ideally such as unit test. ########## test/e2e-v2/cases/storage/storage-cases.yaml: ########## @@ -47,7 +47,7 @@ cases: - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls expected: expected/traces-list.yml # negative tags search: relationship should be logical AND instead of logical OR - - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --tags http.method=POST,http.status_code=200 + - query: swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --tags http.method=POST,http.status_code=200,iserror=true Review Comment: BTW I updated `SW_AGENT_JAVA_COMMIT` to the latest -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
