wu-sheng commented on code in PR #13723: URL: https://github.com/apache/skywalking/pull/13723#discussion_r2883877347
########## oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/compiler/rt/MalRuntimeHelper.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.v2.compiler.rt; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.skywalking.oap.meter.analyzer.v2.dsl.Sample; +import org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily; +import org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamilyBuilder; + +/** + * Static helper methods called by v2-generated {@code MalExpression} classes. + * Keeps new runtime behaviour in the v2 compiler package, avoiding modifications + * to the shared {@link SampleFamily} class. + */ +public final class MalRuntimeHelper { + + private MalRuntimeHelper() { + } + + /** + * Groovy regex match ({@code =~}): returns a {@code String[][]} where each row is + * one match with group 0 (full match) and capture groups 1..N. + * Returns {@code null} if the pattern does not match, so that Groovy-style + * truthiness checks ({@code matcher ? matcher[0][1] : "unknown"}) work via null check. + */ + public static String[][] regexMatch(final String input, final String regex) { + if (input == null) { + return null; + } + final Matcher m = Pattern.compile(regex).matcher(input); Review Comment: MAL regex matching runs once per scrape interval (15s\u201360s), not on a hot loop. The v1 Groovy code also compiles patterns on each call. Caching would add complexity for negligible gain in this context. -- 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]
