-
Notifications
You must be signed in to change notification settings - Fork 4
/
promproxy.go
150 lines (130 loc) · 4.13 KB
/
promproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Package promproxy provides Prometheus proxy for observability and research.
package promproxy
import (
"context"
"net/http"
"github.com/go-faster/errors"
"github.com/go-faster/sdk/zctx"
"go.uber.org/zap"
"github.com/go-faster/oteldb/internal/promapi"
)
var _ promapi.Handler = &Server{}
// NewServer initializes new proxy Server from openapi client.
func NewServer(api *promapi.Client) *Server {
return &Server{
api: api,
}
}
// Server implement proxy server.
type Server struct {
api *promapi.Client
}
// GetLabelValues implements getLabelValues operation.
// GET /api/v1/label/{label}/values
func (s *Server) GetLabelValues(ctx context.Context, params promapi.GetLabelValuesParams) (*promapi.LabelValuesResponse, error) {
return s.api.GetLabelValues(ctx, params)
}
// GetLabels implements getLabels operation.
//
// GET /api/v1/labels
func (s *Server) GetLabels(ctx context.Context, params promapi.GetLabelsParams) (*promapi.LabelsResponse, error) {
return s.api.GetLabels(ctx, params)
}
// GetMetadata implements getMetadata operation.
//
// GET /api/v1/metadata
func (s *Server) GetMetadata(ctx context.Context, params promapi.GetMetadataParams) (*promapi.MetadataResponse, error) {
return s.api.GetMetadata(ctx, params)
}
// GetQuery implements getQuery operation.
//
// Query Prometheus.
//
// GET /api/v1/query
func (s *Server) GetQuery(ctx context.Context, params promapi.GetQueryParams) (*promapi.QueryResponse, error) {
return s.api.GetQuery(ctx, params)
}
// GetQueryExemplars implements getQueryExemplars operation.
//
// Query Prometheus.
//
// GET /api/v1/query_examplars
func (s *Server) GetQueryExemplars(ctx context.Context, params promapi.GetQueryExemplarsParams) (*promapi.QueryExemplarsResponse, error) {
return s.api.GetQueryExemplars(ctx, params)
}
// GetQueryRange implements getQueryRange operation.
//
// Query Prometheus.
//
// GET /api/v1/query_range
func (s *Server) GetQueryRange(ctx context.Context, params promapi.GetQueryRangeParams) (*promapi.QueryResponse, error) {
return s.api.GetQueryRange(ctx, params)
}
// GetRules implements getRules operation.
//
// GET /api/v1/rules
func (s *Server) GetRules(ctx context.Context, params promapi.GetRulesParams) (*promapi.RulesResponse, error) {
return s.api.GetRules(ctx, params)
}
// GetSeries implements getSeries operation.
// Query Prometheus.
//
// GET /api/v1/series
func (s *Server) GetSeries(ctx context.Context, params promapi.GetSeriesParams) (*promapi.SeriesResponse, error) {
return s.api.GetSeries(ctx, params)
}
// PostLabels implements postLabels operation.
//
// POST /api/v1/labels
func (s *Server) PostLabels(ctx context.Context) (*promapi.LabelsResponse, error) {
return s.api.PostLabels(ctx)
}
// PostQuery implements postQuery operation.
//
// Query Prometheus.
//
// POST /api/v1/query
func (s *Server) PostQuery(ctx context.Context, req *promapi.QueryForm) (*promapi.QueryResponse, error) {
return s.api.PostQuery(ctx, req)
}
// PostQueryExemplars implements postQueryExemplars operation.
//
// Query Prometheus.
//
// POST /api/v1/query_examplars
func (s *Server) PostQueryExemplars(ctx context.Context) (*promapi.QueryExemplarsResponse, error) {
return s.api.PostQueryExemplars(ctx)
}
// PostQueryRange implements postQueryRange operation.
//
// Query Prometheus.
//
// POST /api/v1/query_range
func (s *Server) PostQueryRange(ctx context.Context, req *promapi.QueryRangeForm) (*promapi.QueryResponse, error) {
return s.api.PostQueryRange(ctx, req)
}
// PostSeries implements postSeries operation.
//
// Query Prometheus.
//
// POST /api/v1/series
func (s *Server) PostSeries(ctx context.Context) (*promapi.SeriesResponse, error) {
return s.api.PostSeries(ctx)
}
// NewError creates *FailStatusCode from error returned by handler.
//
// Used for common default response.
func (s Server) NewError(ctx context.Context, err error) *promapi.FailStatusCode {
zctx.From(ctx).Error("API Error", zap.Error(err))
if v, ok := errors.Into[*promapi.FailStatusCode](err); ok {
// Pass as-is.
return v
}
return &promapi.FailStatusCode{
StatusCode: http.StatusInternalServerError,
Response: promapi.Fail{
Error: err.Error(),
ErrorType: promapi.FailErrorTypeInternal,
},
}
}