From 11df98a3926c4cf59c80633b7b9a483eb85f6f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Mon, 24 Oct 2022 11:43:47 +0200 Subject: [PATCH] satellite: use evenkit instead of evenstat/top endpoint We had multiple experiment so far to collect high cardinality data (mainly in aggregated form). 1. we have a `/top` endpoint which aggregates events with upper bound 2. we use same api (eventstat) to publish S3 gateway-mt agents to influxdb This patch starts to replace theses api with jtolio/eventkit. Instead of aggregation all events can be sent to a collector host where we can do aggregation and/or persisting data. Change-Id: Id6df4882b51d2dbd2be9401ee4199d14f3ff7186 --- satellite/metainfo/endpoint.go | 16 ---------------- satellite/metainfo/validation.go | 13 ++++++++++--- satellite/metainfo/validation_test.go | 5 ----- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/satellite/metainfo/endpoint.go b/satellite/metainfo/endpoint.go index 85479f63f..a96696ff9 100644 --- a/satellite/metainfo/endpoint.go +++ b/satellite/metainfo/endpoint.go @@ -12,14 +12,12 @@ import ( "go.uber.org/zap" "storj.io/common/encryption" - "storj.io/common/eventstat" "storj.io/common/lrucache" "storj.io/common/macaroon" "storj.io/common/pb" "storj.io/common/rpc/rpcstatus" "storj.io/common/signing" "storj.io/common/storj" - "storj.io/private/debug" "storj.io/storj/satellite/accounting" "storj.io/storj/satellite/attribution" "storj.io/storj/satellite/buckets" @@ -80,15 +78,6 @@ type Endpoint struct { defaultRS *pb.RedundancyScheme config Config versionCollector *versionCollector - top endpointTop -} - -// endpointTop represents in-memory counter stats. -// Cached info can be retrieved from the /mon monitoring endpoint. -type endpointTop struct { - Project eventstat.Sink - Partner eventstat.Sink - UserAgent eventstat.Sink } // NewEndpoint creates new metainfo endpoint instance. @@ -139,11 +128,6 @@ func NewEndpoint(log *zap.Logger, buckets *buckets.Service, metabaseDB *metabase defaultRS: defaultRSScheme, config: config, versionCollector: newVersionCollector(log), - top: endpointTop{ - Project: debug.Top.NewTagCounter("auth_request_project", "project"), - Partner: debug.Top.NewTagCounter("auth_request_partner", "partner"), - UserAgent: debug.Top.NewTagCounter("auth_request_user_agent", "agent"), - }, }, nil } diff --git a/satellite/metainfo/validation.go b/satellite/metainfo/validation.go index a05bab9b6..bfc773c11 100644 --- a/satellite/metainfo/validation.go +++ b/satellite/metainfo/validation.go @@ -11,6 +11,7 @@ import ( "strconv" "time" + "github.com/jtolio/eventkit" "github.com/zeebo/errs" "go.uber.org/zap" "golang.org/x/time/rate" @@ -35,6 +36,8 @@ var ( ipRegexp = regexp.MustCompile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`) ) +var ek = eventkit.Package() + func getAPIKey(ctx context.Context, header *pb.RequestHeader) (key *macaroon.APIKey, err error) { defer mon.Task()(&ctx)(&err) if header != nil { @@ -128,11 +131,15 @@ func (endpoint *Endpoint) validateBasic(ctx context.Context, header *pb.RequestH return nil, nil, rpcstatus.Error(rpcstatus.PermissionDenied, "Unauthorized API credentials") } - endpoint.top.Project(keyInfo.ProjectID.String()) - endpoint.top.Partner(keyInfo.PartnerID.String()) + userAgent := "" if keyInfo.UserAgent != nil { - endpoint.top.UserAgent(string(keyInfo.UserAgent)) + userAgent = string(keyInfo.UserAgent) } + ek.Event("auth", + eventkit.String("user-agent", userAgent), + eventkit.String("project", keyInfo.ProjectID.String()), + eventkit.String("partner", keyInfo.PartnerID.String()), + ) if err = endpoint.checkRate(ctx, keyInfo.ProjectID); err != nil { endpoint.log.Debug("rate check failed", zap.Error(err)) diff --git a/satellite/metainfo/validation_test.go b/satellite/metainfo/validation_test.go index ac006f797..bed8cf1d6 100644 --- a/satellite/metainfo/validation_test.go +++ b/satellite/metainfo/validation_test.go @@ -48,11 +48,6 @@ func TestEndpoint_validateAuthN(t *testing.T) { endpoint := Endpoint{ log: zaptest.NewLogger(t), apiKeys: &mockAPIKeys{secret: secret}, - top: endpointTop{ - Project: func(name string) {}, - Partner: func(name string) {}, - UserAgent: func(name string) {}, - }, } now := time.Now()