[Super Search] super search fields need refactoring
Categories
(Socorro :: General, task)
Tracking
(Not tracked)
People
(Reporter: willkg, Assigned: bdanforth)
References
Details
Attachments
(1 file)
| Reporter | ||
Comment 1•8 years ago
|
||
Comment 2•6 years ago
|
||
I like it, this pattern has worked well for me for similar problems.
Another option is moving the definitions to an external file (JSON, YAML, CSV) and loading them at configuration time. It doesn't help with the duplicate data, but gets them out of code, and may make it easier for a non-staff dev to process the structure. I prefer the functions-returning-dicts, however.
| Reporter | ||
Comment 3•6 years ago
|
||
We originally had a JSON file, but I ditched that for the Python file because JSON sucks for stuff like this where you need to document why things are different. Those were dark days.
Another option is to use attrs data classes which get us a lot of what we're doing above with a lot less code. This will require us to adjust super_search_fields using code, but I think that's probably a good thing all things considered.
I'll spend a couple of hours fiddling with these options to see what's easier to deal with and report back.
I want to do this before embarking on the Elasticsearch migration because simplifying super search fields will make that significantly easier.
| Reporter | ||
Comment 4•6 years ago
|
||
Here's an example using attrs:
@attr.s
class Keyword:
"""Defines a keyword field."""
name = attr.ib()
namespace = attr.ib()
in_database_name = attr.ib(
default=attr.Factory(
lambda self: self.name,
takes_self=True
)
)
default_value = attr.ib(default=None)
data_validation_type = attr.ib(default='str')
description = attr.ib(default='Add description')
has_full_version = attr.ib(default=False)
is_exposed = attr.ib(default=True)
is_mandatory = attr.ib(default=False)
is_returned = attr.ib(default=True)
query_type = attr.ib(default='string')
form_field_choices = attr.ib(default=attr.Factory(list))
permissions_needed = attr.ib(default=attr.Factory(lambda: ['crashstats.view_pii']))
storage_mapping = attr.ib(
default=attr.Factory(
lambda: {'analyzer': 'keyword', 'type': 'string'}
)
)
FIELDS = [
Keyword(
name='ActiveExperiment',
namespace='raw_crash',
description='The telemetry experiment active at the time of the crash, if any.',
)
]
That's pretty succinct. Using attrs allows us to type-check and validate values, too, though I didn't test that out much here. I think I want to go with this.
| Reporter | ||
Comment 5•6 years ago
|
||
A while back, I documented the fields in super_search_fields.py and noticed that is_mandatory and default_value have the same value for all the fields. Adrian and I talked about that briefly:
https://github.com/mozilla-services/socorro/pull/4417#discussion_r184945744
We can remove those.
I'll do this before I go further since it reduces the code.
| Reporter | ||
Comment 6•6 years ago
|
||
| Reporter | ||
Comment 7•6 years ago
|
||
willkg merged PR #4947: "bug 1407212: remove unused super_search_fields code" in 10af200.
That'll make it easier to diff old fields with new fields to make sure they're the same.
| Reporter | ||
Comment 8•6 years ago
|
||
Unassigning myself since I'm not going to get to this any time soon.
Comment 9•1 year ago
|
||
closing in favor of bug 1921849
Comment 10•1 year ago
|
||
sorry, i misunderstood what this bug was about, it's not covered in bug 1921849, reopening
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 11•1 year ago
•
|
||
I was going to do this ticket next, but relud suggested I do this after the migration as a fast-follow:
fixing this bug will conflict with my es8 implementation [Bug 1921849], and if i understand correctly should be something we can clean up after doing the es8 migration
I'll leave it under this meta ticket for now, Bug 1911141, so that we don't lose track of it.
| Assignee | ||
Comment 12•1 year ago
|
||
I'll leave it under this meta ticket for now, Bug 1911141, so that we don't lose track of it.
Actually the dependency graph is confusing if I leave it in this meta ticket. It's tracked in https://mozilla-hub.atlassian.net/browse/OBS-418, so setting it as blocked by the upgrade work, since it's a fast follow.
Description
•