Skip to content

chore: [cache-dir-size-fix] Part 2: Add configuration flags and parsing for file cache size fix#4415

Draft
gargnitingoogle wants to merge 1 commit intogargnitin/cache-dir-size-fix/v1from
gargnitin/cache-dir-size-fix/v2
Draft

chore: [cache-dir-size-fix] Part 2: Add configuration flags and parsing for file cache size fix#4415
gargnitingoogle wants to merge 1 commit intogargnitin/cache-dir-size-fix/v1from
gargnitin/cache-dir-size-fix/v2

Conversation

@gargnitingoogle
Copy link
Copy Markdown
Contributor

@gargnitingoogle gargnitingoogle commented Feb 25, 2026

Description

Link to the issue in case of a bug fix.

b/477828938

Testing details

  1. Manual - NA
  2. Unit tests - NA
  3. Integration tests - NA

Any backward incompatible change? If so, please explain.

@gargnitingoogle
Copy link
Copy Markdown
Contributor Author

/gemini review

@gargnitingoogle
Copy link
Copy Markdown
Contributor Author

/gemini summary

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces new configuration flags for a file cache size scan feature. The changes include updating the configuration struct, adding and parsing command-line flags, and implementing associated validation and rationalization logic. The implementation is clear and includes new tests for argument parsing and config rationalization. My primary feedback is to enhance the test coverage for the new validation logic to ensure all scenarios are properly handled.

