Skip to content
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

Added a config for custom_dimensions_max_length issue-16150 #22582

Open
wants to merge 23 commits into
base: 5.x-dev
Choose a base branch
from

Conversation

jorgeuos
Copy link

Added a config for custom_dimensions_max_length and refactor plugins/CustomDimensions/Tracker/CustomDimensionsRequestProcessor.php:prepareValue() to use the config instead of being hardcoded.

Description:

I will change the max length for custom dimensions in:
https://github.com/matomo-org/matomo/blob/4.11.0-rc1/plugins/CustomDimensions/Tracker/CustomDimensionsRequestProcessor.php#L175

To see how it behaves before I apply my fix.

I'm tracking custom dimensions with a default installation of Matomo. No extra configuration or plugins added.

The default custom_dimension_1 type is varchar(255) in the database.

The tracking code is:

    var _paq = window._paq = window._paq || [];
    var customDimensionId = 1;
    var customDimensionValue = 'LongValue1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
    789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ThisShouldBeCutOff';
    _paq.push(['setCustomDimension', customDimensionId, customDimensionValue]);

I'm modifying the php function like this:

private static function prepareValue($value)
{
    $inputMaxLength = 267;
    $return = mb_substr(trim($value), 0, $inputMaxLength);
    return $return;
}

Story 1:

  • As a user, I want to track a custom dimension with a value that exceeds the limit, so that I can observe how Matomo handles it when the value length is capped at 250 characters.
$inputMaxLength = 250; // 204 OK

Stored value in MySQL:

LongValue1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901

Which equals 250 characters exactly.
custom_dimension_1 type is varchar(255) in the database.

Story 2:

  • As a user, I want to track a custom dimension that reaches the 255-character limit, so that I can verify how Matomo handles and stores the full length.
$inputMaxLength = 255; // 204 OK

Stored value in MySQL:

LongValue1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ThisS

Which equals 255 characters exactly.
custom_dimension_1 type is varchar(255) in the database.

Story 3:

  • As a user, I want to track a custom dimension that exceeds the 255-character limit, so that I can observe Matomo’s behavior when the input length causes data storage to fail without warning.
$inputMaxLength = 256; // 400 Bad Request

Stored value in MySQL:

'' // empty string

This means that MySQL is not storing the value because it is too long. No error is shown in the UI and there is no Tracking failures in the log.
custom_dimension_1 type is varchar(255) in the database.

Story 4:

  • As a user, I want to track a custom dimension with a value longer than the default maximum length by adjusting the database schema to support larger values, so that I can ensure the system behaves correctly with longer data.
  1. I need to change the default column type for custom dimensions in the database from varchar(255) to text.
    According to this issue in Github: Allow custom dimensions of any size (custom_dimension_X fields of unlimited length column (TEXT type) instead of VARCHAR 255) #16150 we can alter the column type in the database like this:
ALTER TABLE matomo_log_visit
MODIFY COLUMN custom_dimension_1 TEXT,
MODIFY COLUMN custom_dimension_2 TEXT,
MODIFY COLUMN custom_dimension_3 TEXT,
MODIFY COLUMN custom_dimension_4 TEXT,
MODIFY COLUMN custom_dimension_5 TEXT;

Which would also help with another unrelated issue: https://forum.matomo.org/t/error-while-updating-to-4-0-0-b1-have-to-change-some-columns-to-text-or-blobs/39482

After a successful change in the database, I will track a custom dimension with a value that is too long so that I can see how Matomo behaves.
custom_dimension_1 type is now TEXT in the database.

  1. Move on to the test case:
$inputMaxLength = 256; // 204 OK

Stored value in MySQL:

LongValue1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ThisSh

Which equals 256 characters exactly.
custom_dimension_1 type is TEXT

Story 5:

  • As a user, I want to track a custom dimension with a value that approaches the TEXT field limit (65,535 characters), so that I can verify that Matomo handles maximum-length values properly.
$inputMaxLength = 65535; // Max length for TEXT

Stored value in MySQL:

LongValue1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ThisShouldBeCutOff

Which equals 250 characters exactly.
custom_dimension_1 type is TEXT in the database.

Conclusion

