|
28 | 28 | import java.util.List; |
29 | 29 | import java.util.Map; |
30 | 30 | import java.util.TreeMap; |
31 | | -import java.util.regex.Matcher; |
32 | | -import java.util.regex.Pattern; |
33 | 31 | import java.util.stream.Collectors; |
34 | 32 | import com.google.common.collect.ImmutableMap; |
35 | 33 | import org.apache.skywalking.oap.server.core.analysis.meter.MeterEntity; |
@@ -95,12 +93,6 @@ static void teardownK8sMocks() { |
95 | 93 | } |
96 | 94 | } |
97 | 95 |
|
98 | | - private static final Pattern TAG_EQUAL_PATTERN = |
99 | | - Pattern.compile("\\.tagEqual\\s*\\(\\s*'([^']+)'\\s*,\\s*'([^']+)'\\s*\\)"); |
100 | | - |
101 | | - private static final String[] HISTOGRAM_LE_VALUES = |
102 | | - {"50", "100", "250", "500", "1000"}; |
103 | | - |
104 | 96 | /** Advance by 2 s per call — must be >1 s (for timeDiff/1000≥1) and <15 s (smallest rate window). */ |
105 | 97 | private long timestampCounter = System.currentTimeMillis(); |
106 | 98 |
|
@@ -193,7 +185,7 @@ private void executeExpression( |
193 | 185 | return; |
194 | 186 | } |
195 | 187 | } |
196 | | - executeWithAutoData(metricName, rule.getFullExpression(), v2MalExpr, v2Meta); |
| 188 | + // No .data.yaml input — compile-only validation |
197 | 189 | } |
198 | 190 |
|
199 | 191 | // ==================== Input-driven runtime execution ==================== |
@@ -462,118 +454,6 @@ private Map<String, org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily |
462 | 454 | return data; |
463 | 455 | } |
464 | 456 |
|
465 | | - // ==================== Auto-generated mock data (fallback) ==================== |
466 | | - |
467 | | - private void executeWithAutoData( |
468 | | - final String metricName, |
469 | | - final String expression, |
470 | | - final org.apache.skywalking.oap.meter.analyzer.v2.dsl.MalExpression v2MalExpr, |
471 | | - final ExpressionMetadata v2Meta) { |
472 | | - final boolean hasIncrease = expression.contains(".increase(") |
473 | | - || expression.contains(".rate("); |
474 | | - |
475 | | - // For increase()/rate(), prime then build real data consecutively |
476 | | - // so that prime→real has a consistent 2 s delta. |
477 | | - final Map<String, org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily> v2Data; |
478 | | - if (hasIncrease) { |
479 | | - try { |
480 | | - final Map<String, org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily> primeData = |
481 | | - buildV2MockData(metricName, expression, v2Meta, 0.5); |
482 | | - for (final org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily s : primeData.values()) { |
483 | | - if (s != org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily.EMPTY) { |
484 | | - s.context.setMetricName(metricName); |
485 | | - } |
486 | | - } |
487 | | - v2MalExpr.run(primeData); |
488 | | - } catch (Exception ignored) { |
489 | | - } |
490 | | - } |
491 | | - v2Data = buildV2MockData(metricName, expression, v2Meta, 1.0); |
492 | | - |
493 | | - // V2 run |
494 | | - org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily v2Sf; |
495 | | - try { |
496 | | - for (final org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily s : v2Data.values()) { |
497 | | - if (s != org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily.EMPTY) { |
498 | | - s.context.setMetricName(metricName); |
499 | | - } |
500 | | - } |
501 | | - v2Sf = v2MalExpr.run(v2Data); |
502 | | - } catch (Exception e) { |
503 | | - fail(metricName + ": v2 runtime failed — " |
504 | | - + e.getClass().getSimpleName() + ": " + e.getMessage()); |
505 | | - return; |
506 | | - } |
507 | | - |
508 | | - // Must succeed |
509 | | - final boolean v2Success = v2Sf != null |
510 | | - && v2Sf != org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily.EMPTY; |
511 | | - assertTrue(v2Success, |
512 | | - metricName + ": v2 returned EMPTY"); |
513 | | - } |
514 | | - |
515 | | - // ==================== V2 mock data (.v2. packages) ==================== |
516 | | - |
517 | | - private Map<String, org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily> buildV2MockData( |
518 | | - final String metricName, final String expression, |
519 | | - final ExpressionMetadata meta, final double valueScale) { |
520 | | - final Map<String, org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily> data = |
521 | | - new HashMap<>(); |
522 | | - final long now = timestampCounter; |
523 | | - timestampCounter += 2_000; |
524 | | - final Map<String, String> tagEqualLabels = extractTagEqualLabels(expression); |
525 | | - |
526 | | - for (final String sampleName : meta.getSamples()) { |
527 | | - final Map<String, String> labels = new HashMap<>(); |
528 | | - for (final String label : meta.getScopeLabels()) { |
529 | | - labels.put(label, inferLabelValue(label, tagEqualLabels)); |
530 | | - } |
531 | | - for (final String label : meta.getAggregationLabels()) { |
532 | | - labels.put(label, inferLabelValue(label, tagEqualLabels)); |
533 | | - } |
534 | | - labels.putAll(tagEqualLabels); |
535 | | - |
536 | | - if (meta.isHistogram()) { |
537 | | - data.put(sampleName, buildV2HistogramSamples( |
538 | | - sampleName, labels, now, valueScale)); |
539 | | - } else { |
540 | | - final org.apache.skywalking.oap.meter.analyzer.v2.dsl.Sample sample = |
541 | | - org.apache.skywalking.oap.meter.analyzer.v2.dsl.Sample.builder() |
542 | | - .name(sampleName) |
543 | | - .labels(ImmutableMap.copyOf(labels)) |
544 | | - .value(100.0 * valueScale) |
545 | | - .timestamp(now) |
546 | | - .build(); |
547 | | - data.put(sampleName, |
548 | | - org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamilyBuilder |
549 | | - .newBuilder(sample).build()); |
550 | | - } |
551 | | - } |
552 | | - return data; |
553 | | - } |
554 | | - |
555 | | - private org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamily buildV2HistogramSamples( |
556 | | - final String sampleName, final Map<String, String> baseLabels, |
557 | | - final long timestamp, final double valueScale) { |
558 | | - final List<org.apache.skywalking.oap.meter.analyzer.v2.dsl.Sample> samples = |
559 | | - new ArrayList<>(); |
560 | | - double cumulativeValue = 0; |
561 | | - for (final String le : HISTOGRAM_LE_VALUES) { |
562 | | - cumulativeValue += 10.0 * valueScale; |
563 | | - final Map<String, String> labels = new HashMap<>(baseLabels); |
564 | | - labels.put("le", le); |
565 | | - samples.add(org.apache.skywalking.oap.meter.analyzer.v2.dsl.Sample.builder() |
566 | | - .name(sampleName) |
567 | | - .labels(ImmutableMap.copyOf(labels)) |
568 | | - .value(cumulativeValue) |
569 | | - .timestamp(timestamp) |
570 | | - .build()); |
571 | | - } |
572 | | - return org.apache.skywalking.oap.meter.analyzer.v2.dsl.SampleFamilyBuilder.newBuilder( |
573 | | - samples.toArray( |
574 | | - new org.apache.skywalking.oap.meter.analyzer.v2.dsl.Sample[0])).build(); |
575 | | - } |
576 | | - |
577 | 457 | // ==================== Helpers ==================== |
578 | 458 |
|
579 | 459 | private static String describeEntity(final MeterEntity entity) { |
@@ -615,50 +495,6 @@ private static org.apache.skywalking.oap.meter.analyzer.v2.dsl.Sample[] sortV2Sa |
615 | 495 | return sorted; |
616 | 496 | } |
617 | 497 |
|
618 | | - private static Map<String, String> extractTagEqualLabels(final String expression) { |
619 | | - final Map<String, String> labels = new HashMap<>(); |
620 | | - final Matcher matcher = TAG_EQUAL_PATTERN.matcher(expression); |
621 | | - while (matcher.find()) { |
622 | | - labels.put(matcher.group(1), matcher.group(2)); |
623 | | - } |
624 | | - return labels; |
625 | | - } |
626 | | - |
627 | | - private static String inferLabelValue(final String label, |
628 | | - final Map<String, String> tagEqualLabels) { |
629 | | - if (tagEqualLabels.containsKey(label)) { |
630 | | - return tagEqualLabels.get(label); |
631 | | - } |
632 | | - switch (label) { |
633 | | - case "service": |
634 | | - return "test-service"; |
635 | | - case "instance": |
636 | | - case "service_instance_id": |
637 | | - return "test-instance"; |
638 | | - case "endpoint": |
639 | | - return "/test"; |
640 | | - case "host_name": |
641 | | - return "test-host"; |
642 | | - case "le": |
643 | | - return "100"; |
644 | | - case "job_name": |
645 | | - return "mysql-monitoring"; |
646 | | - case "cluster": |
647 | | - return "test-cluster"; |
648 | | - case "node": |
649 | | - case "node_id": |
650 | | - return "test-node"; |
651 | | - case "topic": |
652 | | - return "test-topic"; |
653 | | - case "queue": |
654 | | - return "test-queue"; |
655 | | - case "broker": |
656 | | - return "test-broker"; |
657 | | - default: |
658 | | - return "test-value"; |
659 | | - } |
660 | | - } |
661 | | - |
662 | 498 | // ==================== YAML loading ==================== |
663 | 499 |
|
664 | 500 | private Map<String, List<MalTestRule>> loadAllMalYamlFiles() throws Exception { |
|
0 commit comments