-
Notifications
You must be signed in to change notification settings - Fork 341
Optimize the effective logic of num_most_recent_indicesconfiguration in the es plugin #1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
df3f3f9
14193c5
65337e5
26c3833
0c3943c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -100,3 +100,20 @@ cluster_info_interval = "5m" | |||||||||||||||||||||||||||||
| # tls_key = "/etc/categraf/key.pem" | ||||||||||||||||||||||||||||||
| ## Use TLS but skip chain & host verification | ||||||||||||||||||||||||||||||
| # insecure_skip_verify = true | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Sets the number of most recent indices to return for indices that are configured with a date-stamped suffix. | ||||||||||||||||||||||||||||||
| ## Each 'indices_include' entry ending with a wildcard (*) or glob matching pattern will group together all indices that match it, and | ||||||||||||||||||||||||||||||
| ## sort them by the date or number after the wildcard. Metrics then are gathered for only the 'num_most_recent_indices' amount of most | ||||||||||||||||||||||||||||||
| ## recent indices. | ||||||||||||||||||||||||||||||
| num_most_recent_indices = 0 | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## must num_most_recent_indices Coordinated use | ||||||||||||||||||||||||||||||
| ## default ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | ||||||||||||||||||||||||||||||
| ## match //YYYY.MM.DD or YYYY-MM-DD or YYYYMMDD or YYYY-MM-DD-HH | ||||||||||||||||||||||||||||||
| ## //YYYY.MM or YYYY-MM or YYYYMM or YYYYMMDDHH | ||||||||||||||||||||||||||||||
| ## //YY.MM.DD or YY-MM-DD or YYMMDD or YY.MM.DD.HH | ||||||||||||||||||||||||||||||
| ## //v1_001 v1_002 -->v1* v0.1 v0.2 -->v0* v5.2.3 v5.2.4 -->v5* | ||||||||||||||||||||||||||||||
| ## or self expansion | ||||||||||||||||||||||||||||||
| dynamic_index_matcher_regexp = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | ||||||||||||||||||||||||||||||
|
Comment on lines
+113
to
+119
|
||||||||||||||||||||||||||||||
| ## default ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | |
| ## match //YYYY.MM.DD 或 YYYY-MM-DD 或 YYYYMMDD 或 YYYY-MM-DD-HH | |
| ## //YYYY.MM 或 YYYY-MM 或 YYYYMM 或YYYYMMDDHH | |
| ## //YY.MM.DD 或 YY-MM-DD 或 YYMMDD 或YYYY.MM.DD.HH | |
| ## //v1_001 v1_002 -->v1* v0.1 v0.2 -->v0* v5.2.3 v5.2.4 -->v5* | |
| ## or self expansion | |
| dynamic_index_matcher_regexp = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | |
| ## default ["(?P<date>(?:\d{4}|\d{2})[.-]?(?:\d{2})[.-]?(?:\d{2})?[.-]?(?:\d{2})?)$","[\\.-._]\d+(\.\d+){0,2}$"] | |
| ## match //YYYY.MM.DD 或 YYYY-MM-DD 或 YYYYMMDD 或 YYYY-MM-DD-HH | |
| ## //YYYY.MM 或 YYYY-MM 或 YYYYMM 或YYYYMMDDHH | |
| ## //YY.MM.DD 或 YY-MM-DD 或 YYMMDD 或YYYY.MM.DD.HH | |
| ## //v1_001 v1_002 -->v1* v0.1 v0.2 -->v0* v5.2.3 v5.2.4 -->v5* | |
| ## or self expansion | |
| dynamic_index_matcher_regexp = ["(?P<date>(?:\d{4}|\d{2})[.-]?(?:\d{2})[.-]?(?:\d{2})?[.-]?(?:\d{2})?)$","[\\.-._]\d+(\.\d+){0,2}$"] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -483,3 +483,20 @@ ES 7.x 支持基于角色的访问控制(RBACs)。`elasticsearch` 插件需 | |||||
| | elasticsearch_slm_stats_snapshots_deleted_total | counter | 按策略删除的快照数 | | ||||||
| | elasticsearch_slm_stats_snapshot_deletion_failures_total | counter | 按策略快照删除失败次数 | | ||||||
| | elasticsearch_slm_stats_operation_mode | gauge | SLM操作模式(运行中,停止中,已停止) | | ||||||
|
|
||||||
|
|
||||||
| #### `num_most_recent_indices = 0` | ||||||
|
|
||||||
|
|
||||||
| | 设置日期类动态索引可取前"num_most_recent_indices"个最新index的指标数据 | ||||||
| | 可极大减少历史动态索引导致的大指标量级 | ||||||
| | 可与“indices_include”配置一起使用 | ||||||
|
|
||||||
| #### `dynamic_index_matcher_regexp` = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | ||||||
| | 与num_most_recent_indices 配合使用,用于指定动态索引的匹配逻辑,默认值: | ||||||
| | ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | ||||||
| | 支持匹配 //YYYY.MM.DD 或 YYYY-MM-DD 或 YYYYMMDD 或 YYYY-MM-DD-HH | ||||||
| | //YYYY.MM 或 YYYY-MM 或 YYYYMM 或YYYYMMDDHH | ||||||
| | //YY.MM.DD 或 YY-MM-DD 或 YYMMDD 或YYYY.MM.DD.HH | ||||||
|
||||||
| | //YY.MM.DD 或 YY-MM-DD 或 YYMMDD 或YYYY.MM.DD.HH | |
| | //YY.MM.DD 或 YY-MM-DD 或 YYMMDD 或YY.MM.DD.HH |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -477,3 +477,19 @@ ES 7.x supports RBACs. The following security privileges are required for the `e | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | elasticsearch_slm_stats_snapshots_deleted_total | counter | Snapshots deleted by policy | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | elasticsearch_slm_stats_snapshot_deletion_failures_total | counter | Snapshot deletion failures by policy | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | elasticsearch_slm_stats_operation_mode | gauge | SLM operation mode (Running, stopping, stopped) | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### `num_most_recent_indices = 0` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |Set the indicator data for the latest index of the first "num_mast_decent_indice" in the date class dynamic index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |It can greatly reduce the large scale of indicators caused by historical dynamic indexing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |Can be used together with the 'indices_inclub' configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### `dynamic_index_matcher_regexp` = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |Used in conjunction with num_mast_decent_indice to specify the matching logic for dynamic indexes, default value: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+483
to
+489
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |Set the indicator data for the latest index of the first "num_mast_decent_indice" in the date class dynamic index | |
| |It can greatly reduce the large scale of indicators caused by historical dynamic indexing | |
| |Can be used together with the 'indices_inclub' configuration | |
| #### `dynamic_index_matcher_regexp` = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | |
| |Used in conjunction with num_mast_decent_indice to specify the matching logic for dynamic indexes, default value: | |
| |Set the indicator data for the latest index of the first "num_most_recent_indices" in the date class dynamic index | |
| |It can greatly reduce the large scale of indicators caused by historical dynamic indexing | |
| |Can be used together with the 'indices_include' configuration | |
| #### `dynamic_index_matcher_regexp` = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | |
| |Used in conjunction with num_most_recent_indices to specify the matching logic for dynamic indexes, default value: |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spelling "num_mast_decent_indice" should be "num_most_recent_indices" for consistency with the actual configuration parameter name.
| |Set the indicator data for the latest index of the first "num_mast_decent_indice" in the date class dynamic index | |
| |It can greatly reduce the large scale of indicators caused by historical dynamic indexing | |
| |Can be used together with the 'indices_inclub' configuration | |
| #### `dynamic_index_matcher_regexp` = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | |
| |Used in conjunction with num_mast_decent_indice to specify the matching logic for dynamic indexes, default value: | |
| |Set the indicator data for the latest index of the first "num_most_recent_indices" in the date class dynamic index | |
| |It can greatly reduce the large scale of indicators caused by historical dynamic indexing | |
| |Can be used together with the 'indices_inclub' configuration | |
| #### `dynamic_index_matcher_regexp` = ["(?P<date>(?:\\d{4}|\\d{2})[.-]?(?:\\d{2})[.-]?(?:\\d{2})?[.-]?(?:\\d{2})?)$","[\\.-._]\\d+(\\.\\d+){0,2}$"] | |
| |Used in conjunction with num_most_recent_indices to specify the matching logic for dynamic indexes, default value: |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in this comment - "YYY.MM.DD.HH" should be "YY.MM.DD.HH" (with two Y's not three) to be consistent with the other date format patterns mentioned.
| |//YY.MM.DD or YY-MM-DD or YYMMDD or YYY.MM.DD.HH | |
| |//YY.MM.DD or YY-MM-DD or YYMMDD or YY.MM.DD.HH |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,16 +15,17 @@ package collector | |||||
|
|
||||||
| import ( | ||||||
| "encoding/json" | ||||||
| "flashcat.cloud/categraf/pkg/filter" | ||||||
| "fmt" | ||||||
| "io" | ||||||
| "log" | ||||||
| "net/http" | ||||||
| "net/url" | ||||||
| "path" | ||||||
| "sort" | ||||||
| "slices" | ||||||
| "strings" | ||||||
|
|
||||||
| "flashcat.cloud/categraf/pkg/filter" | ||||||
|
|
||||||
| "github.com/prometheus/client_golang/prometheus" | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -37,12 +38,13 @@ type ilmMetric struct { | |||||
|
|
||||||
| // Index Lifecycle Management information object | ||||||
| type IlmIndiciesCollector struct { | ||||||
| client *http.Client | ||||||
| url *url.URL | ||||||
| indicesIncluded []string | ||||||
| numMostRecentIndices int | ||||||
| indexMatchers map[string]filter.Filter | ||||||
| ilmMetric ilmMetric | ||||||
| client *http.Client | ||||||
| url *url.URL | ||||||
| indicesIncluded []string | ||||||
| numMostRecentIndices int | ||||||
| maxIndicesIncludeCount int | ||||||
| indexMatchers map[string]filter.Filter | ||||||
|
||||||
| indexMatchers map[string]filter.Filter |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional logic is redundant. The first condition checks len(i.indicesIncluded) == 0 || len(i.indicesIncluded) > i.maxIndicesIncludeCount, and the else-if checks len(i.indicesIncluded) <= i.maxIndicesIncludeCount. The else-if is unnecessary because it's the only remaining case. This should be simplified to use just an if-else structure.
| } else if len(i.indicesIncluded) <= i.maxIndicesIncludeCount { | |
| } else { |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filterMapByKeys function uses slices.Contains inside a loop which results in O(n*m) time complexity where n is the size of the response map and m is the size of the included slice. For better performance when filtering large datasets, consider converting the allowedKeys slice to a map for O(1) lookup time, reducing overall complexity to O(n).
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using slices.Contains in a loop over potentially large maps creates O(n*m) complexity, where n is the number of indices in the response and m is the number of included indices. For large datasets, this could be inefficient. Consider converting the allowedKeys slice to a map for O(1) lookup performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "must num_most_recent_indices Coordinated use" is grammatically incorrect and unclear. It should be reworded to something like "Must be used in coordination with num_most_recent_indices" or similar to improve clarity.