Skip to content

Commit 282bb07

Browse files
author
anton.voskresensky
committed
set default systems indices config
1 parent cbaed4d commit 282bb07

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

commands/snapshot-manual.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func runSnapshotManual(cmd *cobra.Command, args []string) error {
3131
kind := cfg.GetSnapshotManualKind()
3232
value := cfg.GetSnapshotManualValue()
3333
name := cfg.GetSnapshotManualName()
34-
system := cfg.GetSnapshotManualSystem()
34+
systemFlag := cfg.GetSnapshotManualSystem()
3535

3636
if value == "" {
3737
return fmt.Errorf("value is required")
@@ -41,7 +41,20 @@ func runSnapshotManual(cmd *cobra.Command, args []string) error {
4141
return fmt.Errorf("name is required for regex patterns")
4242
}
4343

44-
logger.Info(fmt.Sprintf("Starting manual snapshot creation kind=%s value=%s name=%s system=%t", kind, value, name, system))
44+
tempConfig := config.IndexConfig{
45+
Kind: kind,
46+
Value: value,
47+
Name: name,
48+
System: systemFlag,
49+
}
50+
51+
system := systemFlag
52+
systemStr := cfg.SnapshotManualSystem
53+
if systemStr == "" {
54+
system = utils.IsSystem(tempConfig, value)
55+
}
56+
57+
logger.Info(fmt.Sprintf("Starting manual snapshot creation kind=%s value=%s name=%s system=%t (auto-detected=%t)", kind, value, name, system, cfg.SnapshotManualSystem == ""))
4558

4659
client, err := utils.NewOSClientWithURL(cfg, cfg.GetOpenSearchURL())
4760
if err != nil {

commands/snapshots.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func runSnapshot(cmd *cobra.Command, args []string) error {
6363
regularConfigs := make([]config.IndexConfig, 0)
6464

6565
for _, indexConfig := range indicesConfig {
66-
if indexConfig.System {
66+
if utils.IsSystem(indexConfig, indexConfig.Value) {
6767
systemConfigs = append(systemConfigs, indexConfig)
6868
} else {
6969
regularConfigs = append(regularConfigs, indexConfig)

example/config-example/osctlindicesconfig.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ indices:
99
- kind: prefix
1010
value: infra-elklogs
1111
days_count: 30
12-
snapshot: false
1312
- kind: prefix
1413
value: d8-ingress
1514
days_count: 7
1615
snapshot: true
1716
snapshot_count_s3: 7
1817
- kind: prefix
1918
value: .kibana
20-
system: true
2119
days_count: 30
2220
snapshot: true
2321
- kind: prefix

example/helm-example/values.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,30 @@ osctl:
8888
# indices:
8989
# - kind: prefix
9090
# value: filebeat
91-
# system: false
9291
# days_count: 5
9392
# snapshot: true
9493
# - kind: prefix
9594
# value: d8
96-
# system: false
9795
# days_count: 7
9896
# snapshot: true
9997
# snapshot_count_s3: 7
10098
# - kind: prefix
10199
# value: eventrouter
102-
# system: false
103100
# days_count: 7
104-
# snapshot: false
105101
# - kind: prefix
106102
# value: mongo
107-
# system: false
108103
# days_count: 5
109104
# snapshot: true
110105
# - kind: prefix
111106
# value: infra
112-
# system: false
113107
# days_count: 5
114108
# snapshot: true
115109
# - kind: prefix
116110
# value: opp-fix
117-
# system: false
118111
# days_count: 5
119112
# snapshot: true
120113
# - kind: prefix
121114
# value: pim
122-
# system: false
123115
# days_count: 5
124116
# snapshot: true
125117
# - kind: prefix

pkg/config/osctlindicesconfig.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func ValidateOsctlIndicesConfig(config *OsctlIndicesConfig, dateFormat string) e
106106
if indexConfig.Name == "" {
107107
return fmt.Errorf("index config #%d: regex pattern '%s' must have 'name' field specified", i+1, indexConfig.Value)
108108
}
109+
if indexConfig.System {
110+
return fmt.Errorf("index config #%d: regex pattern '%s' cannot have system: true (regex patterns cannot be system indices)", i+1, indexConfig.Value)
111+
}
109112
}
110113
}
111114
return nil

pkg/utils/indices.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,38 @@ func IndexInfosToNames(list []opensearch.IndexInfo) []string {
1717
return names
1818
}
1919

20-
func MatchesIndex(indexName string, indexConfig config.IndexConfig) bool {
20+
func IsSystem(indexConfig config.IndexConfig, nameOrPattern string) bool {
21+
if indexConfig.Kind == "regex" {
22+
return false
23+
}
24+
25+
if indexConfig.System {
26+
return true
27+
}
28+
29+
if indexConfig.Kind == "prefix" && strings.HasPrefix(nameOrPattern, ".") {
30+
return true
31+
}
32+
33+
return false
34+
}
2135

36+
func MatchesIndex(indexName string, indexConfig config.IndexConfig) bool {
2237
if !indexConfig.System && ShouldSkipIndex(indexName) {
2338
return false
2439
}
2540

41+
isSystemIndex := IsSystem(indexConfig, indexName)
42+
isSystemConfig := IsSystem(indexConfig, indexConfig.Value)
43+
44+
if isSystemConfig && !isSystemIndex {
45+
return false
46+
}
47+
48+
if !isSystemConfig && isSystemIndex {
49+
return false
50+
}
51+
2652
switch indexConfig.Kind {
2753
case "prefix":
2854
return strings.HasPrefix(indexName, indexConfig.Value)

0 commit comments

Comments
 (0)