-
Notifications
You must be signed in to change notification settings - Fork 34
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
Fix constance being accessed before database is ready and other fixes #341
Conversation
I'm curious about:
These are the endpoints for receiving messages from the chat platform, aren't they? I wouldn't expect them to require Nautobot user authentication. |
return TemplateResponse( | ||
request=self.request, | ||
template="nautobot_chatops_grafana/grafana_disabled.html", | ||
context={}, |
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 should probably be a redirect to another view but this works.
@@ -22,6 +28,9 @@ def run_dashboard_sync(overwrite: bool = False) -> Union[str, None]: | |||
Args: | |||
overwrite (bool): Overwrite Nautobot data and delete records that are no longer in Grafana. | |||
""" | |||
if not DIFFSYNC_INSTALLED: | |||
raise ImportError("DiffSync is not installed. Please install DiffSync to use the grafana integration.") |
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.
ImportError for these calls feels weird to me - shouldn't it be something like RuntimeError?
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 was going to use RuntimeError but then I decided to replicate the exception you would get if you tried to import diffsync in this function. It seemed more appropriate to use ImportError here but I'm happy to change it to RuntimeError if you think that's better here.
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.
Would be my preference, but I don't feel strongly about it.
Might be good either way to add a Raises:
section to the docstring documenting this behavior?
Yeah, these need to be reverted. The API for these views is for the chat platform to communicate with Nautobot. Each of these views have their own way to authenticate the system. For instance, Slack signs their requests. |
That's simple enough to do. I didn't have the context for why these were left wide open. These should probably also be changed to rest_framework views at some point instead of django views? |
except Exception: | ||
grafana_urlpatterns = [] | ||
logger = logging.getLogger(__name__) | ||
logger.warning("Grafana ChatOps integration is not available.", exc_info=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.
Wondering - were there cases where importing the grafana URLs might fail here (missing optional dependency, etc.) that we need to handle still?
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.
Probably. Our dockerfile installs with --extras all
. I'll test without that.
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.
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 fixed now. Discussed the implementation in DSU and decided not to spend too much time on it since ideally nobody will ever encounter this.
They don't use DRF serializers AFAIK so I'm not sure why they would be changed over? |
Just so they don't have to manually disable csrf checks. This is the first place I've seen |
from .integrations.grafana.models import Dashboard as GrafanaDashboard | ||
from .integrations.grafana.models import Panel as GrafanaPanel | ||
from .integrations.grafana.models import PanelVariable as GrafanaPanelVariable | ||
from .integrations.grafana.models import GrafanaDashboard, GrafanaPanel, GrafanaPanelVariable |
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.
Oh good, I am glad that we can get rid of the rename. I am not sure why this wasn't done when originally implemented.
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 had to leave it in for the diffsync code because the diffsync models are called GrafanaDashboard
and GrafanaPanel
and I didn't want to go down another rabbit hole trying to fix those...
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.
Thank you for the fixes!
Closes #340
What's Changed
Screenshots