-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #703 from jbiblio/importer-metrics
Export metrics about the import process
Showing
12 changed files
with
237 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/io/zeebe/monitor/zeebe/hazelcast/HazelcastStateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.zeebe.monitor.zeebe.hazelcast; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.zeebe.monitor.entity.HazelcastConfig; | ||
import io.zeebe.monitor.repository.HazelcastConfigRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* The HazelcastStateService manages the current pointer of the Hazelcast import process. | ||
* <p> | ||
* That pointer is required to read the next-relevant message from the RingBuffer | ||
* <p> | ||
* Usually, that RingBuffer is read 1 by 1, but sometimes, the RingBuffer may overrun by the export process, | ||
* and in that case, the Import process will set the sequence to the current position of the RingBuffer. | ||
*/ | ||
@Component | ||
public class HazelcastStateService { | ||
|
||
private final HazelcastConfigRepository hazelcastConfigRepository; | ||
private final Counter sequenceCounter; | ||
|
||
@Autowired | ||
public HazelcastStateService(HazelcastConfigRepository hazelcastConfigRepository, MeterRegistry meterRegistry) { | ||
this.hazelcastConfigRepository = hazelcastConfigRepository; | ||
|
||
sequenceCounter = Counter.builder("zeebemonitor_importer_ringbuffer_sequences_read"). | ||
description("number of items read from Hazelcast's ringbuffer (sequence counter)"). | ||
register(meterRegistry); | ||
} | ||
|
||
public long getLastSequenceNumber() { | ||
return getHazelcastConfig().getSequence(); | ||
} | ||
|
||
@Transactional | ||
public void saveSequenceNumber(long sequence) { | ||
HazelcastConfig config = getHazelcastConfig(); | ||
|
||
long prev = config.getSequence(); | ||
|
||
config.setSequence(sequence); | ||
|
||
hazelcastConfigRepository.save(config); | ||
|
||
sequenceCounter.increment(sequence - prev); | ||
} | ||
|
||
private HazelcastConfig getHazelcastConfig() { | ||
return hazelcastConfigRepository | ||
.findById("cfg") | ||
.orElseGet( | ||
() -> { | ||
final var config = new HazelcastConfig(); | ||
config.setId("cfg"); | ||
config.setSequence(-1); | ||
return config; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters