Skip to content

Commit

Permalink
[#9280] Matching rules have been improved
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Oct 19, 2022
1 parent 0576c69 commit bc17fa3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
* @author minwoo.jung
*/
public enum MatchingRule {
EXACT(1, "exact"),
CONTAIN(2, "contain"),
ALL(3, "all"),
UNKNOWN(100, "unknown");
// only one
EXACT_ONE(1, "exact_one"),
ANY_ONE(2, "any_one"),

//multi
CONTAIN(100, "contain"),
ALL(200, "all"),


UNKNOWN(999, "unknown");

private final int code;
private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -96,15 +97,35 @@ public List<MetricTag> getTag(MetricDataSearchKey metricDataSearchKey, Field fie
MatchingRule matchingRule = field.getMatchingRule();

switch (matchingRule) {
case EXACT :
case EXACT_ONE:
return getExactMatchingTag(metricDataSearchKey, field);
case ANY_ONE:
return getAnyOneTag(metricDataSearchKey, field);
case ALL :
return createTag(metricDataSearchKey, field, tags);
default :
throw new UnsupportedOperationException("unsupported matchingRule:" + matchingRule);
}
}

private List<MetricTag> getAnyOneTag(MetricDataSearchKey metricDataSearchKey, Field field) {
MetricTagKey metricTagKey = new MetricTagKey(metricDataSearchKey.getHostGroupName(), metricDataSearchKey.getHostName(), metricDataSearchKey.getMetricName(), field.getName(), getSaveTime());
MetricTagCollection metricTagCollection = systemMetricHostInfoDao.selectMetricTagCollection(metricTagKey);

List<MetricTag> metricTagList = metricTagCollection.getMetricTagList();
List<MetricTag> anyOneTag = new ArrayList<>();

if (metricTagList.size() != 1) {
return Collections.emptyList();
}

MetricTag metricTag = metricTagList.get(0);
anyOneTag.add(metricTag.copy());

return anyOneTag;

}

private List<MetricTag> createTag(MetricDataSearchKey metricDataSearchKey, Field field, List<Tag> tags) {
if (tags == null || tags.isEmpty()) {
return allMatchingTag(metricDataSearchKey, field);
Expand Down Expand Up @@ -139,7 +160,7 @@ private List<MetricTag> getExactMatchingTag(MetricDataSearchKey metricDataSearch
continue;
}
if (collectedTagList.containsAll(tagList)) {
exactMetricTagList.add(metricTag);
exactMetricTagList.add(metricTag.copy());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ mappings:
- name: "usage_user"
tags:
- { name: "cpu", value: "cpu-total" }
matchingRule: EXACT
matchingRule: EXACT_ONE
- name: "usage_system"
tags:
- { name: "cpu", value: "cpu-total" }
matchingRule: EXACT
matchingRule: EXACT_ONE
- name: "usage_idle"
tags:
- { name: "cpu", value: "cpu-total" }
matchingRule: EXACT
matchingRule: EXACT_ONE

- definitionId: "memoryPercent"
name: "mem"
Expand All @@ -25,7 +25,7 @@ mappings:
unit: "percent"
fields:
- name: "used_percent"
matchingRule: EXACT
matchingRule: EXACT_ONE

- definitionId: "memoryUsage"
name: "mem"
Expand All @@ -34,9 +34,9 @@ mappings:
unit: "byte"
fields:
- name: "total"
matchingRule: EXACT
matchingRule: EXACT_ONE
- name: "used"
matchingRule: EXACT
matchingRule: EXACT_ONE

- definitionId: "diskUsage"
name: "disk"
Expand Down Expand Up @@ -78,11 +78,11 @@ mappings:
unit: "percent"
fields:
- name: "load1"
matchingRule: EXACT
matchingRule: EXACT_ONE
- name: "load5"
matchingRule: EXACT
matchingRule: EXACT_ONE
- name: "load15"
matchingRule: EXACT
matchingRule: EXACT_ONE

- definitionId: "swap"
name: "swap"
Expand All @@ -91,6 +91,28 @@ mappings:
unit: "count"
fields:
- name: "total"
matchingRule: EXACT
matchingRule: EXACT_ONE
- name: "used"
matchingRule: EXACT
matchingRule: EXACT_ONE

- definitionId: "apacheWorker"
name: "apache"
title: "apache Worker"
grouping: "TAG"
unit: "count"
fields:
- name: "BusyWorkers"
matchingRule: ANY_ONE
- name: "IdleWorkers"
matchingRule: ANY_ONE

- definitionId: "nginxActive"
name: "nginx"
title: "nginx active/waiting"
grouping: "TAG"
unit: "count"
fields:
- name: "active"
matchingRule: ANY_ONE
- name: "waiting"
matchingRule: ANY_ONE

0 comments on commit bc17fa3

Please sign in to comment.