• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trydofor / professional-wings / #147

27 Mar 2025 10:59AM UTC coverage: 63.656% (-0.3%) from 63.978%
#147

push

trydofor
🐛 justauth modify AuthConfig #337

19 of 44 new or added lines in 4 files covered. (43.18%)

37 existing lines in 3 files now uncovered.

12940 of 20328 relevant lines covered (63.66%)

0.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.12
/wings/slardar/src/main/java/pro/fessional/wings/slardar/monitor/MonitorTask.java
1
package pro.fessional.wings.slardar.monitor;
2

3
import lombok.Getter;
4
import lombok.Setter;
5
import lombok.extern.slf4j.Slf4j;
6
import org.springframework.beans.factory.DisposableBean;
7
import org.springframework.beans.factory.InitializingBean;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.scheduling.annotation.Scheduled;
10
import pro.fessional.mirana.stat.JvmStat;
11
import pro.fessional.wings.silencer.spring.help.ApplicationContextHelper;
12
import pro.fessional.wings.slardar.context.Now;
13

14
import java.util.Collections;
15
import java.util.LinkedHashMap;
16
import java.util.List;
17
import java.util.Map;
18

19
/**
20
 * @author trydofor
21
 * @since 2021-07-14
22
 */
23
@Slf4j
1✔
24
@Setter @Getter
25
public class MonitorTask implements InitializingBean, DisposableBean {
1✔
26

27
    @Setter(onMethod_ = { @Autowired })
1✔
28
    private List<WarnMetric> warnMetrics = Collections.emptyList();
1✔
29

30
    @Setter(onMethod_ = { @Autowired })
1✔
31
    private List<WarnReport> warnReports = Collections.emptyList();
1✔
32

33
    @Setter(onMethod_ = { @Autowired(required = false) })
1✔
34
    private List<WarnFilter> warnFilters = Collections.emptyList();
1✔
35

36
    private String applicationName = null;
1✔
37
    private boolean hookSelf = true;
1✔
38

39
    @Scheduled(cron = "${wings.slardar.monitor.cron}")
40
    public void run() {
UNCOV
41
        log.info("MonitorTask started");
×
UNCOV
42
        Map<String, List<WarnMetric.Warn>> warns = new LinkedHashMap<>();
×
UNCOV
43
        metric(warns);
×
UNCOV
44
        filter(warns);
×
UNCOV
45
        report(warns);
×
UNCOV
46
    }
×
47

48
    public void metric(Map<String, List<WarnMetric.Warn>> warns) {
UNCOV
49
        for (WarnMetric metric : warnMetrics) {
×
UNCOV
50
            final String nm = metric.getKey();
×
51
            try {
UNCOV
52
                final List<WarnMetric.Warn> wn = metric.check();
×
UNCOV
53
                final int sz = wn.size();
×
UNCOV
54
                if (sz > 0) {
×
55
                    warns.put(nm, wn);
×
56
                }
UNCOV
57
                log.debug("check {} warns by {}", sz, nm);
×
58
            }
59
            catch (Exception e) {
×
60
                // noinspection StringConcatenationArgumentToLogCall
61
                log.warn("failed to metric, name=" + nm, e);
×
UNCOV
62
            }
×
UNCOV
63
        }
×
UNCOV
64
    }
×
65

66
    private void filter(Map<String, List<WarnMetric.Warn>> warns) {
UNCOV
67
        for (WarnFilter filter : warnFilters) {
×
UNCOV
68
            filter.filter(warns);
×
UNCOV
69
        }
×
UNCOV
70
    }
×
71

72
    public void report(Map<String, List<WarnMetric.Warn>> warns) {
73
        if (warnReports.isEmpty()) return;
1✔
74

75
        final String app = applicationName != null ? applicationName : ApplicationContextHelper.getApplicationName();
1✔
76
        if (app.isBlank()) {
1✔
77
            log.warn("the app name of report should NOT blank");
1✔
78
        }
79

80
        String jvm = JvmStat.jvmName();
1✔
81
        if (jvm != null) jvm = jvm.replace("@", "_");
1✔
82

83
        for (WarnReport report : warnReports) {
1✔
84
            final String rpt = report.getClass().getName();
1✔
85
            try {
86
                log.debug("report {} warns by {}", warns.size(), rpt);
1✔
87
                final WarnReport.Sts sts = report.report(app, jvm, warns);
1✔
88
                if (sts == WarnReport.Sts.Fail) {
1✔
89
                    log.warn("failed to report={}", rpt);
1✔
90
                }
91
                else {
92
                    log.info("report={}, status={}", rpt, sts);
1✔
93
                }
94
            }
95
            catch (Exception e) {
×
96
                // noinspection StringConcatenationArgumentToLogCall
97
                log.warn("failed to report, name=" + rpt, e);
×
98
            }
1✔
99
        }
1✔
100
    }
1✔
101

102
    @Override
103
    public void destroy() {
104
        reportHook("shutting");
1✔
105
    }
1✔
106

107
    @Override
108
    public void afterPropertiesSet() {
109
        reportHook("started");
1✔
110
    }
1✔
111

112
    private void reportHook(String key) {
113
        if (!hookSelf) return;
1✔
114

115
        try {
116
            WarnMetric.Warn wn = new WarnMetric.Warn();
1✔
117
            wn.setType(WarnMetric.Type.Text);
1✔
118
            wn.setKey(key);
1✔
119
            wn.setRule("time");
1✔
120
            wn.setWarn(Now.zonedDateTime().toString());
1✔
121
            List<WarnMetric.Warn> ws = Collections.singletonList(wn);
1✔
122
            final Map<String, List<WarnMetric.Warn>> warns = Collections.singletonMap("wings.slardar.monitor.hook", ws);
1✔
123
            report(warns);
1✔
124
        }
125
        catch (Exception e) {
×
126
            // ignore
127
        }
1✔
128
    }
1✔
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc