Search code examples
javaspring-integrationprometheusspring-integration-dsl

Get all Spring integration channel names at startup - Initializing Spring Integration Metrics at startup


Unfortunately Spring Integration metrics are registered when they are first used.

https://stackoverflow.com/a/63619360/13657000

this means that prometheus query functions like increase give incorrect calculations.

Is there a way to get all channel names in Spring integration so that I can initialize metrics for each channel?

I'm using dsl.

I looked at this https://gist.github.com/flopezluis/2964429 but they find their channel names using XML.

Any help is appreciated, thanks.


Solution

  • I'm not sure why you need names of channels since the story is really about calling a MessageChannel.send(), so you perhaps just need an ApplicationContext.getBeansOfType(MessageChannel.class). Pay attention though, that sending a message to the channel will trigger not only metrics registration but also their consumption on the other side. Therefore you might need to think about filtering these "initial" messages somehow before they reach your real consumer.

    On the other hand I wonder if there is some Micrometer option to make those timer metrics to be registered eagerly even if we don't produce messages yet. Just call registry.timer() as early as possible?