From f345b08bb25fb38745843c282b77e5219aba9cfd Mon Sep 17 00:00:00 2001 From: Vijay Nandwana Date: Mon, 11 Apr 2022 12:55:49 +0530 Subject: [PATCH 1/2] * Added metrics generator * Replaced javax.servlet with Jakarta servlet. --- .github/workflows/ci.yml | 1 + pom.xml | 20 +++--- spotbugs-exclude.xml | 3 + .../plugin/stripe/MetricsGenerator.java | 62 +++++++++++++++++++ .../plugin/stripe/StripeActivator.java | 12 ++++ 5 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/killbill/billing/plugin/stripe/MetricsGenerator.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 267c32e..bf442f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,7 @@ name: ci on: - push + - pull_request - workflow_dispatch env: 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); From d64e4577d459ea19e4b7af93c8a20672d1aabc1f Mon Sep 17 00:00:00 2001 From: Vijay Nandwana Date: Mon, 11 Apr 2022 17:04:12 +0530 Subject: [PATCH 2/2] * Added metrics generator * Replaced javax.servlet with Jakarta servlet. --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf442f7..267c32e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,6 @@ name: ci on: - push - - pull_request - workflow_dispatch env: