Skip to content

Conversation

@unique0lai
Copy link
Collaborator

No description provided.

@unique0lai unique0lai self-assigned this Oct 23, 2025
@unique0lai unique0lai requested review from EASYGOING45 and Copilot and removed request for EASYGOING45 October 23, 2025 13:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements dynamic metric retention time based on associated VM clusters for custom metric query routing. Instead of using a fixed global expiration time, the system now queries each VM cluster's retention configuration and filters metrics accordingly.

Key Changes:

  • Replaced global metric expiration time with per-cluster retention times fetched from VM cluster configurations
  • Added support for grouping metrics by retention time to optimize batch queries
  • Renamed method from getTableIdClusterId to getTableIdBcsClusterId for clarity

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/bk-monitor-worker/internal/metadata/service/spaceredis.go Core implementation: queries VM cluster retention times, groups metrics by retention period, and filters based on cluster-specific expiration rules
pkg/bk-monitor-worker/internal/metadata/service/spaceredis_test.go Added comprehensive test coverage for retention time logic with three test scenarios (30-day, 60-day, 90-day retention)
pkg/bk-monitor-worker/config/metadata_config.go Added QueryDbTableIdBatchSize configuration parameter for controlling table_id batch size

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +1514 to +1519
if err := storage.NewAccessVMRecordQuerySet(db).Select(storage.AccessVMRecordDBSchema.VmClusterId, storage.AccessVMRecordDBSchema.ResultTableId).BkTenantIdEq(bkTenantId).All(&accessVmRecordList); err != nil {
return nil, err
}
if len(accessVmRecordList) == 0 {
return nil, nil
}
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

The query fetches all AccessVMRecord entries for the tenant without filtering by the specific tableIds being processed. This can retrieve unnecessary records when tableIds is a subset of all tables. Add .ResultTableIdIn(tsGroupTableId...) to the query to only fetch records for the tables actually being processed.

Copilot uses AI. Check for mistakes.
if !ok {
continue
}
vmClusterRetentionTimeMap[cluster.ClusterID] = int(retentionTime.(float64))
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

Type assertion to float64 will panic if the retention_time value in JSON is an integer or other type. Use a safer type assertion with the ok pattern: retentionTimeFloat, ok := retentionTime.(float64); if !ok { continue }, or handle multiple numeric types.

Suggested change
vmClusterRetentionTimeMap[cluster.ClusterID] = int(retentionTime.(float64))
var retentionInt int
switch v := retentionTime.(type) {
case float64:
retentionInt = int(v)
case int:
retentionInt = v
case int64:
retentionInt = int(v)
case uint:
retentionInt = int(v)
case uint64:
retentionInt = int(v)
case string:
// Try to parse string to int
if parsed, err := strconv.Atoi(v); err == nil {
retentionInt = parsed
} else {
continue
}
default:
continue
}
vmClusterRetentionTimeMap[cluster.ClusterID] = retentionInt

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant