DASSL / ClassDB

An open-source system to let students experiment with relational data
https://dassl.github.io/ClassDB/
Other
8 stars 2 forks source link

Update monitor functions #150

Closed wildtayne closed 6 years ago

wildtayne commented 6 years ago

This PR updates the DDL monitor and log import functions to support the new DDLActivity and ConnectionActivity tables. I have not tested this functionality yet, but I am creating the PR so others can begin to review it.

Basically, both functions now perform INSERT statements instead of UPDATE statements, which has greatly simplified their code.

smurthys commented 6 years ago

Thanks @srrollo for getting this change started. I will share my observations over the next few comments, probably organized by file.

The following observations are about addDDLMonitors.sql:

Also, I recommend adding functions enableDDLActivityLogging() and disableDDLActivityLogging() to respectively enable and disable the triggers. Instructors and DB managers should be able to execute these functions.

wildtayne commented 6 years ago

Thanks @smurthys for the review. The commits up to 43b20e1 address the issues raised. I added the enableDDLActivityLogging() and disableDDLActivityLogging() functions as well. One thing to note about them is that they remain owned by the creating user, and not ClassDB. This is because only superusers may CREATE/DROP event triggers, and ClassDB is not a superuser. However, we are asserting at the beginning of the script that the user running it is.

smurthys commented 6 years ago

Quick thoughts on the updated addDDLMonitors.sql:

wildtayne commented 6 years ago

7109499 addresses the points brought up in this thread. Currently, it is assuming that ClassDB.isTriggerDefined() will be available, but this can easily be changed to match whatever we end up implementing. I've also added the files disableServerLogging.sql and addConnectionLogging.psql based on today's discussion.

smurthys commented 6 years ago

On function isTriggerDefined, please see my recent comment on another PR.

wildtayne commented 6 years ago

The latest commits add a unit test for the DDL event triggers, and a significant improvement to importLog().

smurthys commented 6 years ago

@srrollo 0955c84 actually "Added terrible unit test" ? 😕

wildtayne commented 6 years ago

Yeah, I was pretty frustrated with the unit test last night 😩. The latest update is much better. The two unit tests are now somewhat comprehensive:

I am having one more issue with testAddLogMgmt.psql - I can't get my non-ClassDB user to login to the database (I get password authentication failed). The code to create the user is this:

CREATE USER conNonClassDB ENCRYPTED PASSWORD ' ';
EXECUTE FORMAT('GRANT CONNECT ON DATABASE %I TO conNonClassDB', CURRENT_DATABASE());
wildtayne commented 6 years ago

The latest commits also remove isTriggerDefined(), as per our discussion. I've removed the creation of the non-ClassDB user in the test for now, as it is not strictly necessary, and can be addressed later (after M2 if necessary).

smurthys commented 6 years ago

Quickly: Functions enableDDLActivityLogging and disableDDLActivityLogging are missing owner assignment.

FYI: I have a meeting and other work related to a different project starting now to EOD.

wildtayne commented 6 years ago

enableDDLActivityLogging and disableDDLActivityLogging must be owned by a superuser, in this case the user executing addDDLMonitors.sql, since all event trigger DDL operations can only be performed by superusers.

I've added some extra comments to better document this requirement.

smurthys commented 6 years ago

Thanks @srrollo for the reminder about event triggers needing super user.

smurthys commented 6 years ago

FYI, I'm reviewing the files right now. EDIT: I'll share my observations over multiple comments.

smurthys commented 6 years ago

Here are some observations:

addConnectionLogging.psql:

enableServerLogging.sql

EDIT: Same observations in disableServerLogging.sql as for enableServerLogging.sql. Plus:

smurthys commented 6 years ago

addLogMgmt.sql is really streamlined. Excellent work @srrollo.

Some observations:

smurthys commented 6 years ago

For now I am unable to review the test scripts due to other urgent work. I think @afig's review on that suffices.

wildtayne commented 6 years ago

Thanks @smurthys for the thorough review. I've made the following changes: addConnectionLogging.psql:

enableServerLogging.sql/disableServerLogging.sql

addDDLMonitors.sql

addLogMgmt.sql

All files:

wildtayne commented 6 years ago

I've added changeTimeZone() to addHelpers.sql in this PR. Originally, it was going to be added in #152, however it is now required by importLog(), and it looks like this PR will be merged before #152.

smurthys commented 6 years ago

All good changes @srrollo:

In addDDLMonitors.sql:

In addLogMgmt.sql:

In *ServerLogging.psql, file name is incorrect on L1 in both files.

On file names:

smurthys commented 6 years ago

Also, perhaps the function importLog should be renamed to importConnectionActivity.

wildtayne commented 6 years ago

Should addLogMgmt.sql maybe be named addConnectionActivityMgmt.sql instead? I feel like addConnectionActivityLogging.sql doesn't convey the intent of the script, since it only adds the management functions, and doesn't directly influence the logging system.

I'm also not sure about taking the minimum of startDate and lastConDateLocal. startDate is intended to override the date check if users want to skip days. I think the documentation also states that except for the first run, you should generally just use importConnectionLog().

wildtayne commented 6 years ago

I just pushed the commits addressing the recent comments.

smurthys commented 6 years ago

All changes look good @srrollo. I have only one observation on addHelpers.sql: It is not necessary to revoke permission from anyone to execute function changeTimeZone. Just granting ownership to ClassDB suffices.

wildtayne commented 6 years ago

Thanks @afig and @smurthys for the reviews. I've removed the unnecessary REVOKE and fixed the errors in the comments.