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

Hyshmily / hotkey / 28735434673

05 Jul 2026 08:55AM UTC coverage: 90.421% (+0.02%) from 90.4%
28735434673

push

github

Hyshmily
perf : simplify the code

Signed-off-by: Hyshmily <cxm8607@outlook.com>

1295 of 1498 branches covered (86.45%)

Branch coverage included in aggregate %.

121 of 134 new or added lines in 11 files covered. (90.3%)

2 existing lines in 1 file now uncovered.

3689 of 4014 relevant lines covered (91.9%)

4.19 hits per line

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

88.24
/common/src/main/java/io/github/hyshmily/hotkey/autoconfigure/HotKeyActuatorAutoConfiguration.java
1
/*
2
 * Copyright 2026 Hyshmily. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.hyshmily.hotkey.autoconfigure;
17

18
import com.github.benmanes.caffeine.cache.Cache;
19
import io.github.hyshmily.hotkey.Internal;
20
import io.github.hyshmily.hotkey.cache.cachesupport.CacheExpireManager;
21
import io.github.hyshmily.hotkey.cache.cachesupport.SingleFlight;
22
import io.github.hyshmily.hotkey.detection.HotKeyStateMachine;
23
import io.github.hyshmily.hotkey.endpoint.HotKeyEndpoint;
24
import io.github.hyshmily.hotkey.endpoint.RingEndpoint;
25
import io.github.hyshmily.hotkey.endpoint.StateMachineEndpoint;
26
import io.github.hyshmily.hotkey.hotkeydetector.heavykeeper.TopK;
27
import io.github.hyshmily.hotkey.reporting.HotKeyReporter;
28
import io.github.hyshmily.hotkey.rule.RuleMatcher;
29
import io.github.hyshmily.hotkey.sharding.ClusterHealthView;
30
import io.github.hyshmily.hotkey.sharding.RingManager;
31
import io.github.hyshmily.hotkey.sync.local.CacheSyncPublisher;
32
import io.github.hyshmily.hotkey.util.version.VersionController;
33
import org.springframework.beans.factory.ObjectProvider;
34
import org.springframework.beans.factory.annotation.Qualifier;
35
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
36
import org.springframework.boot.autoconfigure.AutoConfiguration;
37
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
38
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
39
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
40
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
41
import org.springframework.boot.context.properties.EnableConfigurationProperties;
42
import org.springframework.context.annotation.Bean;
43

44
/**
45
 * Auto-configuration for Actuator endpoints exposing HotKey runtime diagnostics.
46
 *
47
 * <p>Creates three endpoint beans:
48
 * <ul>
49
 *   <li>{@link HotKeyEndpoint} &mdash; {@code /actuator/hotkey}: comprehensive
50
 *       diagnostics including TopK rankings, cache metrics, SingleFlight, reporter
51
 *       stats, rules, TTLs, version tracking, and cluster health.</li>
52
 *   <li>{@link RingEndpoint} &mdash; {@code /actuator/hotkeyring}: consistent-hash
53
 *       ring CRUD (requires MVC and consistent-hashing enabled).</li>
54
 *   <li>{@link StateMachineEndpoint} &mdash; {@code /actuator/hotkey/worker/state}:
55
 *       Worker state-machine configuration (requires Worker mode and MVC).</li>
56
 * </ul>
57
 *
58
 * <p>All dependencies for {@link HotKeyEndpoint} are injected via
59
 * {@link ObjectProvider} so that the endpoint can be created in any deployment mode:
60
 * <ul>
61
 *   <li><b>App-only</b> &mdash; app-side TopK, cache, and SingleFlight available</li>
62
 *   <li><b>Worker-only</b> &mdash; only Worker-side TopK is available</li>
63
 *   <li><b>Coexistence</b> &mdash; both TopK instances, cache, and SingleFlight</li>
64
 * </ul>
65
 * Missing dependencies are silently passed as {@code null} and guarded
66
 * inside each endpoint.
67
 */
