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

Hyshmily / hotkey / 27925388821

22 Jun 2026 02:14AM UTC coverage: 92.403% (-1.2%) from 93.615%
27925388821

push

github

Hyshmily
fix:fix known bugs and promote performance

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

1143 of 1289 branches covered (88.67%)

Branch coverage included in aggregate %.

184 of 236 new or added lines in 19 files covered. (77.97%)

6 existing lines in 3 files now uncovered.

3321 of 3542 relevant lines covered (93.76%)

4.22 hits per line

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

86.67
/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.cache.CacheExpireManager;
20
import io.github.hyshmily.hotkey.cache.SingleFlight;
21
import io.github.hyshmily.hotkey.detection.HotKeyStateMachine;
22
import io.github.hyshmily.hotkey.endpoint.HotKeyEndpoint;
23
import io.github.hyshmily.hotkey.endpoint.RingEndpoint;
24
import io.github.hyshmily.hotkey.endpoint.StateMachineEndpoint;
25
import io.github.hyshmily.hotkey.hotkeydetector.heavykepper.TopK;
26
import io.github.hyshmily.hotkey.reporting.HotKeyReporter;
27
import io.github.hyshmily.hotkey.rule.RuleMatcher;
28
import io.github.hyshmily.hotkey.sharding.RingManager;
29
import io.github.hyshmily.hotkey.sharding.ClusterHealthView;
30
import io.github.hyshmily.hotkey.sync.local.CacheSyncPublisher;
31
import io.github.hyshmily.hotkey.util.version.VersionController;
32
import org.springframework.beans.factory.ObjectProvider;
33
import org.springframework.beans.factory.annotation.Qualifier;
34
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
35
import org.springframework.boot.autoconfigure.AutoConfiguration;
36
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
37
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
38
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
39
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
40
import org.springframework.boot.context.properties.EnableConfigurationProperties;
41
import org.springframework.context.annotation.Bean;
42

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

72
  /**
73
   * Create the {@link HotKeyEndpoint} Actuator endpoint for comprehensive diagnostics.
74
   *
75
   * <p>All dependencies are optional via {@link ObjectProvider} so the endpoint
76
   * works in any deployment mode. Missing components result in empty sub-sections
77
   * in the endpoint response rather than null-pointer errors.
78
   *
79
   * @param hotKeyDetectorProvider      provider for the app-side TopK detector (may be absent)
80
   * @param workerTopKProvider          provider for the Worker-side TopK detector (may be absent)
81
   * @param hotLocalCacheProvider       provider for the L1 Caffeine cache (may be absent)
82
   * @param singleFlightProvider        provider for the SingleFlight dedup layer (may be absent)
83
   * @param hotKeyReporterProvider      provider for the HotKey reporter (may be absent)
84
   * @param ruleMatcherProvider         provider for the rule matcher (may be absent)
85
   * @param ringManagerProvider         provider for the consistent-hash ring manager (may be absent)
86
   * @param expireManagerProvider       provider for the cache expiry manager (may be absent)
87
   * @param versionControllerProvider   provider for the version controller (may be absent)
88
   * @param cacheSyncPublisherProvider  provider for the cache sync publisher (may be absent)
89
   * @param stateMachineProvider        provider for the Worker state machine (may be absent)
90
   * @param healthViewProvider          provider for the cluster health view (may be absent)
91
   * @param properties                  the HotKey configuration properties (never {@code null})
92
   * @return a new {@link HotKeyEndpoint} instance
93
   */
94
  @Bean
95
  @ConditionalOnMissingBean
96
  public HotKeyEndpoint hotKeyEndpoint(
97
    @Qualifier("hotKeyDetector") ObjectProvider<TopK> hotKeyDetectorProvider,
98
    @Qualifier("workerTopK") ObjectProvider<TopK> workerTopKProvider,
99
    ObjectProvider<Cache<String, Object>> hotLocalCacheProvider,
100
    ObjectProvider<SingleFlight> singleFlightProvider,
101
    ObjectProvider<HotKeyReporter> hotKeyReporterProvider,
102
    ObjectProvider<RuleMatcher> ruleMatcherProvider,
103
    ObjectProvider<RingManager> ringManagerProvider,
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 new HotKeyEndpoint(
4✔
112
      hotKeyDetectorProvider.getIfAvailable(),
3✔
113
      workerTopKProvider.getIfAvailable(),
3✔
114
      hotLocalCacheProvider.getIfAvailable(),
3✔
115
      singleFlightProvider.getIfAvailable(),
4✔
116
      properties,
117
      hotKeyReporterProvider.getIfAvailable(),
3✔
118
      ruleMatcherProvider.getIfAvailable(),
3✔
119
      ringManagerProvider.getIfAvailable(),
3✔
120
      expireManagerProvider.getIfAvailable(),
3✔
121
      versionControllerProvider.getIfAvailable(),
3✔
122
      cacheSyncPublisherProvider.getIfAvailable(),
3✔
123
      stateMachineProvider.getIfAvailable(),
4✔
124
      healthViewProvider
125
    );
126
  }
127

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

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