-
Notifications
You must be signed in to change notification settings - Fork 296
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
Jinja2 based routes #1319
Jinja2 based routes #1319
Conversation
grafana-plugin/src/models/channel_filter/channel_filter.types.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, probably a good idea to add a couple tests on this, e.g. somewhere here:
def test_channel_filter_select_filter(make_organization, make_alert_receive_channel, make_channel_filter): |
migrations.AddField( | ||
model_name='channelfilter', | ||
name='filtering_term_type', | ||
field=models.IntegerField(choices=[(0, 'regex'), (1, 'jinja2')], default=None, null=True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have this field non-nullable, but with default value 0? With that we can get rid of to_representation
hack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided not use this kind of migrations to make the release smoother for us and the oss customers (check here for more details)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's valid tradeoff to experience 500's to have more consistent database and codebase. With nullable we need a lot of code to show this field in private/public API correctly and to check for null to write to that field from API.
@@ -56,22 +57,6 @@ def get_slack_channel(self, obj): | |||
"id": obj.slack_channel_pk, | |||
} | |||
|
|||
def validate(self, attrs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where jinja template is validated, when route is created/modified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was used to ensure that the routes are based on the unique regular expressions. I decided to drop uniqueness, if user wants to create exactly same route which will never get it's alert, let them do that, may be they'll want to modify it later.
@@ -176,20 +176,6 @@ def create(self, validated_data): | |||
|
|||
return instance | |||
|
|||
def validate(self, attrs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as in internal API - where jinja template is validated?
return False | ||
if self.filtering_term is not None and self.filtering_term_type == ChannelFilter.FILTERING_TERM_TYPE_REGEX: | ||
try: | ||
return re.search(self.filtering_term, json.dumps(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json.dumps(value) is introduced here, could you please describe why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, left comments. It will be great to support new filter term type in public api and in the terraform provider. Also, i think it is needed to provide some info in docs about jinja based routes. |
), | ||
# Adding same default value on the database level | ||
# for database backwards-compatibility with older versions of code | ||
AddDefaultValue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is possible with RunSQL to insert default values, but we'll need to do that manually for each database. django_add_default_value does that for us
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get that idea. Why we need AddDefaultValue, when we have default=0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the better comment in the code
for more details I recommend to read this article
# What this PR does This PR adds the new way to set up routes using jinja2 templating language <img width="1174" alt="Screenshot 2023-03-06 at 22 11 13" src="https://user-images.githubusercontent.com/2262529/223134053-69d43c47-bb2a-4790-a16d-767425017a76.png"> <img width="1175" alt="Screenshot 2023-03-06 at 22 11 34" src="https://user-images.githubusercontent.com/2262529/223134070-1e5ef82f-021c-4d5d-b255-b19bb3445641.png"> ## Which issue(s) this PR fixes ## Checklist - [ ] Tests updated - [ ] Documentation added - [ ] `CHANGELOG.md` updated
What this PR does
This PR adds the new way to set up routes using jinja2 templating language
Which issue(s) this PR fixes
Checklist
CHANGELOG.md
updated