Skip to content

Commit 5abd464

Browse files
committed
Added failture count
1 parent 5c8744d commit 5abd464

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

jdbc/ydb-token-app/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,5 @@
8787
<version>2.0.12</version>
8888
</dependency>
8989
</dependencies>
90-
9190
</dependencyManagement>
9291
</project>

jdbc/ydb-token-app/src/main/java/tech/ydb/apps/AppMetrics.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ private void printTotal(Logger logger) {
147147
private final Method batchUpdate;
148148

149149
private final AtomicInteger executionsCount = new AtomicInteger(0);
150+
private final AtomicInteger failturesCount = new AtomicInteger(0);
150151
private final AtomicInteger retriesCount = new AtomicInteger(0);
151152

152153
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(
@@ -177,6 +178,10 @@ public Method getBatchUpdate() {
177178
return this.batchUpdate;
178179
}
179180

181+
public void incrementFaiture() {
182+
failturesCount.incrementAndGet();
183+
}
184+
180185
public void runWithMonitor(Runnable runnable) {
181186
Arrays.asList(load, fetch, update, batchUpdate).forEach(Method::reset);
182187
final ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(this::print, 1, 10, TimeUnit.SECONDS);
@@ -197,9 +202,16 @@ private void print() {
197202
}
198203

199204
public void printTotal() {
200-
logger.info("=========== TOTAL ==============");
201-
Arrays.asList(load, fetch, update, batchUpdate).forEach(m -> m.printTotal(logger));
202-
logger.info("Executed {} transactions with {} retries", executionsCount.get(), retriesCount.get());
205+
if (failturesCount.get() > 0) {
206+
logger.error("=========== TOTAL ==============");
207+
Arrays.asList(load, fetch, update, batchUpdate).forEach(m -> m.printTotal(logger));
208+
logger.error("Executed {} transactions with {} retries and {} failtures", executionsCount.get(),
209+
retriesCount.get() - failturesCount.get(), failturesCount.get());
210+
} else {
211+
logger.info("=========== TOTAL ==============");
212+
Arrays.asList(load, fetch, update, batchUpdate).forEach(m -> m.printTotal(logger));
213+
logger.info("Executed {} transactions with {} retries", executionsCount.get(), retriesCount.get());
214+
}
203215
}
204216

205217
public RetryListener getRetryListener() {
@@ -218,7 +230,6 @@ public <T, E extends Throwable> void onError(RetryContext ctx, RetryCallback<T,
218230
if (m != null) {
219231
m.retriesCounter.apply(extractStatusCode(th)).increment();
220232
}
221-
222233
}
223234

224235
@Override

jdbc/ydb-token-app/src/main/java/tech/ydb/apps/Application.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ private void workload(RateLimiter rt, long finishAt) {
197197
executeBatchUpdate(rnd, recordCount); // 10 percents
198198
}
199199
} catch (RuntimeException ex) {
200+
ticker.incrementFaiture();
200201
logger.debug("got exception {}", ex.getMessage());
201202
}
202203
}

jdbc/ydb-token-app/src/main/java/tech/ydb/apps/Config.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tech.ydb.apps;
22

3+
4+
import io.micrometer.core.instrument.MeterRegistry;
35
import org.springframework.boot.context.properties.ConfigurationProperties;
46
import org.springframework.boot.context.properties.ConstructorBinding;
57
import org.springframework.boot.context.properties.bind.Name;
@@ -20,7 +22,7 @@ public class Config {
2022
private final int rpsLimit;
2123

2224
public Config(String connection, int threadsCount, int recordsCount, @Name("load.batchSize") int loadBatchSize,
23-
@Name("workload.duration") int workloadDuration, int rpsLimit) {
25+
@Name("workload.duration") int workloadDuration, int rpsLimit, MeterRegistry registy) {
2426
this.connection = connection;
2527
this.threadsCount = threadsCount <= 0 ? Runtime.getRuntime().availableProcessors() : threadsCount;
2628
this.recordsCount = recordsCount;
@@ -52,5 +54,4 @@ public int getWorkloadDurationSec() {
5254
public RateLimiter getRpsLimiter() {
5355
return rpsLimit <= 0 ? RateLimiter.noLimit() : RateLimiter.withRps(rpsLimit);
5456
}
55-
5657
}

jdbc/ydb-token-app/src/main/java/tech/ydb/apps/annotation/YdbRetryable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@Retention(RetentionPolicy.RUNTIME)
2020
@Retryable(
2121
retryFor = { SQLRecoverableException.class, SQLTransientException.class },
22-
maxAttempts = 5,
22+
maxAttempts = 15,
2323
backoff = @Backoff(delay = 100, multiplier = 2.0, maxDelay = 5000, random = true)
2424
)
2525
public @interface YdbRetryable {

jdbc/ydb-token-app/src/main/java/tech/ydb/apps/service/WorkloadService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.util.UUID;
88
import java.util.stream.Collectors;
99

10+
import javax.persistence.EntityNotFoundException;
11+
1012
import org.slf4j.Logger;
1113
import org.slf4j.LoggerFactory;
1214
import org.springframework.stereotype.Service;
@@ -54,7 +56,7 @@ public Token fetchToken(int id) {
5456

5557
if (!token.isPresent()) {
5658
logger.warn("token {} is not found", id);
57-
return null;
59+
throw new EntityNotFoundException("token " + id + " is not found");
5860
}
5961

6062
return token.get();
@@ -71,6 +73,7 @@ public void updateToken(int id, long counter) {
7173
logger.trace("updated token {} -> {}", id, token.getVersion());
7274
} else {
7375
logger.warn("token {} is not found", id);
76+
throw new EntityNotFoundException("token " + id + " is not found");
7477
}
7578
}
7679

jdbc/ydb-token-app/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ management.metrics.enable.jdbc=true
2626
management.metrics.enable.sdk=true
2727
management.metrics.enable.grpc=true
2828
management.metrics.distribution.percentiles-histogram.all=true
29+
management.metrics.distribution.sla.all=true
30+
2931
management.metrics.export.prometheus.pushgateway.enabled=${app.pushMetrics}
3032
management.metrics.export.prometheus.pushgateway.push-rate=15s
3133
management.metrics.export.prometheus.pushgateway.base-url=${app.prometheusUrl}

0 commit comments

Comments
 (0)