Skip to content

add metrics for tombstones - #18198

Merged
mergify[bot] merged 14 commits into
matrixorigin:mainfrom
Wenbin1002:transfer-tomb-metrics
Aug 17, 2024
Merged

mergify[bot] merged 14 commits into
matrixorigin:mainfrom
Wenbin1002:transfer-tomb-metrics

Conversation

@Wenbin1002

@Wenbin1002 Wenbin1002 commented Aug 17, 2024 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #11471

What this PR does / why we need it:

add metrics for tombstones transfer

  • transfer tombstone count
  • transfer tombstone duration
  • batch transfer tombstone duration

PR Type

Enhancement


Description

  • Added new metrics for monitoring tombstone transfers, including count and duration.
  • Enhanced Grafana dashboard with a new row for visualizing tombstone transfer metrics.
  • Registered and defined new histograms for these metrics in the codebase.
  • Implemented metric observation in the tombstone transfer process to track performance.

Changes walkthrough 📝

Relevant files
Enhancement
grafana_dashboard_txn.go
Add tombstone transfer metrics to Grafana dashboard           

pkg/util/metric/v2/dashboard/grafana_dashboard_txn.go

  • Added a new row for tombstone transfer metrics in the transaction
    dashboard.
  • Introduced metrics for transfer tombstones count and duration.
  • Utilized timeseries for visual representation.
  • +33/-0   
    metrics.go
    Register new tombstone transfer metrics                                   

    pkg/util/metric/v2/metrics.go

  • Registered new histograms for tombstone transfer metrics.
  • Added a function to get short duration buckets.
  • +7/-0     
    txn.go
    Define histograms for tombstone transfer metrics                 

    pkg/util/metric/v2/txn.go

  • Defined new histograms for transfer tombstones count and duration.
  • Added labels for tombstone and batch transfer durations.
  • +21/-0   
    transfer.go
    Implement metric observation in tombstone transfer             

    pkg/vm/engine/disttae/transfer.go

  • Logged additional information about deleted and created objects.
  • Observed metrics for tombstone transfer count and duration.
  • Added observation for batch transfer tombstone duration.
  • +10/-1   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Naming Inconsistency
    The histogram name 'transfer_tombstones_count' doesn't follow the naming convention of other metrics. Consider renaming it to 'transfer_tombstones_count_histogram' for consistency.

    Error Handling
    The deferred function in TransferTombstones() always logs and records metrics, even if an error occurs. Consider adding error checks before logging success messages and recording metrics.

    @qodo-code-review

    qodo-code-review Bot commented Aug 17, 2024 •

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    ✅ Move a metric observation outside of a deferred function to ensure accurate counting
    Suggestion Impact:The metric observation for TransferTombstonesCountHistogram was moved outside the deferred function to ensure accurate counting.

    code diff:

    +	v2.TransferTombstonesCountHistogram.Observe(1)
     	defer func() {
     		duration := time.Since(start)
     		if duration > time.Millisecond*500 || err != nil || wantDetail {
    @@ -82,7 +83,6 @@
     				zap.Error(err),
     			)
     		}
    -		v2.TransferTombstonesCountHistogram.Observe(1)

    Consider moving the metric observation for TransferTombstonesCountHistogram outside
    the deferred function. The current placement might lead to inaccurate counts if the
    function panics before reaching the deferred function.

    pkg/vm/engine/disttae/transfer.go [74-87]

    +v2.TransferTombstonesCountHistogram.Observe(1)
     defer func() {
     		duration := time.Since(start)
     		if duration > time.Second {
     			logutil.Info(
     				"TRANSFER-TOMBSTONE-SLOW-LOG",
     				zap.Duration("duration", duration),
     				zap.Int("count", transferCnt),
     				zap.String("table-name", table.tableDef.Name),
     				zap.Uint64("table-id", table.tableId),
     				zap.Int("deleted-objects", len(deletedObjects)),
     				zap.Int("created-objects", len(createdObjects)),
     				zap.Error(err),
     			)
     		}
    -		v2.TransferTombstonesCountHistogram.Observe(1)
     		v2.TransferTombstonesDurationHistogram.Observe(duration.Seconds())
     	}()
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Moving the metric observation outside the deferred function ensures accurate counting, especially in cases where the function might panic, thus addressing a potential issue in the code.

    9
    Enhancement
    ✅ Update the help text for a metric to accurately reflect its purpose
    Suggestion Impact:The help text was updated to better reflect the metric's purpose, although the final text was slightly different from the suggestion, mentioning "tombstones transfer durations" instead of just "transfer durations".

    code diff:

    -			Help:      "Bucketed histogram of short tn task execute duration.",
    +			Help:      "Bucketed histogram of tombstones transfer durations.",

    The help text for txnTransferDurationHistogram mentions "short tn task execute
    duration", which seems inconsistent with the metric name "transfer_duration".
    Consider updating the help text to accurately reflect the metric's purpose, such as
    "Bucketed histogram of transfer durations".

    pkg/util/metric/v2/txn.go [332-339]

     txnTransferDurationHistogram = prometheus.NewHistogramVec(
     		prometheus.HistogramOpts{
     			Namespace: "mo",
     			Subsystem: "txn",
     			Name:      "transfer_duration",
    -			Help:      "Bucketed histogram of short tn task execute duration.",
    +			Help:      "Bucketed histogram of transfer durations.",
     			Buckets:   getShortDurationBuckets(),
     		}, []string{"type"})
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Correcting the help text to accurately describe the metric's purpose enhances documentation and prevents potential confusion for developers and users.

    8
    Maintainability
    Use a variable for the interval in metric queries instead of hardcoding it

    Consider using a constant or a configuration variable for the interval in the metric
    query string instead of hardcoding '$interval'. This would make the code more
    flexible and easier to maintain.

    pkg/util/metric/v2/dashboard/grafana_dashboard_txn.go [526]

    -"sum by (%s) (increase(%s[$interval]))",
    +"sum by (%s) (increase(%s[%s]))",
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using a variable for the interval in metric queries enhances maintainability by making the code more flexible and easier to update if the interval needs to change.

    7
    Best practice
    Rename function to better describe its purpose of providing high-precision duration buckets

    Consider using a more descriptive name for the getShortDurationBuckets() function,
    such as getHighPrecisionDurationBuckets(), to better reflect its purpose of
    providing buckets with higher precision for shorter durations.

    pkg/util/metric/v2/metrics.go [204-206]

    -func getShortDurationBuckets() []float64 {
    +func getHighPrecisionDurationBuckets() []float64 {
     	return append(prometheus.ExponentialBuckets(0.00000001, 2, 30), math.MaxFloat64)
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: The suggestion improves code readability by providing a more descriptive function name, which helps developers understand its purpose more clearly.

    6

    @matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Aug 17, 2024
    @matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Aug 17, 2024
    @mergify
    mergify Bot merged commit 0fb7bd8 into matrixorigin:main Aug 17, 2024
    fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
    add metrics for tombstones transfer
    * transfer tombstone count
    * transfer tombstone duration
    * batch transfer tombstone duration
    
    Approved by: @aptend, @triump2020, @zhangxu19830126, @XuPeng-SH
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    6 participants