Skip to content

Commit

Permalink
Merge pull request #485 from getsentry/txiao/chore/remove-unused-endp…
Browse files Browse the repository at this point in the history
…oint-for-profiling-filters

chore(profiling): Remove unused endpoint for profiling filters
  • Loading branch information
Zylphrex authored Jul 16, 2024
2 parents 421bcd1 + 395c22e commit c833b84
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 216 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
61 changes: 0 additions & 61 deletions cmd/vroom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package main

import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
89 changes: 0 additions & 89 deletions cmd/vroom/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
58 changes: 0 additions & 58 deletions internal/snubautil/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"

"github.com/getsentry/sentry-go"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c833b84

Please sign in to comment.