68
@Internal
69
@AutoConfiguration
70
@ConditionalOnClass(Endpoint.class)
71
@EnableConfigurationProperties(HotKeyProperties.class)
72
public class HotKeyActuatorAutoConfiguration {
3✔
73

74
  /**
75
   * Create the {@link HotKeyEndpoint} Actuator endpoint for comprehensive diagnostics.
76
   *
77
   * <p>All dependencies are optional via {@link ObjectProvider} so the endpoint
78
   * works in any deployment mode. Missing components result in empty sub-sections
79
   * in the endpoint response rather than null-pointer errors.
80
   *
81
   * @param hotKeyDetectorProvider      provider for the app-side TopK detector (may be absent)
82
   * @param workerTopKProvider          provider for the Worker-side TopK detector (may be absent)
83
   * @param hotLocalCacheProvider       provider for the L1 Caffeine cache (may be absent)
84
   * @param singleFlightProvider        provider for the SingleFlight dedup layer (may be absent)
85
   * @param hotKeyReporterProvider      provider for the HotKey reporter (may be absent)
86
   * @param ruleMatcherProvider         provider for the rule matcher (may be absent)
87
   * @param expireManagerProvider       provider for the cache expiry manager (may be absent)
88
   * @param versionControllerProvider   provider for the version controller (may be absent)
89
   * @param cacheSyncPublisherProvider  provider for the cache sync publisher (may be absent)
90
   * @param stateMachineProvider        provider for the Worker state machine (may be absent)
91
   * @param healthViewProvider          provider for the cluster health view (may be absent)
92
   * @param properties                  the HotKey configuration properties (never {@code null})
93
   * @return a new {@link HotKeyEndpoint} instance
94
   */
95
  @Bean
96
  @ConditionalOnMissingBean
97
  public HotKeyEndpoint hotKeyEndpoint(
98
    @Qualifier("hotKeyDetector") ObjectProvider<TopK> hotKeyDetectorProvider,
99
    @Qualifier("workerTopK") ObjectProvider<TopK> workerTopKProvider,
100
    ObjectProvider<Cache<String, Object>> hotLocalCacheProvider,
101
    ObjectProvider<SingleFlight> singleFlightProvider,
102
    ObjectProvider<HotKeyReporter> hotKeyReporterProvider,
103
    ObjectProvider<RuleMatcher> ruleMatcherProvider,
104
    ObjectProvider<CacheExpireManager> expireManagerProvider,
105
    ObjectProvider<VersionController> versionControllerProvider,
106
    ObjectProvider<CacheSyncPublisher> cacheSyncPublisherProvider,
107
    ObjectProvider<HotKeyStateMachine> stateMachineProvider,
108
    ObjectProvider<ClusterHealthView> healthViewProvider,
109
    HotKeyProperties properties
110
  ) {
111
    return HotKeyEndpoint.builder()
3✔
112
      .hotKeyDetector(hotKeyDetectorProvider.getIfAvailable())
4✔
113
      .workerTopK(workerTopKProvider.getIfAvailable())
4✔
114
      .caffeineCache(hotLocalCacheProvider.getIfAvailable())
4✔
115
      .singleFlight(singleFlightProvider.getIfAvailable())
4✔
116
      .properties(properties)
2✔
117
      .hotKeyReporter(hotKeyReporterProvider.getIfAvailable())
4✔
118
      .ruleMatcher(ruleMatcherProvider.getIfAvailable())
4✔
119
      .expireManager(expireManagerProvider.getIfAvailable())
4✔
120
      .versionController(versionControllerProvider.getIfAvailable())
4✔
121
      .cacheSyncPublisher(cacheSyncPublisherProvider.getIfAvailable())
4✔
122
      .hotKeyStateMachine(stateMachineProvider.getIfAvailable())
4✔
123
      .healthView(healthViewProvider.getIfAvailable())
3✔
124
      .build();
1✔
125
  }
126

127
  /**
128
   * Create the {@link RingEndpoint} for consistent-hash ring CRUD operations.
129
   *
130
   * <p>Only active when {@code hotkey.local.consistent-hashing.enabled=true}
131
   * and Spring MVC ({@code RestController}) is on the classpath.
132
   * Provides REST endpoints at {@code /actuator/hotkeyring} for viewing and
133
   * modifying the consistent-hash ring topology.
134
   *
135
   * @param ringManager        the ring manager for consistent-hash topology (never {@code null})
136
   * @param healthViewProvider optional provider for the cluster health view (may be absent)
137
   * @return a new {@link RingEndpoint} instance
138
   */
139
  @Bean
140
  @ConditionalOnClass(name = "org.springframework.web.bind.annotation.RestController")
141
  @ConditionalOnProperty(prefix = "hotkey.local.consistent-hashing", name = "enabled", havingValue = "true")
142
  @ConditionalOnMissingBean
143
  public RingEndpoint ringEndpoint(
144
    ObjectProvider<RingManager> ringManagerProvider,
145
    ObjectProvider<ClusterHealthView> healthViewProvider
146
  ) {
NEW
147
    return new RingEndpoint(ringManagerProvider.getIfAvailable(), healthViewProvider);
×
148
  }
149

150
  /**
151
   * Create the {@link StateMachineEndpoint} for reading and updating the Worker's
152
   * state-machine configuration at runtime.
153
   *
154
   * <p>Only active when a {@link HotKeyStateMachine} bean is present
155
   * (i.e. in Worker mode) and Spring MVC is on the classpath.
156
   * Exposes REST endpoints at {@code /actuator/hotkey/worker/state}
157
   * for GET (read config) and POST (update config) operations.
158
   * Configuration changes propagate to peer Workers via heartbeat broadcast.
159
   *
160
   * @param stateMachine                    the Worker state machine (never {@code null})
161
   * @param configTimestampCounterProvider  optional provider for the config-change timestamp
162
   *                                        counter; bumped on each config change to trigger
163
   *                                        heartbeat broadcast (may be absent)
164
   * @return a new {@link StateMachineEndpoint} instance
165
   */
166
  @Bean
167
  @ConditionalOnClass(name = "org.springframework.web.bind.annotation.RestController")
168
  @ConditionalOnBean(HotKeyStateMachine.class)
169
  @ConditionalOnMissingBean
170
  public StateMachineEndpoint stateMachineEndpoint(
171
    HotKeyStateMachine stateMachine,
172
    ObjectProvider<java.util.concurrent.atomic.AtomicLong> configTimestampCounterProvider
173
  ) {
174
    return new StateMachineEndpoint(stateMachine, configTimestampCounterProvider);
×
175
  }
176
}
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