The default maximum length for custom dimensions is 250 characters. If a value exceeds this limit, it will be truncated and stored, unless the length exceeds 255 characters (the database limit for varchar(255)), in which case it will not be stored at all. Additionally, no error is displayed in the user interface, and no tracking failures are logged.

To fix this issue, a user needs to change the column type for custom dimensions in the database from varchar(255) to TEXT.

Potential edge cases thought about:

  • The TEXT type is not as efficient as varchar(255) for shorter values. TEXT fields are generally less efficient than VARCHAR fields for smaller values. This can have performance implications for large datasets with frequent updates or queries on these fields.
  • The TEXT type can store up to 65535 characters, which is a lot more than the 250 characters needed for custom dimensions.
  • Switching to TEXT fields could result in increased storage use, particularly if a large number of custom dimension values exceed the original 255-character limit, leading to larger data entries.
  • If the custom dimension columns are indexed for performance reasons, switching to a TEXT field could limit the ability to index effectively, as MySQL has restrictions on how much of a TEXT field can be indexed. This could potentially affect query performance, especially if the dimensions are frequently used in queries.
  • A user needs to alter the column type in the database manually.
  • A user updates only the custom_dimension_1 column, but there are 5 custom dimensions in total. The user needs to update all of them.
  • A user only updates the custom_dimension columns in the matomo_log_visit table, but there are other tables where custom dimensions are stored.
    The log_link_visit_action and log_conversion tables also have custom dimension columns that need to be updated.
  • It’s essential to ensure that any schema changes are consistently applied across all relevant tables.
  • Users might not fully understand why they would need to manually update the schema or why the field behaves differently without adjusting the database, leading to confusion. This should be well-documented in the UI or support materials to minimize misunderstandings.

Review

…CustomDimensions/Tracker/CustomDimensionsRequestProcessor.php:prepareValue() to use the config instead of being hardcoded.
@jorgeuos jorgeuos changed the title Added a config for custom_dimensions_max_length and refactor… Added a config for custom_dimensions_max_length issue-16150 Sep 12, 2024
@jorgeuos
Copy link
Author

jorgeuos commented Sep 12, 2024

This is to fix the issue-16150

Copy link
Contributor

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Sep 27, 2024
innocraft-automation and others added 21 commits October 1, 2024 08:26
* Translated using Weblate (Latvian)

Currently translated at 24.2% (17 of 70 strings)

Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <[email protected]>
Co-authored-by: Liena Ritere <[email protected]>
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-login/lv/
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-privacymanager/
Translation: Matomo/Plugin Login
Translation: Matomo/Plugin PrivacyManager

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Translation: Matomo/Plugin Login
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-login/

---------

Co-authored-by: Liena Ritere <[email protected]>
* Fix archiving for range periods

