diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b0060ff..c787c023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ - Remove unused functions endpoint (dead code) ([#474](https://github.com/getsentry/vroom/pull/474)) - Serialize chunk fields with lower case ([#483](https://github.com/getsentry/vroom/pull/483)) - Filter out samples before start and after end ([#484](https://github.com/getsentry/vroom/pull/484)) +- Remove unused endpoint for profiling filters ([#485](https://github.com/getsentry/vroom/pull/485)) ## 23.12.0 diff --git a/cmd/vroom/main.go b/cmd/vroom/main.go index 5f0fdd13..26a8eb8b 100644 --- a/cmd/vroom/main.go +++ b/cmd/vroom/main.go @@ -2,14 +2,12 @@ package main import ( "context" - "encoding/json" "fmt" "log" "log/slog" "net/http" "os" "os/signal" - "strconv" "syscall" "time" @@ -145,7 +143,6 @@ func (e *environment) newRouter() (*httprouter.Router, error) { path string handler http.HandlerFunc }{ - {http.MethodGet, "/organizations/:organization_id/filters", e.getFilters}, { http.MethodGet, "/organizations/:organization_id/projects/:project_id/profiles/:profile_id", @@ -285,61 +282,3 @@ func (e *environment) getHealth(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusBadGateway) } } - -type Filter struct { - Key string `json:"key"` - Name string `json:"name"` - Values []interface{} `json:"values"` -} - -func (e *environment) getFilters(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - hub := sentry.GetHubFromContext(ctx) - ps := httprouter.ParamsFromContext(ctx) - rawOrganizationID := ps.ByName("organization_id") - organizationID, err := strconv.ParseUint(rawOrganizationID, 10, 64) - if err != nil { - hub.CaptureException(err) - w.WriteHeader(http.StatusBadRequest) - return - } - - hub.Scope().SetTag("organization_id", rawOrganizationID) - - sqb, err := e.profilesQueryBuilderFromRequest(ctx, r.URL.Query(), organizationID) - if err != nil { - hub.CaptureException(err) - w.WriteHeader(http.StatusBadRequest) - return - } - - sqb.WhereConditions = append( - sqb.WhereConditions, - fmt.Sprintf("organization_id = %d", organizationID), - ) - - filters, err := snubautil.GetFilters(sqb) - if err != nil { - hub.CaptureException(err) - w.WriteHeader(http.StatusInternalServerError) - return - } - - s := sentry.StartSpan(ctx, "json.marshal") - defer s.Finish() - - response := make([]Filter, 0, len(filters)) - for k, v := range filters { - response = append(response, Filter{Key: k, Name: k, Values: v}) - } - - b, err := json.Marshal(response) - if err != nil { - hub.CaptureException(err) - w.WriteHeader(http.StatusInternalServerError) - return - } - - w.Header().Set("Content-Type", "application/json") - _, _ = w.Write(b) -} diff --git a/cmd/vroom/utils.go b/cmd/vroom/utils.go index 85a9130a..cafb9cfb 100644 --- a/cmd/vroom/utils.go +++ b/cmd/vroom/utils.go @@ -4,106 +4,17 @@ import ( "context" "math" "net/http" - "net/url" "strconv" "strings" "time" "github.com/google/uuid" - "github.com/rs/zerolog/log" "github.com/getsentry/sentry-go" "github.com/getsentry/vroom/internal/nodetree" "github.com/getsentry/vroom/internal/profile" - "github.com/getsentry/vroom/internal/snubautil" ) -var ( - profileFilterFields = map[string]string{ - "device_classification": "device_classification", - "device_locale": "device_locale", - "device_manufacturer": "device_manufacturer", - "device_model": "device_model", - "device_os_build_number": "device_os_build_number", - "device_os_name": "device_os_name", - "device_os_version": "device_os_version", - "environment": "environment", - "platform": "platform", - "transaction_id": "transaction_id", - "transaction_name": "transaction_name", - } - - profileQueryFilterMakers = []func(url.Values) ([]string, error){ - snubautil.MakeProjectsFilter, - func(params url.Values) ([]string, error) { - return snubautil.MakeTimeRangeFilter("received", params) - }, - func(params url.Values) ([]string, error) { - return snubautil.MakeFieldsFilter(profileFilterFields, params) - }, - snubautil.MakeAndroidAPILevelFilter, - snubautil.MakeVersionNameAndCodeFilter, - } -) - -func setExtrasFromRequest(sqb *snubautil.QueryBuilder, p url.Values) error { - if v := p.Get("limit"); v != "" { - limit, err := strconv.ParseUint(v, 10, 64) - if err != nil { - log.Err(err).Str("limit", v).Msg("can't parse limit value") - return err - } - sqb.Limit = limit - } - - if v := p.Get("offset"); v != "" { - offset, err := strconv.ParseUint(v, 10, 64) - if err != nil { - log.Err(err).Str("offset", v).Msg("can't parse offset value") - return err - } - sqb.Offset = offset - } - - if v := p.Get("granularity"); v != "" { - granularity, err := strconv.ParseUint(v, 10, 64) - if err != nil { - log.Err(err).Str("offset", v).Msg("can't parse granularity value") - return err - } - sqb.Granularity = granularity - } - - return nil -} - -func (e *environment) profilesQueryBuilderFromRequest( - ctx context.Context, - p url.Values, - orgID uint64, -) (snubautil.QueryBuilder, error) { - sqb, err := e.snuba.NewQuery(ctx, "profiles", orgID) - if err != nil { - return snubautil.QueryBuilder{}, err - } - sqb.WhereConditions = make([]string, 0, 5) - - for _, makeFilter := range profileQueryFilterMakers { - conditions, err := makeFilter(p) - if err != nil { - return snubautil.QueryBuilder{}, err - } - sqb.WhereConditions = append(sqb.WhereConditions, conditions...) - } - - err = setExtrasFromRequest(&sqb, p) - if err != nil { - return snubautil.QueryBuilder{}, err - } - - return sqb, nil -} - func getFlamegraphNumWorkers(numProfiles, minNumWorkers int) int { if numProfiles < minNumWorkers { return numProfiles diff --git a/go.mod b/go.mod index 3c503e05..c63d7e4c 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 github.com/pierrec/lz4 v2.6.1+incompatible github.com/pierrec/lz4/v4 v4.1.15 - github.com/rs/zerolog v1.26.1 github.com/segmentio/kafka-go v0.4.38 gocloud.dev v0.29.0 google.golang.org/api v0.114.0 diff --git a/go.sum b/go.sum index c2187ecd..312512ae 100644 --- a/go.sum +++ b/go.sum @@ -1708,11 +1708,8 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= -github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc= -github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -1857,7 +1854,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= @@ -2005,7 +2001,6 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211202192323-5770296d904e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= @@ -2123,7 +2118,6 @@ golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -2482,7 +2476,6 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/snubautil/query.go b/internal/snubautil/query.go index f16198f4..a5be4dcb 100644 --- a/internal/snubautil/query.go +++ b/internal/snubautil/query.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "strings" "time" "github.com/getsentry/sentry-go" @@ -73,63 +72,6 @@ func GetProfiles(sqb QueryBuilder) ([]profile.Profile, error) { return sr.Profiles, err } -type SnubaFiltersResponse struct { - Filters []map[string][]interface{} `json:"data"` -} - -func GetFilters(sqb QueryBuilder) (map[string][]interface{}, error) { - t := sentry.TransactionFromContext(sqb.ctx) - rs := t.StartChild("snuba") - defer rs.Finish() - - sqb.SelectCols = []string{ - "arraySort(groupUniqArray(android_api_level)) AS _android_api_level", - "arraySort(groupUniqArray(device_model)) AS _device_model", - "arraySort(groupUniqArray(device_classification)) AS _device_classification", - "arraySort(groupUniqArray(device_locale)) AS _device_locale", - "arraySort(groupUniqArray(device_manufacturer)) AS _device_manufacturer", - "arraySort(groupUniqArray(device_os_build_number)) AS _device_os_build_number", - "arraySort(groupUniqArray(device_os_name)) AS _device_os_name", - "arraySort(groupUniqArray(device_os_version)) AS _device_os_version", - "arraySort(groupUniqArray(platform)) AS _platform", - "arraySort(groupUniqArray(transaction_name)) AS _transaction_name", - "arraySort(groupUniqArray(tuple(version_name, version_code))) AS _version", - } - - rb, err := sqb.Do(rs) - if err != nil { - return nil, err - } - defer rb.Close() - - s := rs.StartChild("json.unmarshal") - s.Description = "Decode response from Snuba" - defer s.Finish() - - var sr SnubaFiltersResponse - err = json.NewDecoder(rb).Decode(&sr) - if err != nil { - return nil, err - } - filters := make(map[string][]interface{}) - for k, values := range sr.Filters[0] { - k = strings.TrimPrefix(k, "_") - switch k { - case "version": - filters[k] = make([]interface{}, 0, len(values)) - for _, v := range values { - if versions, ok := v.([]interface{}); ok { - filters[k] = append(filters[k], profile.FormatVersion(versions[0], versions[1])) - } - } - default: - filters[k] = values - } - } - - return filters, err -} - func GetProfileIDByTransactionID(organizationID, projectID uint64, transactionID string, sqb QueryBuilder) (string, error) { t := sentry.TransactionFromContext(sqb.ctx) rs := t.StartChild("snuba")