noob-se7en commented on code in PR #18414:
URL: https://github.com/apache/pinot/pull/18414#discussion_r3182585011


##########
pinot-common/src/test/java/org/apache/pinot/common/metrics/prometheus/PrometheusTemplateRegexpTest.java:
##########
@@ -0,0 +1,283 @@
+/**
+ * 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.pinot.common.metrics.prometheus;
+
+import java.io.FileReader;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import java.util.stream.Collectors;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import org.yaml.snakeyaml.Yaml;
+
+
+/**
+ * Verifies that the Prometheus JMX template regexp patterns defined in the 
docker config YAML files
+ * are valid Java regexps and match expected JMX metric name strings with 
correct capture groups.
+ *
+ * Config files under test: 
docker/images/pinot/etc/jmx_prometheus_javaagent/configs/
+ *
+ * @see <a href="https://github.com/apache/pinot/issues/13588";>Issue #13588</a>
+ */
+public class PrometheusTemplateRegexpTest {
+
+  private static final String CONFIG_BASE_PATH =
+      "../docker/images/pinot/etc/jmx_prometheus_javaagent/configs";
+
+  @DataProvider(name = "configFiles")
+  public Object[][] configFiles() {
+    return new Object[][]{
+        {"broker.yml"},
+        {"server.yml"},
+        {"controller.yml"},
+        {"minion.yml"},
+        {"pinot.yml"}
+    };
+  }
+
+  /**
+   * Verifies every pattern in each YAML config file compiles as a valid Java 
regexp.
+   */
+  @Test(dataProvider = "configFiles")
+  public void testAllPatternsAreValidRegexp(String configFile)
+      throws Exception {
+    List<String> patterns = extractPatterns(CONFIG_BASE_PATH + "/" + 
configFile);
+    Assert.assertFalse(patterns.isEmpty(),
+        "Expected at least one rule pattern in " + configFile);
+    for (String patternStr : patterns) {
+      try {
+        Pattern.compile(patternStr);
+      } catch (PatternSyntaxException e) {
+        Assert.fail(
+            "Invalid regexp in " + configFile + ": [" + patternStr + "] - " + 
e.getDescription());
+      }
+    }
+  }
+
+  // ---- Broker patterns ----
+
+  /**
+   * broker.yml: meters/timers scoped to tableNameWithType.
+   * e.g. pinot.broker.myTable_REALTIME.queries
+   */
+  @Test
+  public void testBrokerTableWithTypeMeterPattern() {
+    String pattern = 
"\"?org\\.apache\\.pinot\\.common\\.metrics\"?<type=\"?\\w+\"?, "

Review Comment:
   the targeted tests duplicate each YAML pattern inline rather than loading it 
from the file under test. if someone edits the YAML pattern but not this file, 
the test keeps passing against the stale inline copy — which defeats the PR's 
stated goal of "validate the regexp patterns defined in the YAML." load the 
pattern from the rule (by index or by `name` field) and run the match assertion 
against that loaded value. `testAllPatternsAreValidRegexp` already does the 
YAML read; the targeted tests should reuse it.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to