-
Notifications
You must be signed in to change notification settings - Fork 18
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
add telemetry to GCS #334
base: main
Are you sure you want to change the base?
add telemetry to GCS #334
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2024 Aiven Oy | ||
* | ||
* Licensed 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 io.aiven.kafka.connect.common.config.validators; | ||
|
||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigException; | ||
|
||
public class ClassValidator implements ConfigDef.Validator { | ||
private final Class<?> baseClass; | ||
|
||
public ClassValidator(final Class<?> baseClass) { | ||
this.baseClass = baseClass; | ||
} | ||
|
||
@Override | ||
public void ensureValid(final String name, final Object value) { | ||
if (value != null && !baseClass.isAssignableFrom((Class<?>) value)) { | ||
throw new ConfigException(name, value, "must be a subclass of " + baseClass.getName()); | ||
} | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import com.google.api.gax.tracing.ApiTracerFactory; | ||
import io.aiven.kafka.connect.common.config.validators.ClassValidator; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigException; | ||
import org.apache.kafka.common.config.types.Password; | ||
|
@@ -59,6 +61,7 @@ public final class GcsSinkConfig extends AivenCommonConfig { | |
public static final String GCS_BUCKET_NAME_CONFIG = "gcs.bucket.name"; | ||
public static final String GCS_OBJECT_CONTENT_ENCODING_CONFIG = "gcs.object.content.encoding"; | ||
public static final String GCS_USER_AGENT = "gcs.user.agent"; | ||
public static final String GCS_METRICS = "gcs.metrics.class"; | ||
private static final String GROUP_FILE = "File"; | ||
public static final String FILE_NAME_PREFIX_CONFIG = "file.name.prefix"; | ||
public static final String FILE_NAME_TEMPLATE_CONFIG = "file.name.template"; | ||
|
@@ -144,14 +147,16 @@ private static void addGcsConfigGroup(final ConfigDef configDef) { | |
|
||
configDef.define(GCS_BUCKET_NAME_CONFIG, ConfigDef.Type.STRING, ConfigDef.NO_DEFAULT_VALUE, | ||
new ConfigDef.NonEmptyString(), ConfigDef.Importance.HIGH, | ||
"The GCS bucket name to store output files in.", GROUP_GCS, gcsGroupCounter++, ConfigDef.Width.NONE, // NOPMD | ||
// the | ||
// gcsGroupCounter | ||
// updated | ||
// value | ||
// never | ||
// used | ||
"The GCS bucket name to store output files in.", GROUP_GCS, gcsGroupCounter++, ConfigDef.Width.NONE, | ||
GCS_BUCKET_NAME_CONFIG); | ||
configDef.define(GCS_METRICS, ConfigDef.Type.CLASS, | ||
null, new ClassValidator(ApiTracerFactory.class), | ||
ConfigDef.Importance.LOW, | ||
"class for GCS metrics. Default is not to attache metrics", | ||
GROUP_GCS, gcsGroupCounter++, ConfigDef.Width.NONE, // NOPMD | ||
// retryPolicyGroupCounter updated value never used | ||
GCS_METRICS); | ||
|
||
} | ||
|
||
private static void addGcsRetryPolicies(final ConfigDef configDef) { | ||
|
@@ -438,4 +443,15 @@ public String getGcsEndpoint() { | |
public String getUserAgent() { | ||
return getString(GCS_USER_AGENT); | ||
} | ||
|
||
public ApiTracerFactory getApiTracerFactory() { | ||
if (getClass(GCS_METRICS) == null) { | ||
return null; | ||
} | ||
try { | ||
return getClass(GCS_METRICS).asSubclass(ApiTracerFactory.class).getDeclaredConstructor().newInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that not all implementations of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Happy to add a more complex builder mechanism, with some standard implementations for suggested |
||
} catch (ReflectiveOperationException e) { | ||
throw new RuntimeException(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Just my lazyness - its just that ConfigException doesn't follow normal exception chaining patterns |
||
} | ||
} | ||
} |
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.
Can we instead bring this validator implementation here? IMO it makes code a little more readable when you write
Subclass.of(SomeClass.class)
rather thennew ClassValidator(SomeClass.class)
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.
Is there a common library that you use for these. It seems copying and duplication is a bad way forward, particularly for a common concept like validation
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.
There is no common library yet and when I created the validator I'm suggesting I did not manage to find a ready to use implementation.
I think for now copying is good enough but in future I think if this pattern will repeat we will consider creating our own commons library to address this.