github.com/polarismesh/polaris@v1.17.8/apiserver/httpserver/report_access.go (about)

     1  /**
     2   * Tencent is pleased to support the open source community by making Polaris available.
     3   *
     4   * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     5   *
     6   * Licensed under the BSD 3-Clause License (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at
     9   *
    10   * https://opensource.org/licenses/BSD-3-Clause
    11   *
    12   * Unless required by applicable law or agreed to in writing, software distributed
    13   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    14   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
    15   * specific language governing permissions and limitations under the License.
    16   */
    17  
    18  package httpserver
    19  
    20  import (
    21  	"context"
    22  
    23  	"github.com/emicklei/go-restful/v3"
    24  
    25  	httpcommon "github.com/polarismesh/polaris/apiserver/httpserver/utils"
    26  )
    27  
    28  func (h *HTTPServer) GetClientServer(ws *restful.WebService) error {
    29  	ws.Route(ws.GET("/clients").To(h.GetReportClients))
    30  	return nil
    31  }
    32  
    33  func (h *HTTPServer) GetReportClients(req *restful.Request, rsp *restful.Response) {
    34  	handler := &httpcommon.Handler{
    35  		Request:  req,
    36  		Response: rsp,
    37  	}
    38  
    39  	queryParams := httpcommon.ParseQueryParams(req)
    40  	ctx := handler.ParseHeaderContext()
    41  	ret := h.namingServer.GetPrometheusTargets(ctx, queryParams)
    42  
    43  	_ = rsp.WriteAsJson(ret)
    44  }
    45  
    46  // GetPrometheusDiscoveryServer 注册用于prometheus服务发现的接口
    47  func (h *HTTPServer) GetPrometheusDiscoveryServer(include []string) (*restful.WebService, error) {
    48  	ws := new(restful.WebService)
    49  	ws.Path("/prometheus/v1").Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON)
    50  	h.addPrometheusDefaultAccess(ws)
    51  	return ws, nil
    52  }
    53  
    54  func (h *HTTPServer) addPrometheusDefaultAccess(ws *restful.WebService) {
    55  	ws.Route(ws.GET("/clients").To(h.GetPrometheusClients))
    56  }
    57  
    58  // GetPrometheusClients 对接 prometheus 基于 http 的 service discovery
    59  func (h *HTTPServer) GetPrometheusClients(req *restful.Request, rsp *restful.Response) {
    60  	queryParams := httpcommon.ParseQueryParams(req)
    61  	ret := h.namingServer.GetPrometheusTargets(context.Background(), queryParams)
    62  	_ = rsp.WriteAsJson(ret.Response)
    63  }