diff --git a/pom.xml b/pom.xml
index 0c2a869..cbf46fd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
org.kill-bill.billing
killbill-oss-parent
- 0.144.58
+ 0.145.3-c9eb563-SNAPSHOT
org.kill-bill.billing.plugin.java
stripe-plugin
@@ -85,13 +85,13 @@
test
- javax.inject
- javax.inject
+ jakarta.servlet
+ jakarta.servlet-api
+ provided
- javax.servlet
- javax.servlet-api
- provided
+ javax.inject
+ javax.inject
joda-time
@@ -114,8 +114,7 @@
org.jooq
jooq
-
- 3.13.5
+ 3.14.15
org.kill-bill.billing
@@ -173,6 +172,11 @@
killbill-embeddeddb-common
test
+
+ org.kill-bill.commons
+ killbill-metrics-api
+ provided
+
org.mockito
mockito-core
diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml
index bd9f29c..aaf496e 100644
--- a/spotbugs-exclude.xml
+++ b/spotbugs-exclude.xml
@@ -19,4 +19,7 @@
+
+
+
diff --git a/src/main/java/org/killbill/billing/plugin/stripe/MetricsGenerator.java b/src/main/java/org/killbill/billing/plugin/stripe/MetricsGenerator.java
new file mode 100644
index 0000000..ebbdc68
--- /dev/null
+++ b/src/main/java/org/killbill/billing/plugin/stripe/MetricsGenerator.java
@@ -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);
+ } catch (final OSGIServiceNotAvailable ignored) {
+ logger.warn("No MetricRegistry available");
+ }
+ }
+ }
+ });
+ }
+
+ public void start() {
+ thread.start();
+ }
+
+ public void stop() {
+ stopMetrics = true;
+ }
+}
diff --git a/src/main/java/org/killbill/billing/plugin/stripe/StripeActivator.java b/src/main/java/org/killbill/billing/plugin/stripe/StripeActivator.java
index ff04018..3649dce 100644
--- a/src/main/java/org/killbill/billing/plugin/stripe/StripeActivator.java
+++ b/src/main/java/org/killbill/billing/plugin/stripe/StripeActivator.java
@@ -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)
+ 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);