* adds another test
…to a user (matomo-org#22554)

* Add information about risks associated with giving super user access to a user

* Update risks to allow ActivityLog plugin upsell and link to it when activated

* Update UI test screenshots

* Add UI tests with ActivityLog and without Marketplace

* Tweak UI test spec

* Update UI test screenshots

* Update UI test screenshots from CI run

* Ensure to reload the user manager page after changing plugins config

* Reset modal confirmation UI test screenshot

* Use the same modal screenshot approach as used elsewhere in the suite
* Add configuration for database connection collation

* Rename "connection_collation" config to "collation"

* Pass configured database collation to table creation statements

* Detect default collation to be used during database creation

* Save default database collation to config during installation

* Update database collection config if auto-detectable

* Add database collation to diagnostics

* Configure default collation for test environment

* Update expected screenshots

* Look at most recent archive table for update collation detection
* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Update translation files

Updated by "Squash Git commits" hook in Weblate.

Update translation files

Updated by "Squash Git commits" hook in Weblate.

Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <[email protected]>
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-corehome/
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-deviceplugins/
Translation: Matomo/Plugin CoreHome
Translation: Matomo/Plugin DevicePlugins

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Translation: Matomo/Plugin WebsiteMeasurable
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-websitemeasurable/
matomo-org#22603)

* Ensure LatestStable release channel uses the version provided from API

* Adjust test and link in UI

* always download latest stable if no version provided
* use sha256 instead of md5 for file integrity checks

* apply review feedback

* updates expected UI test files
* Require Write access for adding annotations in UI

* adds UI test
* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <[email protected]>
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-privacymanager/
Translation: Matomo/Plugin PrivacyManager

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <[email protected]>
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-privacymanager/
Translation: Matomo/Plugin PrivacyManager

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Translation: Matomo/Plugin Login
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-login/

* Translated using Weblate (Latvian)

Currently translated at 100.0% (60 of 60 strings)

Translation: Matomo/Plugin ScheduledReports
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-scheduledreports/lv/

* Translated using Weblate (German)

Currently translated at 100.0% (35 of 35 strings)

Translation: Matomo/Plugin VisitFrequency
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-visitfrequency/de/

* Translated using Weblate (Latvian)

Currently translated at 15.2% (36 of 236 strings)

Translation: Matomo/Plugin UsersManager
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-usersmanager/lv/

* Translated using Weblate (Latvian)

Currently translated at 100.0% (226 of 226 strings)

Translation: Matomo/Plugin PrivacyManager
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-privacymanager/lv/

* Translated using Weblate (Czech)

Currently translated at 30.0% (21 of 70 strings)

Translation: Matomo/Plugin Login
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-login/cs/

---------

Co-authored-by: Hosted Weblate <[email protected]>
Co-authored-by: Liena Ritere <[email protected]>
Co-authored-by: PeteTrombone <[email protected]>
Co-authored-by: Jiří Podhorecký <[email protected]>
* Limit the end date of range periods to 10 years in the future

* Mark method as api

* Apply review feedback

Co-authored-by: Marc Neudert <[email protected]>

---------

Co-authored-by: Michal Kleiner <[email protected]>
Co-authored-by: Marc Neudert <[email protected]>
* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <[email protected]>
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-sitesmanager/
Translation: Matomo/Plugin SitesManager

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Co-authored-by: Hosted Weblate <[email protected]>
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-sitesmanager/
Translation: Matomo/Plugin SitesManager

* Update translation files

Updated by "Squash Git commits" hook in Weblate.

Translation: Matomo/Plugin CorePluginsAdmin
Translate-URL: https://hosted.weblate.org/projects/matomo/plugin-corepluginsadmin/
…ive message on PCLZIP_ERR_BAD_FORMAT error (matomo-org#22567)

* Adds code to check plugin wise license status and download link, #PG-3814, #PG-3770

* Build vue files

* fixes PHPCS error

* PR feedback applied

* phpcs fixes

* More refactoring

* Added UI tests

* Adds more UI tests

* PR fixes and UI test updated

* Fixes Ui tests and adds new screenshot

* Improved checks to check if it has a download link

* textual changes

* Fixes some tests

* Fixes UI tests

* Fixes for UI test

* UI fixes

* Ui fixes to capture correct screenshot

* Updated text

* UI screenshots updated and error messaged updated for PCLZIP error

* PR changes

* Changes to show the error message correctly for PCLIB error

* textual changes

* Updated UI screenshot

* Applied PR suggestion

* Fixes PHPCS

* Fixes UI test

* Fixes for UI test

* UI test updated

* UI screenshot updated

* Adds more UI tests

* Adds new UI screenshot

* Apply PR feedback

* Fixes to display messages correctly

* Updated text

* Fixes for licenseStatus

* Updated UI screenshots

* Fixes description not displaying

* Updated UI screenshot

* Improved message for donwload link missing

* PF feedback and screenshot updated

* Textual changes and UI screenshot updated

---------

Co-authored-by: AltamashShaikh <[email protected]>
* Update all submodules

* Increase version

* updates expected UI test files

---------

Co-authored-by: diosmosis <[email protected]>
Co-authored-by: Stefan Giehl <[email protected]>
Copy link
Contributor

This PR was last updated more than one month ago, maybe it's time to close it. Please check if there is anything we still can do or close this PR. ping @matomo-org/core-reviewers

@github-actions github-actions bot added the Stale for long The label used by the Close Stale Issues action label Nov 13, 2024
…sor.php


Make sure value is an int

Co-authored-by: Michal Kleiner <[email protected]>
@jorgeuos
Copy link
Author

Ah, makes sense!
Thank you @michalkleiner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale for long The label used by the Close Stale Issues action Stale The label used by the Close Stale Issues action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants