Skip to content

Instantly share code, notes, and snippets.

View jonatan-ivanov's full-sized avatar
🦉

Jonatan Ivanov jonatan-ivanov

🦉
View GitHub Profile
@jonatan-ivanov
jonatan-ivanov / GaugeUpdateTrick.java
Last active February 4, 2022 18:42
Trick for updating a gauge less frequently
// from Jon Schneider
public class GaugeUpdateTrick {
public static void main(String[] args) {
AtomicLong lastCalculatedTime = new AtomicLong(0);
AtomicLong gaugeValue = new AtomicLong(0);
Gauge.builder("expensive", () -> {
long curr = System.nanoTime();
return gaugeValue.updateAndGet(old ->
lastCalculatedTime.updateAndGet(ts -> curr - ts > 10_000 ? curr : ts) == curr ? 0L /* new */ : old);
});
@jonatan-ivanov
jonatan-ivanov / CpuMetricsDemo.java
Last active January 29, 2022 05:36
CPU Metrics Demo
package org.example;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
@jonatan-ivanov
jonatan-ivanov / java-info.md
Last active November 23, 2021 16:21
by popular OpenJDK distributions
adoptopenjdk:11-jre-hotspot
java.runtime.name: OpenJDK Runtime Environment
java.runtime.version: 11.0.11+9
java.vendor: AdoptOpenJDK
java.version: 11.0.11
java.vm.name: OpenJDK 64-Bit Server VM
java.vm.vendor: AdoptOpenJDK
java.vm.version: 11.0.11+9

Complicated API

  • As a user, it is somewhat complex and quite puzzling using the API
  • There are a lot of components
  • The components are doing different things as I would expect based on their names
  • I think it would worth a review and refactor to make it more usable.

Examples

  • GlobalMetricsProvider
    • Based on its name, it should provide Metrics instances
  • In fact, it provides two things neither of them are Metrics
{
"status": "UP",
"components": {
"discoveryComposite": {
"status": "UP",
"components": {
"discoveryClient": {
"status": "UP",
"details": {
"services": [

4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.2-SNAPSHOT

@jonatan-ivanov
jonatan-ivanov / Friday.md
Last active November 19, 2019 22:08
NFJS 2019
@jonatan-ivanov
jonatan-ivanov / BatchConfiguration.java
Last active May 17, 2020 21:04
spring-batch continuous polling example
@Configuration
@EnableScheduling
@EnableBatchProcessing
public class BatchConfiguration {
@Bean
@StepScope
public ResourceReader reader(
@Value("...") String url,
@Value("...") int pageSize,
@Value("#{jobParameters['ResourceReader.index']}") int index) {

ssh-keygen -t rsa -C "email"