Comment thread cfg/validate_test.go Outdated
Comment on lines +1224 to +1285
func TestValidateFileCacheConfig_SizeScanDeleteEmptyDirs(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
config FileCacheConfig
wantErr bool
}{
{
name: "Enable=False,_Delete=True_->_Error",
config: FileCacheConfig{
SizeScanEnable: false,
SizeScanDeleteEmptyDirs: true,
// Valid defaults
CacheFileForRangeRead: false,
DownloadChunkSizeMb: 50,
EnableCrc: false,
EnableParallelDownloads: false,
MaxParallelDownloads: 4,
MaxSizeMb: -1,
ParallelDownloadsPerFile: 16,
WriteBufferSize: 4 * 1024 * 1024,
EnableODirect: true,
},
wantErr: true,
},
{
name: "Enable=True,_Delete=True_->_Valid",
config: FileCacheConfig{
SizeScanEnable: true,
SizeScanDeleteEmptyDirs: true,
SizeScanFrequencySeconds: 10,
// Valid defaults
CacheFileForRangeRead: false,
DownloadChunkSizeMb: 50,
EnableCrc: false,
EnableParallelDownloads: false,
MaxParallelDownloads: 4,
MaxSizeMb: -1,
ParallelDownloadsPerFile: 16,
WriteBufferSize: 4 * 1024 * 1024,
EnableODirect: true,
},
wantErr: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
c := validConfig(t)
c.FileCache = tc.config

err := ValidateConfig(viper.New(), &c)

if tc.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new test TestValidateFileCacheConfig_SizeScanDeleteEmptyDirs is a good start, but it only covers one of the new validation scenarios for the size scan feature. To ensure robustness, it would be beneficial to expand this test to cover all the new validation logic added in isValidFileCacheConfig.

I'd suggest renaming the test to something more general, like TestValidateFileCacheConfig_SizeScanFlags, and adding test cases for the following scenarios:

  • SizeScanEnable=true with SizeScanFrequencySeconds=0 should return an error.
  • SizeScanEnable=false with SizeScanFiles=true should return an error.
  • SizeScanEnable=false with SizeScanFrequencySeconds explicitly set to a non-zero value should return an error. This requires setting the value in the viper instance passed to ValidateConfig.

Here's an example for the last case:

// In a new test case
v := viper.New()
v.Set("file-cache.size-scan-frequency-seconds", 5)
c := validConfig(t)
c.FileCache.SizeScanEnable = false
c.FileCache.SizeScanFrequencySeconds = 5

err := ValidateConfig(v, &c)

assert.Error(t, err)

This will make the tests for the new validation logic more comprehensive.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request, part two of a cache directory size fix, establishes the foundational configuration and parsing mechanisms for a new file cache size management feature. It introduces several new flags that allow users to precisely control how the file cache directory is scanned for size, including options for enabling/disabling the scan, specifying scan frequency, and managing empty directories. This work lays the groundwork for the actual implementation of the size scanning functionality.

Highlights

  • New Configuration Parameters: Introduced new configuration parameters for controlling file cache size scanning, including enabling/disabling the scan, scanning files, deleting empty directories, and setting scan frequency.
  • Parsing Logic for New Flags: Implemented parsing logic for the newly added file cache size scan flags in the command-line interface.
  • Validation Rules: Added validation rules to ensure consistency and correctness of the file cache size scan configurations, such as requiring a positive scan frequency when enabled.
  • Expanded Test Coverage: Expanded unit and integration tests to cover the new configuration parameters, their parsing, and validation logic.
Changelog
  • cfg/config.go
    • Added SizeScanDeleteEmptyDirs, SizeScanEnable, SizeScanFiles, and SizeScanFrequencySeconds fields to the FileCacheConfig struct.
    • Registered new command-line flags for these file cache size scan parameters.
  • cfg/config_util.go
    • Introduced DefaultFileCacheSizeScanFrequencySeconds constant.
  • cfg/params.yaml
    • Defined new YAML parameters for file-cache.size-scan-delete-empty-dirs, file-cache.size-scan-enable, file-cache.size-scan-files, and file-cache.size-scan-frequency-seconds.
  • cfg/rationalize.go
    • Added resolveSizeScanEnableValue function to conditionally disable size scanning if MaxSizeMb is -1 or file cache is not enabled.
    • Integrated resolveSizeScanEnableValue into the Rationalize function.
  • cfg/rationalize_test.go
    • Added TestRationalize_SizeScanEnableValue to test the conditional disabling of size scanning.
  • cfg/validate.go
    • Modified isValidFileCacheConfig to accept a viper.Viper instance.
    • Implemented new validation logic for file cache size scan flags, ensuring dependencies and valid ranges (e.g., frequency > 0 when enabled).
  • cfg/validate_test.go
    • Added new test cases to validate the file cache size scan configuration logic.
  • cmd/config_validation_test.go
    • Updated defaultFileCacheConfig and TestValidateConfigFile_FileCacheConfigSuccessful to include the new size scan parameters.
  • cmd/root_test.go
    • Updated TestArgsParsing_FileCacheFlags to include new size scan parameters in expected configurations.
    • Added TestArgsParsing_FileCacheSizeScanFlags to specifically test argument parsing and validation for the new size scan flags.
Activity
  • The author, gargnitingoogle, requested a Gemini review.
  • The author, gargnitingoogle, requested a Gemini summary.
  • gemini-code-assist[bot] provided a review comment suggesting to expand the test TestValidateFileCacheConfig_SizeScanDeleteEmptyDirs to cover all new validation scenarios for the size scan feature, including cases for SizeScanEnable=true with SizeScanFrequencySeconds=0, SizeScanEnable=false with SizeScanFiles=true, and SizeScanEnable=false with SizeScanFrequencySeconds explicitly set to a non-zero value.

@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v2 branch 2 times, most recently from 4a6bbb9 to 3938291 Compare February 25, 2026 11:30
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v1 branch from ebd1a5e to fec64b0 Compare February 26, 2026 05:31
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v2 branch from 3938291 to 9e7e9c4 Compare February 26, 2026 06:11
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v1 branch from fec64b0 to 28e5de1 Compare March 12, 2026 05:14
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v2 branch from 9e7e9c4 to 1d5a9ce Compare March 12, 2026 05:14
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v1 branch from 28e5de1 to cc61e60 Compare March 12, 2026 07:42
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v2 branch from 1d5a9ce to 30075a4 Compare March 12, 2026 07:42
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v1 branch from cc61e60 to 77e24b9 Compare March 20, 2026 08:00
@gargnitingoogle gargnitingoogle force-pushed the gargnitin/cache-dir-size-fix/v2 branch from 30075a4 to d754d78 Compare March 20, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant