Skip to content
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

Open
wants to merge 2 commits into
base: work-for-release-0.23.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.kill-bill.billing</groupId>
<artifactId>killbill-oss-parent</artifactId>
<version>0.144.58</version>
<version>0.145.3-c9eb563-SNAPSHOT</version>
</parent>
<groupId>org.kill-bill.billing.plugin.java</groupId>
<artifactId>stripe-plugin</artifactId>
Expand Down Expand Up @@ -85,13 +85,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
Expand All @@ -114,8 +114,7 @@
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<!-- 3.14.0 broke returning() on MySQL :( -->
Copy link
Member

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?

export STRIPE_API_KEY=...
export STRIPE_PUBLIC_KEY=...
mvn test -Pintegration-mysql

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.

<version>3.13.5</version>
<version>3.14.15</version>
</dependency>
<dependency>
<groupId>org.kill-bill.billing</groupId>
Expand Down Expand Up @@ -173,6 +172,11 @@
<artifactId>killbill-embeddeddb-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kill-bill.commons</groupId>
<artifactId>killbill-metrics-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
<Match>
<Class name="~org\.killbill\.billing\.plugin\.stripe\.dao\.gen.*"/>
</Match>
<Bug pattern="EI_EXPOSE_REP"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring EI_EXPOSE_REP and EI_EXPOSE_REP2 is probably fine, however NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE seems a bit suspicious. Can you investigate what's triggering this?

<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);
Copy link
Member

Choose a reason for hiding this comment

The 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:

return intent.capture(paymentIntentParams, requestOptions);

try {
  return intent.capture(paymentIntentParams, requestOptions);
} finally {
  metricRegistry.getMetricRegistry().counter("stripe_capture").inc(1);
}

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
Expand Up @@ -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);
Expand All @@ -60,6 +62,10 @@ public void start(final BundleContext context) throws Exception {
final StripeHealthcheck stripeHealthcheck = new StripeHealthcheck(stripeConfigPropertiesConfigurationHandler);
registerHealthcheck(context, stripeHealthcheck);

// Expose metrics (optional)
Copy link
Member

Choose a reason for hiding this comment

The 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,
Expand Down Expand Up @@ -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);
Expand Down