Skip to content

Commit 519ff8d

Browse files
author
anton.voskresensky
committed
fix logs
1 parent 9446de0 commit 519ff8d

File tree

9 files changed

+185
-165
lines changed

9 files changed

+185
-165
lines changed

commands/coldstorage.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,33 @@ func runColdStorage(cmd *cobra.Command, args []string) error {
115115
successfulMigrations = append(successfulMigrations, index)
116116
}
117117

118-
fmt.Println("\n" + strings.Repeat("=", 60))
119-
fmt.Println("COLD STORAGE MIGRATION SUMMARY")
120-
fmt.Println(strings.Repeat("=", 60))
121-
if len(successfulMigrations) > 0 {
122-
fmt.Printf("Successfully migrated to cold: %d indices\n", len(successfulMigrations))
123-
for _, name := range successfulMigrations {
124-
fmt.Printf(" ✓ %s\n", name)
118+
if !dryRun {
119+
fmt.Println("\n" + strings.Repeat("=", 60))
120+
fmt.Println("COLD STORAGE MIGRATION SUMMARY")
121+
fmt.Println(strings.Repeat("=", 60))
122+
if len(successfulMigrations) > 0 {
123+
fmt.Printf("Successfully migrated to cold: %d indices\n", len(successfulMigrations))
124+
for _, name := range successfulMigrations {
125+
fmt.Printf(" ✓ %s\n", name)
126+
}
125127
}
126-
}
127-
if len(failedMigrations) > 0 {
128-
fmt.Printf("\nFailed to migrate: %d indices\n", len(failedMigrations))
129-
for _, name := range failedMigrations {
130-
fmt.Printf(" ✗ %s\n", name)
128+
if len(failedMigrations) > 0 {
129+
fmt.Printf("\nFailed to migrate: %d indices\n", len(failedMigrations))
130+
for _, name := range failedMigrations {
131+
fmt.Printf(" ✗ %s\n", name)
132+
}
131133
}
132-
}
133-
if len(alreadyCold) > 0 {
134-
fmt.Printf("\nAlready in cold: %d indices\n", len(alreadyCold))
135-
for _, name := range alreadyCold {
136-
fmt.Printf(" - %s\n", name)
134+
if len(alreadyCold) > 0 {
135+
fmt.Printf("\nAlready in cold: %d indices\n", len(alreadyCold))
136+
for _, name := range alreadyCold {
137+
fmt.Printf(" - %s\n", name)
138+
}
137139
}
140+
if len(successfulMigrations) == 0 && len(failedMigrations) == 0 && len(alreadyCold) == 0 {
141+
fmt.Println("No indices were migrated to cold storage")
142+
}
143+
fmt.Println(strings.Repeat("=", 60))
138144
}
139-
if len(successfulMigrations) == 0 && len(failedMigrations) == 0 && len(alreadyCold) == 0 {
140-
fmt.Println("No indices were migrated to cold storage")
141-
}
142-
fmt.Println(strings.Repeat("=", 60))
143145

144146
logger.Info(fmt.Sprintf("Cold storage migration completed processed=%d skipped_already_cold=%d", len(coldIndices), len(alreadyCold)))
145147
return nil

commands/datasource.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,27 @@ func runDataSource(cmd *cobra.Command, args []string) error {
175175
}
176176
}
177177

178-
fmt.Println("\n" + strings.Repeat("=", 60))
179-
fmt.Println("DATA SOURCE SUMMARY")
180-
fmt.Println(strings.Repeat("=", 60))
181-
if len(createdDataSources) > 0 {
182-
fmt.Printf("Created: %d data sources\n", len(createdDataSources))
183-
for _, name := range createdDataSources {
184-
fmt.Printf(" ✓ %s\n", name)
178+
if !dryRun {
179+
fmt.Println("\n" + strings.Repeat("=", 60))
180+
fmt.Println("DATA SOURCE SUMMARY")
181+
fmt.Println(strings.Repeat("=", 60))
182+
if len(createdDataSources) > 0 {
183+
fmt.Printf("Created: %d data sources\n", len(createdDataSources))
184+
for _, name := range createdDataSources {
185+
fmt.Printf(" ✓ %s\n", name)
186+
}
185187
}
186-
}
187-
if len(existingDataSources) > 0 {
188-
fmt.Printf("\nAlready exists: %d data sources\n", len(existingDataSources))
189-
for _, name := range existingDataSources {
190-
fmt.Printf(" - %s\n", name)
188+
if len(existingDataSources) > 0 {
189+
fmt.Printf("\nAlready exists: %d data sources\n", len(existingDataSources))
190+
for _, name := range existingDataSources {
191+
fmt.Printf(" - %s\n", name)
192+
}
191193
}
194+
if len(createdDataSources) == 0 && len(existingDataSources) == 0 {
195+
fmt.Println("No data sources were added")
196+
}
197+
fmt.Println(strings.Repeat("=", 60))
192198
}
193-
if len(createdDataSources) == 0 && len(existingDataSources) == 0 {
194-
fmt.Println("No data sources were added")
195-
}
196-
fmt.Println(strings.Repeat("=", 60))
197199

198200
return nil
199201
}

commands/dereplicator.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,33 @@ func runDereplicator(cmd *cobra.Command, args []string) error {
104104
}
105105
}
106106

107-
fmt.Println("\n" + strings.Repeat("=", 60))
108-
fmt.Println("DEREPLICATOR SUMMARY")
109-
fmt.Println(strings.Repeat("=", 60))
110-
if len(successfulDereplications) > 0 {
111-
fmt.Printf("Successfully dereplicated: %d indices\n", len(successfulDereplications))
112-
for _, name := range successfulDereplications {
113-
fmt.Printf(" ✓ %s\n", name)
107+
if !dryRun {
108+
fmt.Println("\n" + strings.Repeat("=", 60))
109+
fmt.Println("DEREPLICATOR SUMMARY")
110+
fmt.Println(strings.Repeat("=", 60))
111+
if len(successfulDereplications) > 0 {
112+
fmt.Printf("Successfully dereplicated: %d indices\n", len(successfulDereplications))
113+
for _, name := range successfulDereplications {
114+
fmt.Printf(" ✓ %s\n", name)
115+
}
114116
}
115-
}
116-
if len(problemIndices) > 0 {
117-
fmt.Printf("\nFailed to dereplicate: %d indices\n", len(problemIndices))
118-
for _, name := range problemIndices {
119-
fmt.Printf(" ✗ %s\n", name)
117+
if len(problemIndices) > 0 {
118+
fmt.Printf("\nFailed to dereplicate: %d indices\n", len(problemIndices))
119+
for _, name := range problemIndices {
120+
fmt.Printf(" ✗ %s\n", name)
121+
}
120122
}
121-
}
122-
if len(skippedNoSnapshot) > 0 {
123-
fmt.Printf("\nSkipped (no valid snapshot): %d indices\n", len(skippedNoSnapshot))
124-
for _, name := range skippedNoSnapshot {
125-
fmt.Printf(" - %s\n", name)
123+
if len(skippedNoSnapshot) > 0 {
124+
fmt.Printf("\nSkipped (no valid snapshot): %d indices\n", len(skippedNoSnapshot))
125+
for _, name := range skippedNoSnapshot {
126+
fmt.Printf(" - %s\n", name)
127+
}
126128
}
129+
if len(successfulDereplications) == 0 && len(problemIndices) == 0 && len(skippedNoSnapshot) == 0 {
130+
fmt.Println("No indices were dereplicated")
131+
}
132+
fmt.Println(strings.Repeat("=", 60))
127133
}
128-
if len(successfulDereplications) == 0 && len(problemIndices) == 0 && len(skippedNoSnapshot) == 0 {
129-
fmt.Println("No indices were dereplicated")
130-
}
131-
fmt.Println(strings.Repeat("=", 60))
132134

133135
if len(skippedNoSnapshot) > 0 {
134136
logger.Warn(fmt.Sprintf("Skipped (no valid snapshot) %s", strings.Join(skippedNoSnapshot, ", ")))

commands/indexpatterns.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,20 @@ func runIndexPatterns(cmd *cobra.Command, args []string) error {
122122
}
123123
}
124124

125-
fmt.Println("\n" + strings.Repeat("=", 60))
126-
fmt.Println("INDEX PATTERNS SUMMARY")
127-
fmt.Println(strings.Repeat("=", 60))
128-
if len(createdPatterns) > 0 {
129-
fmt.Printf("Created: %d index patterns\n", len(createdPatterns))
130-
for _, name := range createdPatterns {
131-
fmt.Printf(" ✓ %s\n", name)
125+
if !dryRun {
126+
fmt.Println("\n" + strings.Repeat("=", 60))
127+
fmt.Println("INDEX PATTERNS SUMMARY")
128+
fmt.Println(strings.Repeat("=", 60))
129+
if len(createdPatterns) > 0 {
130+
fmt.Printf("Created: %d index patterns\n", len(createdPatterns))
131+
for _, name := range createdPatterns {
132+
fmt.Printf(" ✓ %s\n", name)
133+
}
134+
} else {
135+
fmt.Println("No index patterns were added")
132136
}
133-
} else {
134-
fmt.Println("No index patterns were added")
137+
fmt.Println(strings.Repeat("=", 60))
135138
}
136-
fmt.Println(strings.Repeat("=", 60))
137139
return nil
138140
}
139141

@@ -238,18 +240,20 @@ func runIndexPatterns(cmd *cobra.Command, args []string) error {
238240
}
239241
}
240242

241-
fmt.Println("\n" + strings.Repeat("=", 60))
242-
fmt.Println("INDEX PATTERNS SUMMARY")
243-
fmt.Println(strings.Repeat("=", 60))
244-
if len(createdPatterns) > 0 {
245-
fmt.Printf("Created: %d index patterns\n", len(createdPatterns))
246-
for _, name := range createdPatterns {
247-
fmt.Printf(" ✓ %s\n", name)
243+
if !dryRun {
244+
fmt.Println("\n" + strings.Repeat("=", 60))
245+
fmt.Println("INDEX PATTERNS SUMMARY")
246+
fmt.Println(strings.Repeat("=", 60))
247+
if len(createdPatterns) > 0 {
248+
fmt.Printf("Created: %d index patterns\n", len(createdPatterns))
249+
for _, name := range createdPatterns {
250+
fmt.Printf(" ✓ %s\n", name)
251+
}
252+
} else {
253+
fmt.Println("No index patterns were added")
248254
}
249-
} else {
250-
fmt.Println("No index patterns were added")
255+
fmt.Println(strings.Repeat("=", 60))
251256
}
252-
fmt.Println(strings.Repeat("=", 60))
253257

254258
return nil
255259
}

commands/indicesdelete.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,27 @@ func runIndicesDelete(cmd *cobra.Command, args []string) error {
111111
logger.Info("No indices for deletion")
112112
}
113113

114-
fmt.Println("\n" + strings.Repeat("=", 60))
115-
fmt.Println("INDICES DELETION SUMMARY")
116-
fmt.Println(strings.Repeat("=", 60))
117-
if len(successfulDeletions) > 0 {
118-
fmt.Printf("Successfully deleted: %d indices\n", len(successfulDeletions))
119-
for _, name := range successfulDeletions {
120-
fmt.Printf(" ✓ %s\n", name)
114+
if !cfg.GetDryRun() {
115+
fmt.Println("\n" + strings.Repeat("=", 60))
116+
fmt.Println("INDICES DELETION SUMMARY")
117+
fmt.Println(strings.Repeat("=", 60))
118+
if len(successfulDeletions) > 0 {
119+
fmt.Printf("Successfully deleted: %d indices\n", len(successfulDeletions))
120+
for _, name := range successfulDeletions {
121+
fmt.Printf(" ✓ %s\n", name)
122+
}
121123
}
122-
}
123-
if len(failedDeletions) > 0 {
124-
fmt.Printf("\nFailed to delete: %d indices\n", len(failedDeletions))
125-
for _, name := range failedDeletions {
126-
fmt.Printf(" ✗ %s\n", name)
124+
if len(failedDeletions) > 0 {
125+
fmt.Printf("\nFailed to delete: %d indices\n", len(failedDeletions))
126+
for _, name := range failedDeletions {
127+
fmt.Printf(" ✗ %s\n", name)
128+
}
127129
}
130+
if len(successfulDeletions) == 0 && len(failedDeletions) == 0 {
131+
fmt.Println("No indices were deleted")
132+
}
133+
fmt.Println(strings.Repeat("=", 60))
128134
}
129-
if len(successfulDeletions) == 0 && len(failedDeletions) == 0 {
130-
fmt.Println("No indices were deleted")
131-
}
132-
fmt.Println(strings.Repeat("=", 60))
133135

134136
logger.Info("Indices deletion completed")
135137
return nil

commands/retention.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,26 +145,28 @@ func runRetention(cmd *cobra.Command, args []string) error {
145145
}
146146
}
147147

148-
fmt.Println("\n" + strings.Repeat("=", 60))
149-
fmt.Println("RETENTION SUMMARY")
150-
fmt.Println(strings.Repeat("=", 60))
151-
fmt.Printf("Final disk utilization: %d%%\n", avgUtil)
152-
if len(successfulDeletions) > 0 {
153-
fmt.Printf("\nSuccessfully deleted: %d indices\n", len(successfulDeletions))
154-
for _, name := range successfulDeletions {
155-
fmt.Printf(" ✓ %s\n", name)
148+
if !dryRun {
149+
fmt.Println("\n" + strings.Repeat("=", 60))
150+
fmt.Println("RETENTION SUMMARY")
151+
fmt.Println(strings.Repeat("=", 60))
152+
fmt.Printf("Final disk utilization: %d%%\n", avgUtil)
153+
if len(successfulDeletions) > 0 {
154+
fmt.Printf("\nSuccessfully deleted: %d indices\n", len(successfulDeletions))
155+
for _, name := range successfulDeletions {
156+
fmt.Printf(" ✓ %s\n", name)
157+
}
156158
}
157-
}
158-
if len(failedDeletions) > 0 {
159-
fmt.Printf("\nFailed to delete: %d indices\n", len(failedDeletions))
160-
for _, name := range failedDeletions {
161-
fmt.Printf(" ✗ %s\n", name)
159+
if len(failedDeletions) > 0 {
160+
fmt.Printf("\nFailed to delete: %d indices\n", len(failedDeletions))
161+
for _, name := range failedDeletions {
162+
fmt.Printf(" ✗ %s\n", name)
163+
}
162164
}
165+
if len(successfulDeletions) == 0 && len(failedDeletions) == 0 {
166+
fmt.Println("No indices were deleted")
167+
}
168+
fmt.Println(strings.Repeat("=", 60))
163169
}
164-
if len(successfulDeletions) == 0 && len(failedDeletions) == 0 {
165-
fmt.Println("No indices were deleted")
166-
}
167-
fmt.Println(strings.Repeat("=", 60))
168170

169171
logger.Info(fmt.Sprintf("Retention completed finalUtilization=%d", avgUtil))
170172
return nil

commands/sharding.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -350,33 +350,35 @@ func runSharding(cmd *cobra.Command, args []string) error {
350350
return nil
351351
}
352352

353-
fmt.Println("\n" + strings.Repeat("=", 60))
354-
fmt.Println("SHARDING SUMMARY")
355-
fmt.Println(strings.Repeat("=", 60))
356-
if len(successfulChanges) > 0 {
357-
fmt.Printf("Successfully changed: %d templates\n", len(successfulChanges))
358-
for _, ch := range successfulChanges {
359-
if ch.action == "create" {
360-
fmt.Printf(" ✓ Created: %s (pattern=%s, shards=%d, replicas=%d)\n", ch.template, ch.pattern, ch.shards, ch.replicas)
361-
} else {
362-
fmt.Printf(" ✓ Updated: %s (pattern=%s, shards %d→%d)\n", ch.template, ch.pattern, ch.oldShards, ch.shards)
353+
if !dryRun {
354+
fmt.Println("\n" + strings.Repeat("=", 60))
355+
fmt.Println("SHARDING SUMMARY")
356+
fmt.Println(strings.Repeat("=", 60))
357+
if len(successfulChanges) > 0 {
358+
fmt.Printf("Successfully changed: %d templates\n", len(successfulChanges))
359+
for _, ch := range successfulChanges {
360+
if ch.action == "create" {
361+
fmt.Printf(" ✓ Created: %s (pattern=%s, shards=%d, replicas=%d)\n", ch.template, ch.pattern, ch.shards, ch.replicas)
362+
} else {
363+
fmt.Printf(" ✓ Updated: %s (pattern=%s, shards %d→%d)\n", ch.template, ch.pattern, ch.oldShards, ch.shards)
364+
}
363365
}
364366
}
365-
}
366-
if len(failedChanges) > 0 {
367-
fmt.Printf("\nFailed to change: %d templates\n", len(failedChanges))
368-
for _, ch := range failedChanges {
369-
if ch.action == "create" {
370-
fmt.Printf(" ✗ Failed to create: %s (pattern=%s)\n", ch.template, ch.pattern)
371-
} else {
372-
fmt.Printf(" ✗ Failed to update: %s (pattern=%s)\n", ch.template, ch.pattern)
367+
if len(failedChanges) > 0 {
368+
fmt.Printf("\nFailed to change: %d templates\n", len(failedChanges))
369+
for _, ch := range failedChanges {
370+
if ch.action == "create" {
371+
fmt.Printf(" ✗ Failed to create: %s (pattern=%s)\n", ch.template, ch.pattern)
372+
} else {
373+
fmt.Printf(" ✗ Failed to update: %s (pattern=%s)\n", ch.template, ch.pattern)
374+
}
373375
}
374376
}
377+
if len(successfulChanges) == 0 && len(failedChanges) == 0 {
378+
fmt.Println("No templates were changed")
379+
}
380+
fmt.Println(strings.Repeat("=", 60))
375381
}
376-
if len(successfulChanges) == 0 && len(failedChanges) == 0 {
377-
fmt.Println("No templates were changed")
378-
}
379-
fmt.Println(strings.Repeat("=", 60))
380382

381383
return nil
382384
}

0 commit comments

Comments
 (0)