Skip to content

Add split phase metrics for filestream fsync operations - #10493

Merged
valyala merged 5 commits into
VictoriaMetrics:masterfrom
mehrdadbn9:feature/filestream-fsync-metrics
Apr 2, 2026
Merged

Add split phase metrics for filestream fsync operations#10493
valyala merged 5 commits into
VictoriaMetrics:masterfrom
mehrdadbn9:feature/filestream-fsync-metrics

Conversation

@mehrdadbn9

Copy link
Copy Markdown
Contributor

Summary

This PR implements split phase metrics for filestream operations as requested in #10432.

Changes

  • Added vm_filestream_fsync_duration_seconds_total metric to track fsync syscall duration separately
  • Added vm_filestream_fsync_calls_total metric to count fsync calls
  • Added vm_filestream_write_syscall_duration_seconds_total metric to track write syscall duration (previously mixed with flush time)
  • Refactored MustClose() and MustFlush() to use new flush() and sync() helper methods
  • Kept vm_filestream_write_duration_seconds_total for backward compatibility

Problem Solved

Previously, vm_filestream_write_duration_seconds_total was being incremented in two places:

  1. statWriter.Write() - triggered by bw.Flush() and bw.Write()
  2. Writer.MustFlush() - which included the above process, leading to double-counting

This made it impossible to distinguish between write syscall time and fsync time, which is critical for diagnosing storage latency issues.

Solution

The new metrics allow users to:

  • Distinguish "flush got slower" vs "fsync got slower" using metrics only
  • No file path labels (bounded cardinality)
  • No double-counting between metrics

Testing

  • Code compiles successfully
  • All existing metrics are preserved for backward compatibility

Closes #10432

## Summary

This PR implements split phase metrics for filestream operations as requested in VictoriaMetrics#10432.

### Changes

- Added `vm_filestream_fsync_duration_seconds_total` metric to track fsync syscall duration separately
- Added `vm_filestream_fsync_calls_total` metric to count fsync calls
- Added `vm_filestream_write_syscall_duration_seconds_total` metric to track write syscall duration (previously mixed with flush time)
- Refactored `MustClose()` and `MustFlush()` to use new `flush()` and `sync()` helper methods
- Kept `vm_filestream_write_duration_seconds_total` for backward compatibility

### Problem Solved

Previously, `vm_filestream_write_duration_seconds_total` was being incremented in two places:
1. `statWriter.Write()` - triggered by `bw.Flush()` and `bw.Write()`
2. `Writer.MustFlush()` - which included the above process, leading to double-counting

This made it impossible to distinguish between write syscall time and fsync time, which is critical for diagnosing storage latency issues.

### Solution

The new metrics allow users to:
- Distinguish "flush got slower" vs "fsync got slower" using metrics only
- No file path labels (bounded cardinality)
- No double-counting between metrics

Closes VictoriaMetrics#10432

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 1 file

@valyala valyala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread lib/filestream/filestream.go Outdated
Comment thread lib/filestream/filestream.go Outdated
valyala added 2 commits April 2, 2026 13:13
Signed-off-by: Aliaksandr Valialkin <[email protected]>
Signed-off-by: Aliaksandr Valialkin <[email protected]>
@valyala
valyala merged commit dd2d680 into VictoriaMetrics:master Apr 2, 2026
@valyala

valyala commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

@mehrdadbn9 , thank you for the pull request!

valyala added a commit that referenced this pull request Apr 2, 2026
## Summary

This PR implements split phase metrics for filestream operations as
requested in #10432.

### Changes

- Added `vm_filestream_fsync_duration_seconds_total` metric to track
fsync syscall duration separately
- Added `vm_filestream_fsync_calls_total` metric to count fsync calls
- Added `vm_filestream_write_syscall_duration_seconds_total` metric to
track write syscall duration (previously mixed with flush time)
- Refactored `MustClose()` and `MustFlush()` to use new `flush()` and
`sync()` helper methods
- Kept `vm_filestream_write_duration_seconds_total` for backward
compatibility

### Problem Solved

Previously, `vm_filestream_write_duration_seconds_total` was being
incremented in two places:
1. `statWriter.Write()` - triggered by `bw.Flush()` and `bw.Write()`
2. `Writer.MustFlush()` - which included the above process, leading to
double-counting

This made it impossible to distinguish between write syscall time and
fsync time, which is critical for diagnosing storage latency issues.

### Solution

The new metrics allow users to:
- Distinguish "flush got slower" vs "fsync got slower" using metrics
only
- No file path labels (bounded cardinality)
- No double-counting between metrics

### Testing

- Code compiles successfully
- All existing metrics are preserved for backward compatibility

Closes #10432

---------

Signed-off-by: Aliaksandr Valialkin <[email protected]>
Signed-off-by: Aliaksandr Valialkin <[email protected]>
Co-authored-by: Aliaksandr Valialkin <[email protected]>
Co-authored-by: Aliaksandr Valialkin <[email protected]>
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.

Split filestream write vs fsync metrics

3 participants