Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(geo): Store subdivisions #2058

Merged
merged 11 commits into from
Apr 24, 2023
Merged

feat(geo): Store subdivisions #2058

merged 11 commits into from
Apr 24, 2023

Conversation

udameli
Copy link
Contributor

@udameli udameli commented Apr 21, 2023

Store city.subdivisions (ref) per customer request.

Fixes #2057

@udameli udameli requested a review from a team April 21, 2023 18:43
Copy link
Member

@mitsuhiko mitsuhiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to be added to the struct definitions and tests.

@udameli
Copy link
Contributor Author

udameli commented Apr 21, 2023

This also needs to be added to the struct definitions and tests.

Added 👍

city.subdivisions
.as_ref()
.and_then(|subdivisions| Some(subdivisions.names.as_ref()?.get("en")?.to_string())),
),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is failing because subdivisions is a list like this one:

"subdivisions": [
    {
      "geoname_id": 5332921,
      "iso_code": "CA",
      "names": {
        "de": "Kalifornien",
        "en": "California",
        "es": "California",
        "fr": "Californie",
        "ja": "カリフォルニア",
        "ru": "Калифорния",
        "zh-CN": "加州"
      }
    }
  ]

but I'm not too sure how to grab first element in Rust

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

city.subdivisions.as_ref().and_then(|subdivisions| {
            subdivisions.get(0).and_then(|subdivision| {
                subdivision.names.as_ref().and_then(|subdivision_names| {
                    subdivision_names
                        .get("en")
                        .cloned()
                        .map(|subdivision_name| subdivision_name.to_string())
                })
            })
        });

i think?
i do wonder how often the multi subdivision case comes up and if its worth storing an array of them instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably fine just to take the first (top level as i understand it) subdivision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on this example it looks like it's always a list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was gonna grab the first element but rust wasn't happy about how I did it. I'll try your suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also changed it subdivisions -> subdivision

@udameli udameli requested a review from mitsuhiko April 22, 2023 00:47
Copy link
Contributor

@olksdr olksdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Some tests are failing, seems like because of the fixtures are not updated yet.
To fix the snapshots for tests, please, see https://github.com/getsentry/relay/blob/master/README.md#snapshot-tests

You will have to install insta as per instruction , run the tests locally add updated snapshots to this PR.

Once it's done we can merge it.

relay-general/src/store/geo.rs Outdated Show resolved Hide resolved
jjbayer and others added 3 commits April 24, 2023 09:37
Co-authored-by: Oleksandr <1931331+olksdr@users.noreply.github.com>
Copy link
Contributor

@olksdr olksdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@mitsuhiko mitsuhiko merged commit 3fc247b into master Apr 24, 2023
@mitsuhiko mitsuhiko deleted the du/feat/store-subdivisions branch April 24, 2023 10:09
@AbhiPrasad
Copy link
Member

Can we also make sure we update https://develop.sentry.dev/sdk/event-payloads/user/?

udameli added a commit to getsentry/sentry that referenced this pull request Apr 25, 2023
Now that we store `geo.subdivision`
getsentry/relay#2058 make this field queryable

Relies on getsentry/snuba#4080

Fixes https://github.com/getsentry/getsentry/issues/10313
udameli added a commit to getsentry/sentry that referenced this pull request Apr 27, 2023
expose subdivision field in the search.

should be merged after:

- [x] getsentry/relay#2058
- [x] getsentry/snuba#4080
- [x] #47995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add geo.country_subdivision field
6 participants