MCPcopy Index your code
hub / github.com/cortexproject/cortex / NewClient

Function NewClient

integration/e2ecortex/client.go:61–112  ·  view source on GitHub ↗

NewClient makes a new Cortex client

(
	distributorAddress string,
	querierAddress string,
	alertmanagerAddress string,
	rulerAddress string,
	orgID string,
)

Source from the content-addressed store, hash-verified

59
60// NewClient makes a new Cortex client
61func NewClient(
62 distributorAddress string,
63 querierAddress string,
64 alertmanagerAddress string,
65 rulerAddress string,
66 orgID string,
67) (*Client, error) {
68 // Create querier API client
69 querierAPIClient, err := promapi.NewClient(promapi.Config{
70 Address: "http://" + querierAddress + "/api/prom",
71 RoundTripper: &addOrgIDRoundTripper{orgID: orgID, next: http.DefaultTransport},
72 })
73 if err != nil {
74 return nil, err
75 }
76
77 client := &http.Client{
78 Transport: &addOrgIDRoundTripper{orgID: orgID, next: http.DefaultTransport},
79 }
80 remoteWriteAPI, err := remoteapi.NewAPI(fmt.Sprintf("http://%s", distributorAddress),
81 remoteapi.WithAPIHTTPClient(client),
82 remoteapi.WithAPIPath("/api/prom/push"),
83 )
84 if err != nil {
85 return nil, err
86 }
87
88 c := &Client{
89 distributorAddress: distributorAddress,
90 querierAddress: querierAddress,
91 alertmanagerAddress: alertmanagerAddress,
92 rulerAddress: rulerAddress,
93 timeout: 30 * time.Second,
94 httpClient: &http.Client{},
95 querierClient: promv1.NewAPI(querierAPIClient),
96 remoteWriteAPI: remoteWriteAPI,
97 orgID: orgID,
98 }
99
100 if alertmanagerAddress != "" {
101 alertmanagerAPIClient, err := promapi.NewClient(promapi.Config{
102 Address: "http://" + alertmanagerAddress,
103 RoundTripper: &addOrgIDRoundTripper{orgID: orgID, next: http.DefaultTransport},
104 })
105 if err != nil {
106 return nil, err
107 }
108 c.alertmanagerClient = alertmanagerAPIClient
109 }
110
111 return c, nil
112}
113
114// NewPromQueryClient makes a new client but used for Prometheus Query only.
115func NewPromQueryClient(address string) (*Client, error) {

Calls

no outgoing calls