From af27d1772d3088c0671ed74d6296a634e57a99ed Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 31 Jan 2024 12:03:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(cloud):=20=E5=A2=9E=E5=8A=A0prometheus?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=8E=B7=E5=8F=96=E5=AE=9E=E4=BE=8B=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/httpRequests/http-requests-log.http | 140 +++++++++--------- .../service/cloud/CloudController.java | 14 ++ .../cloud/entity/PrometheusTarget.java | 36 +++++ test/test.http | 5 +- 4 files changed, 124 insertions(+), 71 deletions(-) create mode 100644 service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/entity/PrometheusTarget.java diff --git a/.idea/httpRequests/http-requests-log.http b/.idea/httpRequests/http-requests-log.http index 457b7af..fcfe7e3 100644 --- a/.idea/httpRequests/http-requests-log.http +++ b/.idea/httpRequests/http-requests-log.http @@ -1,3 +1,73 @@ +GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_cloud_query/cloud/targets +Connection: Keep-Alive +User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) +Cookie: JSESSIONID=82403D318FAEAAA09F215DA39DCB41FE +Accept-Encoding: br,deflate,gzip,x-gzip + +<> 2024-01-31T105823.200.json + +### + +GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_cloud_query/cloud/targets +Connection: Keep-Alive +User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) +Cookie: JSESSIONID=82403D318FAEAAA09F215DA39DCB41FE +Accept-Encoding: br,deflate,gzip,x-gzip + +<> 2024-01-31T105819.404.json + +### + +GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_cloud_query/cloud/targets +Connection: Keep-Alive +User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) +Cookie: JSESSIONID=3809A2F1A78D12F02D47F709504B0FDC +Accept-Encoding: br,deflate,gzip,x-gzip + +<> 2024-01-31T105750.404.json + +### + +GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_cloud_query/cloud/targets +Connection: Keep-Alive +User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) +Cookie: JSESSIONID=3809A2F1A78D12F02D47F709504B0FDC +Accept-Encoding: br,deflate,gzip,x-gzip + +<> 2024-01-31T105744.404.json + +### + +GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_cloud_query/cloud/services?service_name=service-gateway +Connection: Keep-Alive +User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) +Cookie: JSESSIONID=D3453177E948A070A4BCC930DCDDE188 +Accept-Encoding: br,deflate,gzip,x-gzip + +<> 2024-01-31T104803.200.json + +### + +GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_cloud_query/cloud/services?service_name=center-gateway-new +Connection: Keep-Alive +User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) +Cookie: JSESSIONID=A489280C82FB7E8BA81909F8812DA0FB +Accept-Encoding: br,deflate,gzip,x-gzip + +<> 2024-01-31T104754.200.json + +### + +GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_web/cloud/list +Connection: Keep-Alive +User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) +Cookie: JSESSIONID=1B7C9D76DE2F888A0F0AB4EAF3CFFC19 +Accept-Encoding: br,deflate,gzip,x-gzip + +<> 2024-01-31T104721.200.json + +### + GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@b12s25.hdp.dc:36781/queue/clear/compaction-queue-pre Connection: Keep-Alive User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) @@ -392,73 +462,3 @@ Accept-Encoding: br,deflate,gzip,x-gzip ### -GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_scheduler/schedule/schedule_times -Connection: Keep-Alive -User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) -Cookie: JSESSIONID=0C3AEB91AD103B11FD674356CB0FCC2B -Accept-Encoding: br,deflate,gzip,x-gzip - -<> 2024-01-15T144539.200.json - -### - -GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_scheduler/schedule/schedule_times -Connection: Keep-Alive -User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) -Cookie: JSESSIONID=0C3AEB91AD103B11FD674356CB0FCC2B -Accept-Encoding: br,deflate,gzip,x-gzip - -<> 2024-01-15T144500.200.json - -### - -GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_scheduler/schedule/schedule_times -Connection: Keep-Alive -User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) -Cookie: JSESSIONID=E854FA8E5E26010DB1870C60EF6643D1 -Accept-Encoding: br,deflate,gzip,x-gzip - -<> 2024-01-15T144458.200.json - -### - -GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_scheduler/schedule/schedule_times -Connection: Keep-Alive -User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) -Cookie: JSESSIONID=E854FA8E5E26010DB1870C60EF6643D1 -Accept-Encoding: br,deflate,gzip,x-gzip - -<> 2024-01-15T143420.200.json - -### - -GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_scheduler/schedule/schedule_times -Connection: Keep-Alive -User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) -Cookie: JSESSIONID=E854FA8E5E26010DB1870C60EF6643D1 -Accept-Encoding: br,deflate,gzip,x-gzip - -<> 2024-01-15T143315.200.json - -### - -GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_scheduler/schedule/schedule_times -Connection: Keep-Alive -User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) -Cookie: JSESSIONID=E854FA8E5E26010DB1870C60EF6643D1 -Accept-Encoding: br,deflate,gzip,x-gzip - -<> 2024-01-15T143306.200.json - -### - -GET http://AxhEbscwsJDbYMH2:cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4@132.126.207.130:35690/hudi_services/service_scheduler/schedule/schedule_times -Connection: Keep-Alive -User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.9) -Cookie: JSESSIONID=E854FA8E5E26010DB1870C60EF6643D1 -Accept-Encoding: br,deflate,gzip,x-gzip - -<> 2024-01-15T143304.200.json - -### - diff --git a/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java index a7a1b0e..591e1e8 100644 --- a/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java +++ b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/CloudController.java @@ -1,8 +1,11 @@ package com.lanyuanxiaoyao.service.cloud; import cn.hutool.core.util.StrUtil; +import com.lanyuanxiaoyao.service.cloud.entity.PrometheusTarget; import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.list.ImmutableList; +import org.eclipse.collections.api.map.ImmutableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.client.discovery.DiscoveryClient; @@ -49,4 +52,15 @@ public class CloudController { .toSortedList() .toImmutable(); } + + @GetMapping("targets") + public ImmutableList prometheusTargets() { + return Lists.immutable.ofAll(client.getServices()) + .collect(name -> { + ImmutableList targets = Lists.immutable.ofAll(client.getInstances(name)) + .collect(instance -> instance.getUri().toString()); + ImmutableMap labels = Maps.immutable.of("application", name); + return new PrometheusTarget(targets, labels); + }); + } } diff --git a/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/entity/PrometheusTarget.java b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/entity/PrometheusTarget.java new file mode 100644 index 0000000..f10d2a0 --- /dev/null +++ b/service-cloud-query/src/main/java/com/lanyuanxiaoyao/service/cloud/entity/PrometheusTarget.java @@ -0,0 +1,36 @@ +package com.lanyuanxiaoyao.service.cloud.entity; + +import org.eclipse.collections.api.list.ImmutableList; +import org.eclipse.collections.api.map.ImmutableMap; + +/** + * Prometheus服务发现 + * + * @author lanyuanxiaoyao + * @date 2024-01-31 + */ +public class PrometheusTarget { + private final ImmutableList targets; + private final ImmutableMap labels; + + public PrometheusTarget(ImmutableList targets, ImmutableMap labels) { + this.targets = targets; + this.labels = labels; + } + + public ImmutableList getTargets() { + return targets; + } + + public ImmutableMap getLabels() { + return labels; + } + + @Override + public String toString() { + return "PrometheusTarget{" + + "ips=" + targets + + ", labels=" + labels + + '}'; + } +} diff --git a/test/test.http b/test/test.http index efcc68f..4de7780 100644 --- a/test/test.http +++ b/test/test.http @@ -73,7 +73,10 @@ GET http://132.122.116.149:35680/api/message_id?flink_job_id=1542097984132706304 GET {{web-url}}/cloud/deploy_plan ### Get info query services -GET {{services-url}}/cloud/services?service_name=center-gateway-new +GET {{services-url}}/cloud/services?service_name=service-gateway + +### Get Prometheus targets +GET {{services-url}}/cloud/targets ### Sync status GET {{web-url}}/overview/sync_running_status