fix for duplicate config_cyclerate gauge when striderate is used

This commit is contained in:
Mark Wolters 2024-01-31 16:37:33 -04:00
parent 46917d18bd
commit 6ffa867d6c
3 changed files with 56 additions and 24 deletions

View File

@ -25,9 +25,13 @@ public enum RateLimiters {
private static final Logger logger = LogManager.getLogger(RateLimiters.class);
public static synchronized RateLimiter createOrUpdate(final NBComponent parent, final RateLimiter extant, final SimRateSpec spec) {
return createOrUpdate(parent, extant, spec, "cycle");
}
public static synchronized RateLimiter createOrUpdate(final NBComponent parent, final RateLimiter extant, final SimRateSpec spec,final String type) {
if (null == extant) {
final RateLimiter rateLimiter= new SimRate(parent, spec);
final RateLimiter rateLimiter= new SimRate(parent, spec, type);
RateLimiters.logger.info(() -> "Using rate limiter: " + rateLimiter);
return rateLimiter;

View File

@ -79,32 +79,58 @@ public class SimRate extends NBBaseComponent implements RateLimiter, Thread.Unca
private long startTime;
public SimRate(NBComponent parent, SimRateSpec spec) {
this(parent, spec, "cycle");
}
public SimRate(NBComponent parent, SimRateSpec spec, String type) {
super(parent, NBLabels.forKV());
this.spec = spec;
initMetrics();
initMetrics(type);
startFiller();
}
private void initMetrics() {
create().gauge(
"cycles_waittime",
() -> (double)getWaitTimeDuration().get(ChronoUnit.NANOS),
MetricCategory.Core,
"The cumulative scheduling delay which accrues when" +
" an activity is not able to execute operations as fast as requested."
);
create().gauge(
"config_cyclerate",
() -> spec.opsPerSec,
MetricCategory.Config,
"The configured cycle rate in ops/s"
);
create().gauge(
"config_burstrate",
() -> spec.burstRatio,
MetricCategory.Config,
"the configured burst rate as a multiplier to the configured cycle rate. ex: 1.05 means 5% faster is allowed."
);
private void initMetrics(String type) {
if (type.equalsIgnoreCase("cycle")) {
create().gauge(
"cycles_waittime",
() -> (double) getWaitTimeDuration().get(ChronoUnit.NANOS),
MetricCategory.Core,
"The cumulative scheduling delay which accrues when" +
" an activity is not able to execute operations as fast as requested."
);
create().gauge(
"config_cyclerate",
() -> spec.opsPerSec,
MetricCategory.Config,
"The configured cycle rate in ops/s"
);
create().gauge(
"config_burstrate",
() -> spec.burstRatio,
MetricCategory.Config,
"the configured burst rate as a multiplier to the configured cycle rate. ex: 1.05 means 5% faster is allowed."
);
} else {
create().gauge(
"stride_waittime",
() -> (double) getWaitTimeDuration().get(ChronoUnit.NANOS),
MetricCategory.Core,
"The cumulative scheduling delay which accrues when" +
" an activity is not able to execute operations as fast as requested."
);
create().gauge(
"config_striderate",
() -> spec.opsPerSec,
MetricCategory.Config,
"The configured stride rate in ops/s"
);
create().gauge(
"config_burstrate",
() -> spec.burstRatio,
MetricCategory.Config,
"the configured burst rate as a multiplier to the configured cycle rate. ex: 1.05 means 5% faster is allowed."
);
}
}
public long refill() {

View File

@ -89,6 +89,8 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok
private ActivityMetricProgressMeter progressMeter;
private String workloadSource = "unspecified";
private final RunStateTally tally = new RunStateTally();
public static final String STRIDE = "stride";
public static final String CYCLE = "cycle";
public SimpleActivity(NBComponent parent, ActivityDef activityDef) {
super(parent, NBLabels.forKV("activity", activityDef.getAlias()).and(activityDef.auxLabels()));
@ -315,11 +317,11 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok
}
public void createOrUpdateStrideLimiter(SimRateSpec spec) {
strideLimiter = RateLimiters.createOrUpdate(this, strideLimiter, spec);
strideLimiter = RateLimiters.createOrUpdate(this, strideLimiter, spec, STRIDE);
}
public void createOrUpdateCycleLimiter(SimRateSpec spec) {
cycleLimiter = RateLimiters.createOrUpdate(this, cycleLimiter, spec);
cycleLimiter = RateLimiters.createOrUpdate(this, cycleLimiter, spec, CYCLE);
}
/**