启动 zipkin 服务器时出错:Prometheus 要求所有具有相同名称的仪表具有相同的标签键集

Posted

技术标签:

【中文标题】启动 zipkin 服务器时出错:Prometheus 要求所有具有相同名称的仪表具有相同的标签键集【英文标题】:Getting error while starting zipkin server : Prometheus requires that all meters with the same name have the same set of tag keys 【发布时间】:2020-11-14 08:07:06 【问题描述】:

我们在其他微服务中有slueth,我们想将数据发送到 zipkin 服务器以进行合并日志记录。我正在尝试启动我的 zipkin 服务器。我收到以下错误:

java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named 'http_server_requests_seconds' containing tag keys [exception, method, status, uri]. The meter you are attempting to register has keys [method, status, uri].
    at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$collectorByName$9(PrometheusMeterRegistry.java:360) ~[micrometer-registry-prometheus-1.0.8.jar:1.0.8]
    at java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1877) ~[na:1.8.0_231]
    at io.micrometer.prometheus.PrometheusMeterRegistry.collectorByName(PrometheusMeterRegistry.java:347) ~[micrometer-registry-prometheus-1.0.8.jar:1.0.8]
    at io.micrometer.prometheus.PrometheusMeterRegistry.newTimer(PrometheusMeterRegistry.java:160) ~[micrometer-registry-prometheus-1.0.8.jar:1.0.8]
    at io.micrometer.core.instrument.MeterRegistry.lambda$timer$2(MeterRegistry.java:258) ~[micrometer-core-1.0.8.jar:1.0.8]
    at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:567) ~[micrometer-core-1.0.8.jar:1.0.8]
    at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:529) ~[micrometer-core-1.0.8.jar:1.0.8]
    at io.micrometer.core.instrument.MeterRegistry.timer(MeterRegistry.java:256) ~[micrometer-core-1.0.8.jar:1.0.8]
    at io.micrometer.core.instrument.Timer$Builder.register(Timer.java:447) ~[micrometer-core-1.0.8.jar:1.0.8]
    at zipkin2.autoconfigure.prometheus.ZipkinPrometheusMetricsAutoConfiguration$HttpRequestDurationHandler.lambda$handleRequest$0(ZipkinPrometheusMetricsAutoConfiguration.java:78) ~[zipkin-autoconfigure-metrics-prometheus-2.11.7.jar:na]
    at io.undertow.server.HttpServerExchange.invokeExchangeCompleteListeners(HttpServerExchange.java:1276) ~[undertow-core-1.4.26.Final.jar:1.4.26.Final]
    at io.undertow.server.HttpServerExchange.terminateResponse(HttpServerExchange.java:1558) ~[undertow-core-1.4.26.Final.jar:1.4.26.Final]
    at io.undertow.server.Connectors.terminateResponse(Connectors.java:143) ~[undertow-core-1.4.26.Final.jar:1.4.26.Final]
    at io.undertow.server.protocol.http.ServerFixedLengthStreamSinkConduit.channelFinished(ServerFixedLengthStreamSinkConduit.java:58) ~[undertow-core-1.4.26.Final.jar:1.4.26.Final]
    at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.exitFlush(AbstractFixedLengthStreamSinkConduit.java:316) ~[undertow-core-1.4.26.Final.jar:1.4.26.Final]
    at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.flush(AbstractFixedLengthStreamSinkConduit.java:234) ~[undertow-core-1.4.26.Final.jar:1.4.26.Final]
    at org.xnio.conduits.ConduitStreamSinkChannel.flush(ConduitStreamSinkChannel.java:162) ~[xnio-api-3.3.8.Final.jar:3.3.8.Final]
    at io.undertow.channels.DetachableStreamSinkChannel.flush(DetachableStreamSinkChannel.java:119) ~[undertow-core-1.4.26.Final.jar:1.4.26.Final]
    at org.xnio.channels.Channels.flushBlocking(Channels.java:63) ~[xnio-api-3.3.8.Final.jar:3.3.8.Final]
    at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputStreamImpl.java:617) ~[undertow-servlet-1.4.26.Final.jar:1.4.26.Final]
    at io.undertow.servlet.spec.HttpServletResponseImpl.closeStreamAndWriter(HttpServletResponseImpl.java:481) ~[undertow-servlet-1.4.26.Final.jar:1.4.26.Final]

我尝试使用 sleuth 和 zipkin 旧版本,但出现冲突和 spring 应用程序无法启动 我们看不到 Zipkin UI。 而pom.xml 就像:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.zipkin.server</groupId>
    <artifactId>zipkin-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>zipkin-server</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.7.RELEASE</version>
        <relativePath/> 
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>2.11.7</version>
        </dependency>

        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>2.11.7</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

任何建议都会有所帮助。

【问题讨论】:

你在类路径上没有侦探。 谢谢@marcin-grzejszczak。我们在项目中添加了 spring-cloud-starter-sleuth 和 spring-cloud-starter-zipkin 依赖项。我们还需要做什么?在类路径中添加 slueth 请阅读文档cloud.spring.io/spring-cloud-static/spring-cloud-sleuth/…并查看参考示例github.com/spring-cloud-samples/sleuth-documentation-apps 无需自建zipkin服务器:zipkin.io/pages/quickstart.html 【参考方案1】:

你应该创建 application.properties 文件,然后你应该添加以下内容

你的 application.properties :

server.port:9411 // Not Required
management.metrics.web.server.auto-time-requests=false //Required

你的主要课程:

import zipkin.server.EnableZipkinServer;

@EnableZipkinServer
@SpringBootApplication
public class ZipkinServerApplication 

    public static void main(String[] args) 
        SpringApplication.run(ZipkinServerApplication.class, args);

    


你的 Pom.xml :

 <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>zipkin-server</artifactId>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.7.RELEASE</version>
        <relativePath />
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>2.11.7</version>
        </dependency>

        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>2.11.7</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

你的 zipkin 端口:

http://localhost:9411/zipkin

【讨论】:

以上是关于启动 zipkin 服务器时出错:Prometheus 要求所有具有相同名称的仪表具有相同的标签键集的主要内容,如果未能解决你的问题,请参考以下文章

spring cloud分布式整合zipkin的链路跟踪

Zipkin_Slueth微服务链式追踪

Zipkin_Slueth微服务链式追踪

深入探究ZIPKIN调用链跟踪——拓扑Dependencies篇

ubuntu部署使用zipkin链路追踪

第二十七章 springboot + zipkin(brave-okhttp实现)