Skip to content

Commit fea8460

Browse files
committed
RPC request handler
1 parent a63d4e0 commit fea8460

File tree

16 files changed

+718
-900
lines changed

16 files changed

+718
-900
lines changed

cmd/statshouse-api/statshouse-api.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ import (
2222

2323
"github.com/cloudflare/tableflip"
2424
"github.com/gorilla/handlers"
25-
"github.com/gorilla/mux"
2625
"github.com/spf13/pflag"
2726

2827
"github.com/vkcom/statshouse-go"
2928
"github.com/vkcom/statshouse/internal/api"
3029
"github.com/vkcom/statshouse/internal/data_model/gen2/tlmetadata"
31-
"github.com/vkcom/statshouse/internal/data_model/gen2/tlstatshouseApi"
3230
"github.com/vkcom/statshouse/internal/format"
3331
"github.com/vkcom/statshouse/internal/pcache"
3432
"github.com/vkcom/statshouse/internal/util"
@@ -358,9 +356,9 @@ func run(argv args, cfg *api.Config, vkuthPublicKeys map[string][]byte) error {
358356
}
359357
defer func() { _ = f.Close() }()
360358

361-
m := api.Router{Handler: f, Router: mux.NewRouter()}
359+
m := api.NewHTTPRouter(f)
362360
a := m.PathPrefix(api.RoutePrefix).Subrouter()
363-
a.Path("/"+api.EndpointLegacyRedirect).Methods("GET", "HEAD", "POST").HandlerFunc(api.HandleLegacyRedirect)
361+
a.Router.Path("/"+api.EndpointLegacyRedirect).Methods("GET", "HEAD", "POST").HandlerFunc(f.HandleLegacyRedirect)
364362
a.Path("/" + api.EndpointMetricList).Methods("GET").HandlerFunc(api.HandleGetMetricsList)
365363
a.Path("/" + api.EndpointMetricTagValues).Methods("GET").HandlerFunc(api.HandleGetMetricTagValues)
366364
a.Path("/" + api.EndpointMetric).Methods("GET").HandlerFunc(api.HandleGetMetric)
@@ -466,13 +464,7 @@ func run(argv args, cfg *api.Config, vkuthPublicKeys map[string][]byte) error {
466464
c.Value(format.BuiltinMetricNameHeartbeatVersion, heartbeatTags, uptime)
467465
}))
468466

469-
hr := api.NewRpcHandler(f, brs, jwtHelper, argv.HandlerOptions)
470-
handlerRPC := &tlstatshouseApi.Handler{
471-
GetChunk: hr.GetChunk,
472-
RawGetQuery: hr.RawGetQuery,
473-
ReleaseChunks: hr.ReleaseChunks,
474-
RawGetQueryPoint: hr.RawGetQueryPoint,
475-
}
467+
handlerRPC := api.NewRPCRouter(f, brs)
476468
var hijackListener *rpc.HijackListener
477469
metrics := util.NewRPCServerMetrics("statshouse_api")
478470
srv := rpc.NewServer(

internal/api/access.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ import (
1717
)
1818

1919
type accessInfo struct {
20-
user string
21-
service bool
22-
insecureMode bool // full access to everything; can not be obtained from bits
23-
protectedPrefixes []string
24-
bitAdmin bool
25-
bitDeveloper bool
26-
bitViewDefault bool
27-
bitEditDefault bool
28-
bitViewPrefix map[string]bool
29-
bitEditPrefix map[string]bool
30-
bitViewMetric map[string]bool
31-
bitEditMetric map[string]bool
32-
skipBadgesValidation bool
20+
user string
21+
service bool
22+
insecureMode bool // full access to everything; can not be obtained from bits
23+
protectedPrefixes []string
24+
bitAdmin bool
25+
bitDeveloper bool
26+
bitViewDefault bool
27+
bitEditDefault bool
28+
bitViewPrefix map[string]bool
29+
bitEditPrefix map[string]bool
30+
bitViewMetric map[string]bool
31+
bitEditMetric map[string]bool
3332
}
3433

3534
func parseAccessToken(jwtHelper *vkuth.JWTHelper,
@@ -122,9 +121,6 @@ func (ai *accessInfo) protectedMetric(name string) bool {
122121
}
123122

124123
func (ai *accessInfo) CanViewMetricName(name string) bool {
125-
if name == format.BuiltinMetricNameBadges && ai.skipBadgesValidation {
126-
return true
127-
}
128124
if ai.insecureMode {
129125
return true
130126
}

internal/api/context.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

internal/api/endpoint_stat.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/vkcom/statshouse-go"
1818
"github.com/vkcom/statshouse/internal/format"
19+
"github.com/vkcom/statshouse/internal/util"
1920
"github.com/vkcom/statshouse/internal/vkgo/rpc"
2021
"github.com/vkcom/statshouse/internal/vkgo/srvfunc"
2122
)
@@ -63,16 +64,6 @@ type endpointStat struct {
6364
timings ServerTimingHeader
6465
}
6566

66-
func newEndpointStatRPC(endpoint, method string) *endpointStat {
67-
return &endpointStat{
68-
timestamp: time.Now(),
69-
endpoint: endpoint,
70-
protocol: format.TagValueIDRPC,
71-
method: method,
72-
dataFormat: "TL",
73-
}
74-
}
75-
7667
func (es *endpointStat) reportServiceTime(code int, err error) {
7768
if len(es.metric) != 0 {
7869
statshouse.Count(
@@ -124,6 +115,18 @@ func (es *endpointStat) report(code int, metric string) {
124115
statshouse.Value(metric, t, v)
125116
}
126117

118+
func (es *endpointStat) reportQueryKind(isFast, isLight, isHardware bool) {
119+
es.laneMutex.Lock()
120+
defer es.laneMutex.Unlock()
121+
if len(es.lane) == 0 {
122+
es.lane = strconv.Itoa(util.QueryKind(isFast, isLight, isHardware))
123+
}
124+
}
125+
126+
func (es *endpointStat) reportTiming(name string, dur time.Duration) {
127+
es.timings.Report(name, dur)
128+
}
129+
127130
func getStatTokenName(user string) string {
128131
if strings.Contains(user, "@") {
129132
return userTokenName

0 commit comments

Comments
 (0)