Observability Dev Services

我们已经熟悉了 Dev Service 的概念,但在可观察性的情况下,我们需要一种编排和连接多个开发服务的方法,通常是整个服务堆栈;比如定期抓取应用程序度量指标的度量指标代理,将其推送到时序数据库,Grafana 提供该时序数据的图形。

We are already familiar with Dev Service concept, but in the case of Observability we need a way to orchestrate and connect more than a single dev service, usually a whole stack of them; e.g. a metrics agent periodically scraping application for metrics, pushing them into timeseries database, and Grafana feeding graphs of this timeseries data.

考虑到这一点,我们添加了一个新的概念,即开发资源,这是开发服务概念和 Testcontainers 之间的适配器。由于我们现在有了细粒度的服务(每个容器都有开发资源),我们还可以进一步扩展,允许用户选择使用此新开发资源概念的方式:

With this in mind, we added a new concept of Dev Resource, an adapter between Dev Service concept and Testcontainers. And since we now have fine-grained services - with the Dev Resource per container, we can take this even further, allowing the user to choose the way to use this new Dev Resource concept:

每个开发资源实现也是一个 @QuarkusTestResourceLifecycleManager 实现

Each Dev Resource implementation is an @QuarkusTestResourceLifecycleManager implementation as well

  • leave it to Dev Services to pick-up various Dev Resources from classpath, and apply Dev Service concept to it

  • explicitly disable Dev Services and enable Dev Resources and use less-heavy concept of starting and stopping Dev Resources

  • explicitly disable both Dev Services and Dev Resources, and use Quarkus' @WithTestResource testing concept (see Note)

你可以添加可观察性扩展依赖项和必要的开发资源依赖项,或者使用现有的 sinks- pom.xml 文件,这些文件会添加可观察性扩展依赖项以及特定技术栈所需的其他依赖项;例如,victoriametrics 接收器将包含 quarkus-observability-devresource-victoriametricsquarkus-victoriametrics-client 依赖项,这些依赖项已经包含在 pom.xml 中。

You can either add Observability extension dependency along with needed Dev Resources dependencies, or you use existing sinks - pom.xml files which add Observability extension dependency along with other required dependencies for certain technology stacks; e.g. victoriametrics sink would have quarkus-observability-devresource-victoriametrics and quarkus-victoriametrics-client dependencies already included in the pom.xml.

确保将这些接收器依赖项的 scope 设置为 provided,否则 Testcontainers 等库会最终进入你的应用的生产库中:

Make sure you set the scope of these sink dependencies to provided, otherwise libraries such as Testcontainers will end-up in your app’s production libraries:

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-observability-devservices-...</artifactId>
            <scope>provided</scope> <!-- !! -->
        </dependency>

让我们实际看看所有这一切,采用通常的 all-in-one Grafana 用法,以 OTel-LGTM Docker 镜像的形式。

Let’s see how all of this looks in practice, with the usual all-in-one Grafana usage, in the form of OTel-LGTM Docker image.