-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Naireen
committed
Dec 10, 2024
1 parent
6edfcd4
commit be7242c
Showing
10 changed files
with
372 additions
and
14 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
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
84 changes: 84 additions & 0 deletions
84
sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/DelegatingGauge.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,84 @@ | ||
/* | ||
* 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.beam.sdk.metrics; | ||
|
||
import java.io.Serializable; | ||
import org.apache.beam.sdk.annotations.Internal; | ||
|
||
/** Implementation of {@link Gauge} that delegates to the instance for the current context. */ | ||
@Internal | ||
public class DelegatingGauge implements Metric, Gauge, Serializable { | ||
private final MetricName name; | ||
private final boolean processWideContainer; | ||
private final boolean perWorkerGauge; | ||
|
||
/** | ||
* Create a {@code DelegatingGauge} with {@code perWorkerGauge} and {@code processWideContainer} | ||
* set to false. | ||
* | ||
* @param name Metric name for this metric. | ||
*/ | ||
public DelegatingGauge(MetricName name) { | ||
this(name, false, false); | ||
} | ||
|
||
/** | ||
* Create a {@code DelegatingGauge} with {@code perWorkerGauge} set to false. | ||
* | ||
* @param name Metric name for this metric. | ||
* @param processWideContainer Whether this Gauge is stored in the ProcessWide container or the | ||
* current thread's container. | ||
*/ | ||
public DelegatingGauge(MetricName name, boolean processWideContainer) { | ||
this(name, processWideContainer, false); | ||
} | ||
|
||
/** | ||
* @param name Metric name for this metric. | ||
* @param processWideContainer Whether this gauge is stored in the ProcessWide container or the | ||
* current thread's container. | ||
* @param perWorkerGauge Whether this gauge refers to a perWorker metric or not. | ||
*/ | ||
public DelegatingGauge(MetricName name, boolean processWideContainer, boolean perWorkerGauge) { | ||
this.name = name; | ||
this.processWideContainer = processWideContainer; | ||
this.perWorkerGauge = perWorkerGauge; | ||
} | ||
|
||
/** Set the gauge. */ | ||
@Override | ||
public void set(long n) { | ||
MetricsContainer container = | ||
this.processWideContainer | ||
? MetricsEnvironment.getProcessWideContainer() | ||
: MetricsEnvironment.getCurrentContainer(); | ||
if (container == null) { | ||
return; | ||
} | ||
if (perWorkerGauge) { | ||
container.getPerWorkerGauge(name).set(n); | ||
} else { | ||
container.getGauge(name).set(n); | ||
} | ||
} | ||
|
||
@Override | ||
public MetricName getName() { | ||
return name; | ||
} | ||
} |
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
Oops, something went wrong.