apache / hertzbeat

Apache HertzBeat(incubating) is a real-time monitoring system with agentless, performance cluster, prometheus-compatible, custom monitoring and status page building capabilities.
https://hertzbeat.apache.org/
Apache License 2.0
5.46k stars 947 forks source link

[BUG] <title>AlarmCommonReduce throw exception `UnsupportedOperationException` #2411

Closed yuluo-yx closed 1 month ago

yuluo-yx commented 1 month ago
    public void reduceAndSendAlarm(Alert alert) {
        alert.setTimes(1);
        Map<String, String> tags = alert.getTags();
        if (tags == null) {
            tags = new HashMap<>(8);
            alert.setTags(tags);
        }

        System.out.println("确认 tag 是否可以修改:");
        System.out.println("原有 tags + " + tags);
        System.out.println("===========================");
        System.out.println("tags 添加值 1 1 :");
        tags.put("1", "1");
        System.out.println("===========================");
        System.out.println("测试结束");

        String monitorIdStr = tags.get(CommonConstants.TAG_MONITOR_ID);
        if (monitorIdStr == null) {
            log.debug("receiver extern alarm message: {}", alert);
        } else {

output:

Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
确认 tag 是否可以修改:
原有 tags + {monitorId=123}
===========================
tags 添加值 1 1 :

java.lang.UnsupportedOperationException
    at java.base/java.util.ImmutableCollections.uoe(ImmutableCollections.java:142)
    at java.base/java.util.ImmutableCollections$AbstractImmutableMap.put(ImmutableCollections.java:1072)
    at org.apache.hertzbeat.alert.reduce.AlarmCommonReduce.reduceAndSendAlarm(AlarmCommonReduce.java:60)
    at org.apache.hertzbeat.alert.reduce.AlarmCommonReduceTest.testReduceAndSendAlarmWithMonitorId(AlarmCommonReduceTest.java:108)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
yuluo-yx commented 1 month ago

image

this issue from lombok @Data generated setter method. it is immutable collection