Add validation constraints to system.performance

Created on 2 April 2024, 5 months ago
Updated 15 July 2024, about 2 months ago

Problem/Motivation

system.performance has 4 property path that are not yet validatable:

./vendor/bin/drush config:inspect --filter-keys=system.performance --detail --list-constraints
➜  🤖 Analyzing…

 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ----------------------------------------------- --------- ------------- ------ ------------------------------------------ 
  Key                                             Status    Validatable   Data   Validation constraints                    
 ----------------------------------------------- --------- ------------- ------ ------------------------------------------ 
  system.performance                              Correct   76%           ✅❓   ValidKeys: '<infer>'                      
   system.performance:                            Correct   Validatable   ✅✅   ValidKeys: '<infer>'                      
   system.performance:_core                       Correct   Validatable   ✅✅   ValidKeys:                                
                                                                                   - default_config_hash                   
   system.performance:_core.default_config_hash   Correct   Validatable   ✅✅   NotNull: {  }                             
                                                                                 Regex: '/^[a-zA-Z0-9\-_]+$/'              
                                                                                 Length: 43                                
                                                                                 ↣ PrimitiveType: {  }                     
   system.performance:cache                       Correct   Validatable   ✅✅   ValidKeys: '<infer>'                      
   system.performance:cache.page                  Correct   Validatable   ✅✅   ValidKeys: '<infer>'                      
   system.performance:cache.page.max_age          Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here  
   system.performance:css                         Correct   Validatable   ✅✅   ValidKeys: '<infer>'                      
   system.performance:css.gzip                    Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                     
   system.performance:css.preprocess              Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                     
   system.performance:fast_404                    Correct   Validatable   ✅✅   ValidKeys: '<infer>'                      
   system.performance:fast_404.enabled            Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                     
   system.performance:fast_404.exclude_paths      Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here  
   system.performance:fast_404.html               Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here  
   system.performance:fast_404.paths              Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here  
   system.performance:js                          Correct   Validatable   ✅✅   ValidKeys: '<infer>'                      
   system.performance:js.gzip                     Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                     
   system.performance:js.preprocess               Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }                     
 ----------------------------------------------- --------- ------------- ------ ------------------------------------------

Steps to reproduce

  1. Get a local git clone of Drupal core 10.3.x.
  2. composer require drupal/config_inspector — or manually install https://www.drupal.org/project/config_inspector/releases/2.1.5 or newer (which supports Drupal 11!)
  3. composer require drush/drush
  4. vendor/bin/drush config:inspect --filter-keys=system.performance --detail --list-constraints

Proposed resolution

Add validation constraints to:

  1. system.performance:cache.page.max_age
  2. system.performance:fast_404.exclude_paths
  3. system.performance:fast_404.html
  4. system.performance:fast_404.paths

For examples, search *.schema.yml files for the string constraints: 😊

Reach out to @borisson_ or @wimleers in the #distributions-and-recipes.

Remaining tasks

User interface changes

None.

API changes

Data model changes

More validation 🚀

Release notes snippet

None.

📌 Task
Status

Needs work

Version

11.0 🔥

Component
System 

Last updated 1 day ago

No maintainer
Created by

