[Bug 42217] New: ERM Usage – Harvesting Twice Does Not Overwrite Data
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Bug ID: 42217 Summary: ERM Usage – Harvesting Twice Does Not Overwrite Data Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: major Priority: P5 - low Component: ERM Assignee: jonathan.druart@gmail.com Reporter: michaela.sieber@kit.edu QA Contact: testopia@bugs.koha-community.org CC: jonathan.druart@gmail.com, jonathan.field@openfifth.co.uk, martin.renvoize@openfifth.co.uk, matt.blenkinsop@openfifth.co.uk, pedro.amorim@openfifth.co.uk If reports are harvested more than once, the usage_count should be overwritten when the data has changed. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=39344 --- Comment #1 from Michaela Sieber <michaela.sieber@kit.edu> --- Please see also Bug 39344 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrew.auld@openfifth.co.uk | |, clemens.tubach@kit.edu, | |katrin.fischer@bsz-bw.de -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #2 from Michaela Sieber <michaela.sieber@kit.edu> --- Created attachment 202590 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202590&action=edit Example-Cambridge-Data-Reharvest-Notification -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #3 from Michaela Sieber <michaela.sieber@kit.edu> --- If a month was harvested twice than the usage values should be overwritten and not added • Otherwise, multiple rows per month can lead to incorrect calculation of usage data, because usage_count is summed when values differ • Example: First harvesting of the month → result = 5; another run → result = 15 → total becomes 20, although the usage_count should be overwritten with 15 → Providers are allowed to correct usage data. This can be reproduced by modifying/manipulating the usage_count in the database and running the harvesting again. The comparison should not include usage_count -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jvinke@austinseminary.edu -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- Comma delimited| |Karlsruhe Institute of list of Sponsors| |Technology (KIT) Keywords| |rel_26_11_candidate Assignee|jonathan.druart@gmail.com |matt.blenkinsop@openfifth.c | |o.uk Sponsorship status|--- |Sponsored Version(s)| |If a month is harvested released in| |twice then the usage values | |will now be overwritten and | |not added. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |43904 Target Milestone|--- |26.11 Status|NEW |ASSIGNED Priority|P5 - low |P1 - high --- Comment #4 from Michaela Sieber <michaela.sieber@kit.edu> --- Link to Omnibus Bug to track all ERM Usage Improvements Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43904 [Bug 43904] [OMNIBUS] ERM Usage Improvements -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |42218 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42218 [Bug 42218] ERM Usage – remove Database table erm_usage_yus ? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |41294 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41294 [Bug 41294] Allow monthly harvesting only so Data not available for certain months do not result in a complete failure of the harvest -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |Laura.escamilla@bywatersolu |y.org |tions.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Christian Nelson <christian.nelson@uwasa.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |christian.nelson@uwasa.fi -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|Laura.escamilla@bywatersolu |nick@bywatersolutions.com |tions.com | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #209212|0 |1 is obsolete| | Attachment #209213|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #9 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- Created attachment 210084 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210084&action=edit Bug 42217: Prevent re-harvested data from duplicating usage A second harvest of a month that was already stored added a new erm_usage_mus row next to the old one as soon as the count differed, so the monthly usage was duplicated and the yearly totals doubled. A month that the provider later corrected to zero was never touched, because CounterFile skipped every zero cell before it reached the database. UsageObject->monthly_usages now identifies a row by every column except usage_count (usage object, provider, year, month, metric type, report type and, where the report has them, access type and yop) and for each monthly usage passed in: - adds a row when none exists - skips the row when the count is unchanged - updates the row in place when the count changed - deletes the rows when the count is zero; zero months are not stored Duplicates left by earlier harvests are removed and the oldest row is kept. The rows of the usage object are read once per call and every change of one call runs in one transaction. CounterFile passes all the months of a report row in one call, including the zero months. The job report gains an updated_mus counter next to added_mus and skipped_mus. Sponsored-by: Karlsruhe Institute of Technology (KIT) Assisted-by: Sonnet 5 (Anthropic) Signed-off-by: Clemens Tubach <clemens.tubach@kit.edu> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #10 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- Created attachment 210085 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210085&action=edit Bug 42217: Update unit tests UsageObject.t covers monthly_usages: add, skip, update in place, a new identity, duplicates removed with the oldest row kept, zero months not stored and removed when they exist, several months in one call, and the rollback of the whole call when one store fails. The harvester tests check a third harvest over stale, duplicated and zero-month data, through both the SUSHI and the file upload paths. The CounterFile tests check that storing the same file twice adds no rows. Test plan: prove -l t/db_dependent/Koha/ERM/EUsage/UsageObject.t \ t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t \ t/db_dependent/Koha/ERM/EUsage/COUNTER_5/CounterFile.t \ t/db_dependent/Koha/ERM/EUsage/COUNTER_5.1/CounterFile.t yarn cypress run --spec t/cypress/integration/ERM/ModuleDashboard_spec.ts Assisted-by: Sonnet 5 (Anthropic) Signed-off-by: Clemens Tubach <clemens.tubach@kit.edu> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #11 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- This seems a pretty major issue, the code makes sense, tests cover cases, passing QA It would, however, be really nice to have a test plan and a manual file for testing for any future bugs like this. The tests, also, could be more readable and explanatory - they mock a user agent response with a preloaded file - there is a method to pass the file content into the background job, and that would be more readable -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #12 from Michaela Sieber <michaela.sieber@kit.edu> --- Created attachment 210090 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210090&action=edit TR_sample_r51_official-COUNTER-file This is a sample file for COUNTER 5.1 Title Master Report (TR) downloaded from the official COUNTER documentation website : https://cop5.countermetrics.org/en/5.1.1/appendices/g-sample-counter-reports... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #210090|0 |1 is obsolete| | --- Comment #13 from Michaela Sieber <michaela.sieber@kit.edu> --- Comment on attachment 210090 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210090 TR_sample_r51_official-COUNTER-file Because of Bug 43944 the official COUNTER sample file can not be used. I will attach a new file which can be parsed without a solution of bug 43944 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #14 from Michaela Sieber <michaela.sieber@kit.edu> --- Created attachment 210106 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210106&action=edit TR_sample_r51 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #210106|0 |1 is obsolete| | --- Comment #15 from Michaela Sieber <michaela.sieber@kit.edu> --- Created attachment 210115 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210115&action=edit TR_sample_file_with-only-one-access_type Please use TR_sample_file_with-only-one-access_type , otherwise the test plan gets too complicated (due to Bug 43967) Test Plan: 1.) enable ERM Module 2.) create a provider manually (no need for credentials) with report type TR 3.) Manual Upload of the attache file 'TR_sample_file_with-only-one-access_type' 4.) koha-mysql kohadev 5.) MariaDB [koha_kohadev]> select * from erm_usage_mus where title_id = 1 and month=1 and metric_type = 'Unique_Item_Requests'; +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | monthly_usage_summary_id | title_id | platform_id | database_id | item_id | usage_data_provider_id | year | month | usage_count | metric_type | access_type | yop | report_type | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | 62| 1 | NULL | NULL | NULL | 1 | 2022 | 1 | 497| Unique_Item_Requests | NULL | NULL | TR | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ -- > Result : 1 rows (access_type is missing, but this is a different Bug 43967) 6.) Now manipulate the usage_count to simulate a second harvest with a different usage_count later UPDATE erm_usage_mus set usage_count = 111 where title_id = 1 and month=1 and metric_type = 'Unique_Item_Requests' and usage_count=497; The usage_count is now 111 MariaDB [koha_kohadev]> select * from erm_usage_mus where title_id = 1 and month=1 and metric_type = 'Unique_Item_Requests'; +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | monthly_usage_summary_id | title_id | platform_id | database_id | item_id | usage_data_provider_id | year | month | usage_count | metric_type | access_type | yop | report_type | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | 62| 1 | NULL | NULL | NULL | 1 | 2022 | 1 | 111 | Unique_Item_Requests | NULL | NULL | TR | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ 7.) upload the file again, this is the "second harvest" . Note that in the background job there is a line saying "Monthly usages added: 1" Result now: +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | monthly_usage_summary_id | title_id | platform_id | database_id | item_id | usage_data_provider_id | year | month | usage_count | metric_type | access_type | yop | report_type | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | 62| 1 | NULL | NULL | NULL | 1 | 2022 | 1 | 111 | Unique_Item_Requests | NULL | NULL | TR | | 697| 1 | NULL | NULL | NULL | 1 | 2022 | 1 | 497 | Unique_Item_Requests | NULL | NULL | TR | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ -- > Result : 2 rows 8.) Apply patch 9.) upload the file again Result now: MariaDB [koha_kohadev]> select * from erm_usage_mus where title_id = 1 and month=1 and metric_type = 'Unique_Item_Requests'; +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | monthly_usage_summary_id | title_id | platform_id | database_id | item_id | usage_data_provider_id | year | month | usage_count | metric_type | access_type | yop | report_type | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ | 62| 1 | NULL | NULL | NULL | 1 | 2022 | 1 | 497| Unique_Item_Requests | NULL | NULL | TR | +--------------------------+----------+-------------+-------------+---------+------------------------+------+-------+-------------+----------------------+-------------+------+-------------+ -- > Result : only one row as expected. Oldest ID is kept -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #210084|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #210085|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #16 from Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> --- Created attachment 210273 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210273&action=edit Bug 42217: Prevent re-harvested data from duplicating usage A second harvest of a month that was already stored added a new erm_usage_mus row next to the old one as soon as the count differed, so the monthly usage was duplicated and the yearly totals doubled. A month that the provider later corrected to zero was never touched, because CounterFile skipped every zero cell before it reached the database. UsageObject->monthly_usages now identifies a row by every column except usage_count (usage object, provider, year, month, metric type, report type and, where the report has them, access type and yop) and for each monthly usage passed in: - adds a row when none exists - skips the row when the count is unchanged - updates the row in place when the count changed - deletes the rows when the count is zero; zero months are not stored Duplicates left by earlier harvests are removed and the oldest row is kept. The rows of the usage object are read once per call and every change of one call runs in one transaction. CounterFile passes all the months of a report row in one call, including the zero months. The job report gains an updated_mus counter next to added_mus and skipped_mus. Sponsored-by: Karlsruhe Institute of Technology (KIT) Assisted-by: Sonnet 5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #17 from Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> --- Created attachment 210274 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210274&action=edit Bug 42217: Update unit tests UsageObject.t covers monthly_usages: add, skip, update in place, a new identity, duplicates removed with the oldest row kept, zero months not stored and removed when they exist, several months in one call, and the rollback of the whole call when one store fails. The harvester tests check a third harvest over stale, duplicated and zero-month data, through both the SUSHI and the file upload paths. The CounterFile tests check that storing the same file twice adds no rows. Test plan: prove -l t/db_dependent/Koha/ERM/EUsage/UsageObject.t \ t/db_dependent/Koha/BackgroundJobs/ErmSushiHarvester.t \ t/db_dependent/Koha/ERM/EUsage/COUNTER_5/CounterFile.t \ t/db_dependent/Koha/ERM/EUsage/COUNTER_5.1/CounterFile.t yarn cypress run --spec t/cypress/integration/ERM/ModuleDashboard_spec.ts Assisted-by: Sonnet 5 (Anthropic) Signed-off-by: Clemens Tubach <clemens.tubach@kit.edu> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #210273|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 --- Comment #18 from Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> --- Created attachment 210614 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210614&action=edit Bug 42217: Prevent re-harvested data from duplicating usage A second harvest of a month that was already stored added a new erm_usage_mus row next to the old one as soon as the count differed, so the monthly usage was duplicated and the yearly totals doubled. A month that the provider later corrected to zero was never touched, because CounterFile skipped every zero cell before it reached the database. UsageObject->monthly_usages now identifies a row by every column except usage_count (usage object, provider, year, month, metric type, report type and, where the report has them, access type and yop) and for each monthly usage passed in: - adds a row when none exists - skips the row when the count is unchanged - updates the row in place when the count changed - deletes the rows when the count is zero; zero months are not stored Duplicates left by earlier harvests are removed and the oldest row is kept. The rows of the usage object are read once per call and every change of one call runs in one transaction. CounterFile passes all the months of a report row in one call, including the zero months. The job report gains an updated_mus counter next to added_mus and skipped_mus. Sponsored-by: Karlsruhe Institute of Technology (KIT) Assisted-by: Sonnet 5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Lisa G <lgonzalez@palni.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lgonzalez@palni.edu -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Failed QA --- Comment #19 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- The sample file with a single access type has two sets of usage data for "Title 3" - they differ only in YOP - the second overwrites the first - is this correct/expected? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|41294 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41294 [Bug 41294] Allow monthly harvesting only so Data not available for certain months do not result in a complete failure of the harvest -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42217 Michaela Sieber <michaela.sieber@kit.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|rel_26_11_candidate | Target Milestone|26.11 |27.05 --- Comment #20 from Michaela Sieber <michaela.sieber@kit.edu> --- Regarding the issues with cleaning up legacy data, we don't want to rush things. We think we need to take more time to investigate the matter thoroughly. (In reply to Nick Clemens (kidclamp) from comment #19)
The sample file with a single access type has two sets of usage data for "Title 3" - they differ only in YOP - the second overwrites the first - is this correct/expected?
No. The problem is that YOP (and Acccess_Type see Bug 43967) are not stored for Report types where these attributes are not mandatory (Master Reports = TR, DR, PR, IR) -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org