-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GOBBLIN-2161] Support for configuring openTelemetry metric exporter as logExporter #4061
[GOBBLIN-2161] Support for configuring openTelemetry metric exporter as logExporter #4061
Conversation
public static final String METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_ENABLED = METRICS_REPORTING_OPENTELEMETRY_PREFIX + "logexporter.enabled"; | ||
|
||
public static final Boolean DEFAULT_METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_ENABLED = false; | ||
|
||
public static final String METRICS_REPORTING_OPENTELEMETRY_LOGEXPORTER_CLASSNAME = METRICS_REPORTING_OPENTELEMETRY_PREFIX + "logexporter.className"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making a direct reference around a log exporter, how about we make the metric exporter a generic className such that any metric exporter class can be instantiated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default class if no class is defined can be the OtlpHttpMetricExporter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that it would be useful to make the MetricExporter instantiation more generic, allowing for any MetricExporter class to be instantiated. However, since different exporters may require varying instantiation methods (e.g., constructors vs. static methods), and we also need to set certain properties which are specific to OtlpHttpMetricExporter
, so it's challenging to handle them all in a truly generic way.
One possible solution could be to use a factory pattern, where we have a separate factory class for each MetricExporter type. Each factory would know how to properly instantiate its corresponding MetricExporter. However, this would require significant changes
public interface MetricExporterFactory {
MetricExporter create(State state);
}
@Override
protected MetricExporter initializeMetricExporter(State state) {
MetricExporterFactory factory = getMetricExporterFactory(state);
return factory.create(state);
}
Or we can update initializeMetricExporter
method to use reflection to instantiate the class specified in the configuration, however, since the instantiation is not common across different metricExporters, supporting another metricExporter might still require new code to be handled.
protected MetricExporter initializeMetricExporter(State state) {
MetricExporter metricExporter;
String exporterClassName = state.getProp(ConfigurationKeys.METRICS_REPORTING_OPENTELEMETRY_EXPORTER_CLASSNAME,
OtlpHttpMetricExporter.class.getName());
try {
Class<?> clazz = Class.forName(exporterClassName);
Method instanceMethod = clazz.getMethod("instance");
// Invoke the method to get the singleton instance
metricExporter = (MetricExporter) instanceMethod.invoke(null);
} catch (Exception e) {
log.error("Error occurred while instantiating opentelemetry Exporter class: " + exporterClassName, e);
metricExporter = createDefaultExporter(state);
}
return metricExporter;
}
Let me know if the existing way to create LogMetricExporter is fine given the constraints or you meant something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I see, for the context of this PR a logging exporter shouldn't require a different constructor like the second method you mentioned but the long term soln is definitely to use the factory pattern. Please add a TODO for that. Otherwise seems reasonable to me.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4061 +/- ##
=============================================
+ Coverage 45.12% 55.28% +10.16%
+ Complexity 3199 1582 -1617
=============================================
Files 705 307 -398
Lines 26949 10581 -16368
Branches 2680 1069 -1611
=============================================
- Hits 12160 5850 -6310
+ Misses 13781 4226 -9555
+ Partials 1008 505 -503
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Dear Gobblin maintainers,
Please accept this PR. I understand that it will not be reviewed until I have checked off all the steps below!
JIRA
Description
false
by default andOtlpHttpMetricExporter
would be the default metricExporter class.Tests
Commits