🇮🇳India narendraR Jaipur, India

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @narendraR
  • Merge request !7321Resolve #3437608 "Add validation constraints" → (Open) created by narendraR
  • Pipeline finished with Failed
    5 months ago
    Total: 570s
    #137165
  • Pipeline finished with Failed
    5 months ago
    Total: 342s
    #137292
  • Pipeline finished with Failed
    5 months ago
    Total: 628s
    #137314
  • Pipeline finished with Failed
    5 months ago
    Total: 666s
    #137690
  • First commit to issue fork.
  • Pipeline finished with Success
    5 months ago
    Total: 718s
    #137828
  • Pipeline finished with Success
    5 months ago
    Total: 690s
    #138262
  • Status changed to Needs review 5 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Pipeline finished with Success
    5 months ago
    Total: 711s
    #138381
  • Status changed to Needs review 5 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Pipeline finished with Failed
    5 months ago
    Total: 191s
    #140516
  • Pipeline finished with Success
    5 months ago
    Total: 1306s
    #140522
  • Status changed to Needs review 5 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review 5 months ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    The changes to the kernel test are out of scope. The "fix" is wrong.

  • Pipeline finished with Failed
    5 months ago
    Total: 359s
    #141717
  • Pipeline finished with Failed
    5 months ago
    Total: 271s
    #141721
  • Pipeline finished with Canceled
    5 months ago
    Total: 430s
    #141731
  • Status changed to Needs review 5 months ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Pipeline finished with Success
    5 months ago
    #141742
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review 5 months ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Status changed to Needs work 5 months ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review 5 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    Dear bot, get lost.

  • Pipeline finished with Success
    5 months ago
    Total: 1417s
    #141878
  • Status changed to Needs work 5 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
    1. +1 for @phenaproxima's proposal at https://git.drupalcode.org/project/drupal/-/merge_requests/7321#note_294324 to use DivisibleBy instead of Choice.

      IMHO it should be done here, not elsewhere, because none of the existing uses of the Choice constraint in Drupal core so far are using it to restrict it to a list of integers. In principle, there's nothing wrong with that, but it'll be very likely that values specified in config by hand will be considered incorrect. The "multiple of 60" rule that @phenaproxima proposes is much more elegant: it's lenient to allow any number, as long as it's with a granularity of 1 minute. That seems much better!

    2. Also spotted one thing that's still lacking validation: https://git.drupalcode.org/project/drupal/-/merge_requests/7321#note_294477
    3. And one thing whose validation is semantically incorrect: https://git.drupalcode.org/project/drupal/-/merge_requests/7321#note_294478 — but for which a correct example was introduced in Drupal core in [PP-1] Mark parts of CKEditor 5 and Editor config schema as fully validatable Postponed :)
  • Pipeline finished with Success
    5 months ago
    Total: 1007s
    #141910
  • Pipeline finished with Failed
    4 months ago
    Total: 1908s
    #162665
  • Pipeline finished with Canceled
    4 months ago
    Total: 359s
    #162686
  • Pipeline finished with Canceled
    4 months ago
    #162697
  • Pipeline finished with Failed
    4 months ago
    Total: 178s
    #162698
  • Pipeline finished with Canceled
    4 months ago
    Total: 117s
    #162702
  • Pipeline finished with Success
    4 months ago
    Total: 538s
    #162703
  • Status changed to Needs review 4 months ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Status changed to Needs work 4 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
    1. There's one last thing to address: https://git.drupalcode.org/project/drupal/-/merge_requests/7321#note_294486 :)
    2. The MR needs to be updated to target 11.x.
  • First commit to issue fork.
  • Merge request !7992Resolve #3437608 "Validation 11 x" → (Open) created by mikelutz
  • 🇺🇸United States mikelutz Michigan, USA

    mikelutz changed the visibility of the branch 3437608-add-validation-constraints to hidden.

  • 🇺🇸United States mikelutz Michigan, USA

    mikelutz changed the visibility of the branch 11.x to hidden.

  • Status changed to Needs review 4 months ago
  • 🇺🇸United States mikelutz Michigan, USA

    Opened a new MR against 11.x, and added a constraint to validate whether a string is valid regex.

  • Pipeline finished with Failed
    4 months ago
    Total: 607s
    #168123
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States smustgrave

    Can the MR be rebased? Believe the errors may be related to broken HEAD from the other day.

  • Pipeline finished with Success
    4 months ago
    Total: 664s
    #169803
  • Status changed to Needs review 4 months ago
  • 🇺🇸United States mikelutz Michigan, USA
  • Assigned to mikelutz
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States mikelutz Michigan, USA

    NW for Phenaproxima's comments.

  • Pipeline finished with Failed
    4 months ago
    Total: 167s
    #175808
  • Issue was unassigned.
  • Status changed to Needs review 4 months ago
  • 🇺🇸United States mikelutz Michigan, USA

    That all sounds good to me. I also set 'regex' as a schema type so we don't have to add the constraint anywhere we might need to use it in the future.

    As a side note, it seems weird to me that 'exclude paths' can't be empty/null, but I checked the code, and fast404 just doesn't do anything unless you exclude *something*. Seems like that could be adjusted, but out of scope here.

    All feedback addressed. back to NR.

  • Pipeline finished with Failed
    4 months ago
    Total: 3155s
    #175823
  • 🇺🇸United States mikelutz Michigan, USA

    The failing test seems to be broken on HEAD, will rebase once it's fixed.

  • 🇺🇸United States mikelutz Michigan, USA

    Rebased now that 🐛 InstallerTranslationExistingFileTest fails on 11.x branch Active is in. Tests should pass now.

  • Pipeline finished with Success
    4 months ago
    Total: 628s
    #176600
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    I think this looks great, I agree that both html and regex being new types is a good idea for reusability. We should create change records for both of those new types.

  • Status changed to Needs work 4 months ago
  • 🇺🇸United States smustgrave

    Agreed on the CR.

    Eventually would love if we could update the cheat sheet on https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-... or start a new one.

  • Status changed to Needs review 3 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Status changed to RTBC 3 months ago
  • 🇺🇸United States smustgrave

    CR's look good. I really like the sections "How to use?" even though pretty straightforward it's a nice touch.

    Thanks!

  • Status changed to Needs work 3 months ago
  • 🇬🇧United Kingdom catch

    Don't really agree with max age being limited to multiples of 60, left a comment on the MR.

  • Status changed to Needs review 3 months ago
  • 🇺🇸United States mikelutz Michigan, USA

    The latest push makes the change I recommended above, constraining the value to an integer between 1 and 3156000 and reconfiguring the form to use a number field with the same constraints. I didn't see any specific tests around this form to adjust, but there might be a functional Javascript test somewhere that will need to be adjusted.

  • Pipeline finished with Failed
    3 months ago
    Total: 575s
    #187195
  • Pipeline finished with Success
    3 months ago
    Total: 543s
    #187228
  • Pipeline finished with Success
    3 months ago
    Total: 528s
    #187285
  • 🇺🇸United States mikelutz Michigan, USA

    Reverted the form changes and moved them to a follow-up 📌 Improve UX of system performance form max-age form input Active to determine how best to improve the form UX

    Also reverted the changes to ConstraintManager that exposed DivisibleBy as we are no longer going to use it here.

    Thanks to @catch and @phenaproxima for the slack discussion. Back to NR

  • Status changed to RTBC 3 months ago
  • 🇺🇸United States smustgrave

    Checked the CR and both read fine. "Generally speaking:" like those sections

    Ran test-only feature and got https://git.drupalcode.org/issue/drupal-3437608/-/jobs/1740193 so definitely shows extensive test coverage.

    Checking MR appear all feedback has been resolved.

    Applied to 11.x with config inspector installed

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    LGTM!

  • Pipeline finished with Canceled
    3 months ago
    #196869
  • Pipeline finished with Success
    3 months ago
    #196870
  • Status changed to Needs work 2 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    I've added a couple of comments to the MR - minor test related stuff. Otherwise this looks great.

  • Pipeline finished with Success
    2 months ago
    Total: 532s
    #209929
  • Status changed to Needs review 2 months ago
  • 🇮🇳India narendraR Jaipur, India

    Feedback addressed.

  • Status changed to RTBC 2 months ago
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    Back to rtbc now that the remarks have been fixed.

  • Status changed to Needs work 2 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    I think we need to think a bit more about HTML validation and what an html type means. Plus we have an issue with adding a new code dependency to the Utility component.

  • 🇺🇸United States phenaproxima Massachusetts

    That makes sense.

    IMHO, we should be looking at this as a snippet of HTML, rather than a full page. What would be a reasonable way of validating that, if we can't use a parser?

    I also agree that we don't want to add accidental cross-component dependencies, so this probably needs some refactoring. Maybe a whole new constraint to confirm that something is a valid HTML snippet?

  • Assigned to mikelutz
  • 🇺🇸United States mikelutz Michigan, USA

    I'm going to move it to a full fledged constraint in Core/Validation to solve the dependency issue. To make it work for both snippets and full pages, I think we can have the constraint just wrap snippets in "" .. "". We could either define whether to do so in an argument to the constraint, or try to autodetect, but I'm going with a constraint argument that defaults to snippet because the schema would want to decide which it allows. The fast_404 html here would want a full page and want to reject a snippet so I don't see autodetecting being practical.

    (Ironically, I was resurrecting 📌 Create a trait and base class to implement \Drupal\Component\Plugin\ConfigurableInterface Needs review the other day and I realized the we nearly did the same intercomponent dependency in the patch we committed and reverted all those years ago. We were going to call Component\Utility\NestedArray from Component\Plugin and didn't notice)

  • Pipeline finished with Failed
    about 2 months ago
    Total: 170s
    #221890
  • Issue was unassigned.
  • Status changed to Needs review about 2 months ago
  • 🇺🇸United States mikelutz Michigan, USA
  • Pipeline finished with Failed
    about 2 months ago
    Total: 319s
    #221900
  • Pipeline finished with Success
    about 2 months ago
    Total: 449s
    #221951
  • Status changed to Needs work about 2 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    Found a lot of small things I think could be improved. But in general I agree with the approach here and the usefulness of these new constraints.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 175s
    #224975
Production build 0.71.5 2024