Skip to content

Commit a11678b

Browse files
committed
Clean up metrics
1 parent 5272a43 commit a11678b

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

Diff for: 01-k8-demo/src/main/java/com/cognite/examples/Demo.java

-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ Configuration section. The configuration values are read from the following loca
4141
static final CollectorRegistry collectorRegistry = new CollectorRegistry();
4242
static final Gauge jobDurationSeconds = Gauge.build()
4343
.name("job_duration_seconds").help("Job duration in seconds").register(collectorRegistry);
44-
static final Gauge jobStartTimeStamp = Gauge.build()
45-
.name("job_start_timestamp").help("Job start time stamp").register(collectorRegistry);
4644
static final Gauge errorGauge = Gauge.build()
4745
.name("job_errors").help("Total job errors").register(collectorRegistry);
4846

@@ -75,7 +73,6 @@ public static void main(String[] args) {
7573
private static void run() throws Exception {
7674
LOG.info("Starting container...");
7775
Gauge.Timer jobDurationTimer = jobDurationSeconds.startTimer();
78-
jobStartTimeStamp.setToCurrentTime();
7976

8077
LOG.info("Starting some work...");
8178
Thread.sleep(3000);

Diff for: 02-raw-to-clean-batch-job/src/main/java/com/cognite/examples/RawToClean.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ public class RawToClean {
7777
private static final CollectorRegistry collectorRegistry = new CollectorRegistry();
7878
private static final Gauge jobDurationSeconds = Gauge.build()
7979
.name("job_duration_seconds").help("Job duration in seconds").register(collectorRegistry);
80-
private static final Gauge jobStartTimeStamp = Gauge.build()
81-
.name("job_start_timestamp").help("Job start timestamp").register(collectorRegistry);
8280
private static final Gauge errorGauge = Gauge.build()
8381
.name("job_errors").help("Total job errors").register(collectorRegistry);
8482
private static final Gauge noElementsGauge = Gauge.build()
@@ -128,12 +126,10 @@ public static void main(String[] args) {
128126
The main logic to execute.
129127
*/
130128
private static void run() throws Exception {
131-
Instant startInstant = Instant.now();
132129
LOG.info("Starting raw to clean pipeline...");
133130

134-
// Prepare the job start metrics
131+
// Prepare the job duration metrics
135132
Gauge.Timer jobDurationTimer = jobDurationSeconds.startTimer();
136-
jobStartTimeStamp.setToCurrentTime();
137133

138134
// Set up the reader for the raw table
139135
LOG.info("Starting to read the raw table {}.{}.",
@@ -158,10 +154,11 @@ private static void run() throws Exception {
158154
noElementsGauge.inc(events.size());
159155
}
160156

157+
jobDurationTimer.setDuration();
161158
LOG.info("Finished processing {} rows from raw. Duration {}",
162159
noElementsGauge.get(),
163-
Duration.between(startInstant, Instant.now()));
164-
jobDurationTimer.setDuration();
160+
Duration.ofSeconds((long) jobDurationSeconds.get()));
161+
165162

166163
// The job completion metric is only added to the registry after job success,
167164
// so that a previous success in the Pushgateway isn't overwritten on failure.

Diff for: 21-met-metalerts-rss-extractor/src/main/java/com/cognite/met/AlertsRssExtractor.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ public class AlertsRssExtractor {
7070
private static final CollectorRegistry collectorRegistry = new CollectorRegistry();
7171
private static final Gauge jobDurationSeconds = Gauge.build()
7272
.name("job_duration_seconds").help("Job duration in seconds").register(collectorRegistry);
73-
private static final Gauge jobStartTimeStamp = Gauge.build()
74-
.name("job_start_timestamp").help("Job start timestamp").register(collectorRegistry);
7573
private static final Gauge errorGauge = Gauge.build()
7674
.name("job_errors").help("Total job errors").register(collectorRegistry);
7775
private static final Gauge noElementsGauge = Gauge.build()
@@ -116,12 +114,10 @@ public static void main(String[] args) {
116114
The main logic to execute.
117115
*/
118116
private static void run() throws Exception {
119-
Instant startInstant = Instant.now();
120117
LOG.info("Starting Met Alerts RSS extractor...");
121118

122-
// Prepare the job start metrics
119+
// Prepare the job duration metrics
123120
Gauge.Timer jobDurationTimer = jobDurationSeconds.startTimer();
124-
jobStartTimeStamp.setToCurrentTime();
125121

126122
LOG.info("Sending request to source uri: {}", sourceUri);
127123

@@ -143,10 +139,11 @@ private static void run() throws Exception {
143139
getCogniteClient().raw().rows().upsert(rawRows);
144140
noElementsGauge.inc(rawRows.size());
145141

142+
// All done
143+
jobDurationTimer.setDuration();
146144
LOG.info("Finished processing {} rss items. Duration {}",
147145
noElementsGauge.get(),
148-
Duration.between(startInstant, Instant.now()));
149-
jobDurationTimer.setDuration();
146+
Duration.ofSeconds((long) jobDurationSeconds.get()));
150147

151148
// The job completion metric is only added to the registry after job success,
152149
// so that a previous success in the Pushgateway isn't overwritten on failure.
@@ -158,7 +155,7 @@ private static void run() throws Exception {
158155
/*
159156
Parse the RSS item to a raw row.
160157
*/
161-
private static RawRow parseRawRow(Item rssItem) throws Exception {
158+
private static RawRow parseRawRow(Item rssItem) {
162159
final String loggingPrefix = "parseRawRow() - ";
163160

164161
final String titleKey = "title";

Diff for: 22-met-alerts-cap-extractor/src/main/java/com/cognite/met/AlertsCapExtractor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ public static void main(String[] args) {
150150
The main logic to execute.
151151
*/
152152
private static void run() throws Exception {
153-
Instant startInstant = Instant.now();
154153
LOG.info("Starting Met Alerts CAP extractor...");
155154

156-
// Prepare the job start metrics
155+
// Prepare the job duration metrics
157156
Gauge.Timer jobDurationTimer = jobDurationSeconds.startTimer();
158157
jobStartTimeStamp.setToCurrentTime();
159158

@@ -223,10 +222,11 @@ private static void run() throws Exception {
223222
// Stop the state store. This will also store the final state
224223
getStateStore().ifPresent(stateStore -> stateStore.stop());
225224

225+
// All done
226+
jobDurationTimer.setDuration();
226227
LOG.info("Finished processing {} cap items. Duration {}",
227228
noElementsGauge.get(),
228-
Duration.between(startInstant, Instant.now()));
229-
jobDurationTimer.setDuration();
229+
Duration.ofSeconds((long) jobDurationSeconds.get()));
230230

231231
// The job completion metric is only added to the registry after job success,
232232
// so that a previous success in the Pushgateway isn't overwritten on failure.

0 commit comments

Comments
 (0)