Abacn commented on code in PR #33059:
URL: https://github.com/apache/beam/pull/33059#discussion_r1837467313
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/metrics/Metrics.java:
##########
@@ -50,9 +57,59 @@
* example off how to query metrics.
*/
public class Metrics {
+ private static final Logger LOG = LoggerFactory.getLogger(Metrics.class);
private Metrics() {}
+ static class MetricsFlag {
+ private static final AtomicReference<@Nullable MetricsFlag> INSTANCE = new
AtomicReference<>();
+ final boolean counterDisabled;
+ final boolean stringSetDisabled;
+
+ private MetricsFlag(boolean counterDisabled, boolean stringSetDisabled) {
+ this.counterDisabled = counterDisabled;
+ this.stringSetDisabled = stringSetDisabled;
+ }
+
+ static boolean counterDisabled() {
+ MetricsFlag flag = INSTANCE.get();
+ return flag != null && flag.counterDisabled;
+ }
+
+ static boolean stringSetDisabled() {
+ MetricsFlag flag = INSTANCE.get();
+ return flag != null && flag.stringSetDisabled;
+ }
+ }
+
+ /**
+ * Initialize metrics flags if not already done so.
+ *
+ * <p>Should be called by worker at worker harness initialization. Should
not be called by user
+ * code (and it does not have an effect as the initialization completed
before).
+ */
+ @Internal
+ public static void setDefaultPipelineOptions(PipelineOptions options) {
+ MetricsFlag flag = MetricsFlag.INSTANCE.get();
+ if (flag == null) {
+ ExperimentalOptions exp = options.as(ExperimentalOptions.class);
+ boolean counterDisabled = ExperimentalOptions.hasExperiment(exp,
"disableCounterMetrics");
+ if (counterDisabled) {
+ LOG.info("Counter metrics are disabled.");
+ }
+ boolean stringSetDisabled = ExperimentalOptions.hasExperiment(exp,
"disableStringSetMetrics");
Review Comment:
Thanks, closed this one and opened an alternative PR: #33085 for this
suggestion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]