weixiaohui-1/nacos-consul-adapter

数据结构有问题,prometheus无法解析

pan003 opened this issue · 2 comments

level=error ts=2022-06-20T16:09:49.955143007Z caller=consul.go:470 component="discovery manager scrape" discovery=consul msg="Error refreshing service" service=consul-adapter-gateway tag= err="json: cannot unmarshal object into Go struct field CatalogService.Node of type string"
level=error ts=2022-06-20T16:09:49.960731235Z caller=consul.go:470 component="discovery manager scrape" discovery=consul msg="Error refreshing service" service=monitor-prometheus tag= err="json: cannot unmarshal object into Go struct field CatalogService.Node of type string"

prometheus版本
$ ./prometheus --version
prometheus, version 2.8.1 (branch: HEAD, revision: 4d60eb36dcbed725fcac5b27018574118f12fffb)
build user: root@bfdd6a22a683
build date: 20190328-18:04:08
go version: go1.11.6

adapter项目依赖版本信息:

<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.3.7.RELEASE</spring-boot.version>
<spring-cloud-alibaba.version>2.2.2.RELEASE</spring-cloud-alibaba.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>

spring-cloud-starter-alibaba-nacos-discovery 2.2.6
nacos-consul-adapter 0.0.4.M
spring-cloud-starter-gateway 2.2.6
nacos-server 2.0.4

从伪装的adapter中获取的service信息与从consul接口中取得的信息,数据结构不一致:

adapter获取到的数据:
http://10.66.227.99:18848/v1/catalog/services
{"monitor-consul-prometheus":[],"monitor-prometheus":[],"monitor-test11":[],"consul-adapter-gateway":[]}

http://10.66.227.99:18848/v1/catalog/service/monitor-consul-prometheus
[
{
"Node":{
"ID":"10.66.227.91#18080#DEFAULT#DEFAULT_GROUP@@monitor-consul-prometheus",
"Address":"10.66.227.91",
"Datacenter":"dc1"
},
"Service":{
"ID":"monitor-consul-prometheus-18080",
"Service":"monitor-consul-prometheus",
"Port":18080
},
"Checks":null
}
]

consul返回的数据:
http://10.66.227.91:8500/v1/catalog/services
{
consul: [ ],
monitor-consul-prometheus: [
"secure=false"
]
}

http://10.66.227.91:8500/v1/catalog/service/monitor-consul-prometheus
[
{
"ID": "91ddf7c1-baf0-f38e-a62e-0bbfdf5e0845",
"Node": "machine",
"Address": "127.0.0.1",
"Datacenter": "dc1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"lan_ipv4": "127.0.0.1",
"wan": "127.0.0.1",
"wan_ipv4": "127.0.0.1"
},
"NodeMeta": {
"consul-network-segment": ""
},
"ServiceKind": "",
"ServiceID": "monitor-consul-prometheus-18080",
"ServiceName": "monitor-consul-prometheus",
"ServiceTags": [
"secure=false"
],
"ServiceAddress": "10.66.227.91",
"ServiceTaggedAddresses": {
"lan_ipv4": {
"Address": "10.66.227.91",
"Port": 18080
},
"wan_ipv4": {
"Address": "10.66.227.91",
"Port": 18080
}
},
"ServiceWeights": {
"Passing": 1,
"Warning": 1
},
"ServiceMeta": {},
"ServicePort": 18080,
"ServiceSocketPath": "",
"ServiceEnableTagOverride": false,
"ServiceProxy": {
"Mode": "",
"MeshGateway": {},
"Expose": {}
},
"ServiceConnect": {},
"CreateIndex": 56,
"ModifyIndex": 156
}
]

consul是什么版本

我看了一下consul文档,/v1/catalog/service/{appName}返回的格式是不对,我改一下。