-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Added metrics generator #46
base: work-for-release-0.23.x
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -19,4 +19,7 @@ | |
<Match> | ||
<Class name="~org\.killbill\.billing\.plugin\.stripe\.dao\.gen.*"/> | ||
</Match> | ||
<Bug pattern="EI_EXPOSE_REP"/> | ||
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. Ignoring |
||
<Bug pattern="EI_EXPOSE_REP2"/> | ||
<Bug pattern="NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE"/> | ||
</FindBugsFilter> |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||
/* | ||||
* Copyright 2020-2022 Equinix, Inc | ||||
* Copyright 2014-2022 The Billing Project, LLC | ||||
* | ||||
* The Billing Project 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.killbill.billing.plugin.stripe; | ||||
|
||||
import org.killbill.billing.osgi.libs.killbill.OSGIMetricRegistry; | ||||
import org.killbill.billing.osgi.libs.killbill.OSGIServiceNotAvailable; | ||||
import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | ||||
|
||||
public class MetricsGenerator { | ||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MetricsGenerator.class); | ||||
|
||||
private final Thread thread; | ||||
|
||||
private volatile boolean stopMetrics; | ||||
|
||||
public MetricsGenerator(final OSGIMetricRegistry metricRegistry) { | ||||
this.thread = new Thread(new Runnable() { | ||||
public void run() { | ||||
while (!stopMetrics) { | ||||
try { | ||||
Thread.sleep(1000L); | ||||
} catch (final InterruptedException ignored) { | ||||
Thread.currentThread().interrupt(); | ||||
logger.info("MetricsGenerator shutting down..."); | ||||
break; | ||||
} | ||||
|
||||
try { | ||||
metricRegistry.getMetricRegistry().counter("stripe_plugin_counter").inc(1); | ||||
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. This code snippet from the hello world plugin is really just an example. We probably don't want it in plugins that are used in production code 😉 You could add something more useful here for instance: killbill-stripe-plugin/src/main/java/org/killbill/billing/plugin/stripe/StripePaymentPluginApi.java Line 573 in 8eb30d7
Same for other Stripe client API calls. |
||||
} catch (final OSGIServiceNotAvailable ignored) { | ||||
logger.warn("No MetricRegistry available"); | ||||
} | ||||
} | ||||
} | ||||
}); | ||||
} | ||||
|
||||
public void start() { | ||||
thread.start(); | ||||
} | ||||
|
||||
public void stop() { | ||||
stopMetrics = true; | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ public class StripeActivator extends KillbillActivatorBase { | |
|
||
private StripeConfigPropertiesConfigurationHandler stripeConfigPropertiesConfigurationHandler; | ||
|
||
private MetricsGenerator metricsGenerator; | ||
|
||
@Override | ||
public void start(final BundleContext context) throws Exception { | ||
super.start(context); | ||
|
@@ -60,6 +62,10 @@ public void start(final BundleContext context) throws Exception { | |
final StripeHealthcheck stripeHealthcheck = new StripeHealthcheck(stripeConfigPropertiesConfigurationHandler); | ||
registerHealthcheck(context, stripeHealthcheck); | ||
|
||
// Expose metrics (optional) | ||
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. Not optional anymore 😄 |
||
metricsGenerator = new MetricsGenerator(metricRegistry); | ||
metricsGenerator.start(); | ||
|
||
// Register the payment plugin | ||
Stripe.setAppInfo("Kill Bill", "7.2.0", "https://killbill.io"); | ||
final StripePaymentPluginApi pluginApi = new StripePaymentPluginApi(stripeConfigPropertiesConfigurationHandler, | ||
|
@@ -87,6 +93,12 @@ public void start(final BundleContext context) throws Exception { | |
registerHandlers(); | ||
} | ||
|
||
@Override | ||
public void stop(final BundleContext context) throws Exception { | ||
metricsGenerator.stop(); | ||
super.stop(context); | ||
} | ||
|
||
public void registerHandlers() { | ||
final PluginConfigurationEventHandler handler = new PluginConfigurationEventHandler(stripeConfigPropertiesConfigurationHandler); | ||
dispatcher.registerEventHandlers(handler); | ||
|
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.
Could you confirm this is now fixed, by running the integration tests?
This has been a long standing bug in
jooq
that has prevented us from upgrading. It would be very good news if it's now addressed, many plugins could be upgraded.