Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/org/apache/nifi/processor/ProcessSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.nifi.processor.io.InputStreamCallback;
import org.apache.nifi.processor.io.OutputStreamCallback;
import org.apache.nifi.processor.io.StreamCallback;
import org.apache.nifi.processor.metrics.CommitTiming;
import org.apache.nifi.provenance.ProvenanceReporter;
import org.apache.nifi.provenance.ProvenanceEventType;

Expand Down Expand Up @@ -253,6 +254,18 @@ default void commitAsync(Runnable onSuccess) {
*/
void adjustCounter(String name, long delta, boolean immediate);

/**
* Record measurement value for the named Gauge, registering the named Gauge when not present in the system.
Comment on lines +257 to +258
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be useful addition in the javadoc for developers not familiar with the terminology

Suggested change
/**
* Record measurement value for the named Gauge, registering the named Gauge when not present in the system.
/**
* Record measurement value for the named Gauge, registering the named Gauge when not present in the system.
* Unlike counters which track cumulative values, gauges represent point-in-time measurements that can increase or decrease.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that is a helpful clarification to distinguish it from counters.

* Gauges represent a measurement at a point in time, unlike counters that track cumulative values.
*
* @param name Gauge name to update or register
* @param value Measurement value to record
* @param commitTiming Timing for when the measurement value should be committed
*/
default void recordGauge(String name, double value, CommitTiming commitTiming) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to also have a convenience method like

default void recordGauge(String name, double value) {
    recordGauge(name, value, CommitTiming.SESSION_COMMITTED);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that possibility, but I could also see an argument for making NOW the default option. In the end, I think it is best to follow the pattern of adjustCounter, and require the argument in all cases.


}

/**
* Returns the {@link FlowFile} from the work queue that is next highest priority to process.
* If no FlowFiles are available, returns {@code null}.
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/apache/nifi/processor/metrics/CommitTiming.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.processor.metrics;

/**
* Enumeration of timing options for committing metrics
*/
public enum CommitTiming {
/** Commit metrics immediately regardless of session transaction status */
NOW,

/** Commit metrics on successful commit of session transaction */
SESSION_COMMITTED
}