OK thank you, I’ll try that way.

So I need either to implement a bundle that will get the names of other bundles 
it should register metrics for, or I should build metrics in specific bundles, 
and in case I’d like to have karaf-wide Prometheus metrics collection I’d need 
to modify WebContainer implementation?

Are there any plans to provide build-in Prometheus metrics collection in 
pax-web?

Best regards,
Lukasz Lech


From: [email protected] [mailto:[email protected]] On Behalf Of 
Grzegorz Grzybek
Sent: Mittwoch, 17. Oktober 2018 08:14
To: [email protected]
Subject: Re: [PAX-WEB] WebContainer - registering ServletFilter - confusion

Hello

First, the most important line in your code is:

WebContainer webContainer = (WebContainer) context.getService(reference);

And especially "context" you're using. pax-web in general and 
"registerFilter()" method in particular is an attempt to implement concepts 
from javax.servlet specification (concepts from WEB-INF/web.xml) in OSGi.
Short - you're registering filter in different context than the one you have 
your servlets you want to filter. Even in JavaEE you can't have a filter that's 
filtering servlets in different contexts.

You can however grab a BundleContext from different bundle - just get the 
single (or even more) Bundle from context.getBundles() by symbolic name for 
example and get its context - then grab WebContainer service from this context 
instead of the context you're given in BundleActivator.start().

regards
Grzegorz Grzybek

wt., 16 paź 2018 o 15:05 Lukasz Lech 
<[email protected]<mailto:[email protected]>> napisał(a):
Hello,

I’m trying to register io.prometheus.client.filter.MetricsFilter for Prometheus 
metrics.

I’m trying to call registerFilter() with many possible url patterns, but none 
seem to have any affect:

  @Override
  public void start(BundleContext context) throws Exception
  {
    webContainerTracker = new WebContainerTracker(context);
    webContainerTracker.open();
  }

  @Override
  public Object addingService(ServiceReference reference)
  {
    WebContainer webContainer = (WebContainer) context.getService(reference);
    this.metricsFilter = new MetricsFilter();
    webContainer.registerFilter(metricsFilter, new String[]{"/", "*", "/*"}, 
null, null, false, null);
    return webContainer;
  }

Expected behavior:
Any request to Karaf, including opening WebConsole, would land me in 
MetricsFilter.doFilter breakpoint
Observed behavior:
Nothing, even init() method is not called.

Do wildcards are supported by WebContainer for registering filters? Or not 
every request goes through that filters, and I’d need to register filter on 
jetty directly? (how?, Jetty seems not to be exposed in OSGi context).

I’m using JaxRS-Publisher that registers servlets using 
HttpService.addServlet() (and WebContainer is the only available 
implementation).

WebConsole also uses WebContainer, so I assume, it must register servlets also 
using that method.

Where is the problem? What I’m doing wrong?

Best regards,
Lukasz Lech

--
--
------------------
OPS4J - http://www.ops4j.org - 
[email protected]<mailto:[email protected]>

---
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.
--
--
------------------
OPS4J - http://www.ops4j.org - 
[email protected]<mailto:[email protected]>

---
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to