(ctx *globalOptions)
| 196 | } |
| 197 | |
| 198 | func (cmd *analyseBlockCmd) Run(ctx *globalOptions) error { |
| 199 | blobBytes, err := humanize.ParseBytes(cmd.BlobThreshold) |
| 200 | if err != nil { |
| 201 | return err |
| 202 | } |
| 203 | |
| 204 | r, _, _, err := loadBackend(&cmd.backendOptions, ctx) |
| 205 | if err != nil { |
| 206 | return err |
| 207 | } |
| 208 | |
| 209 | blockSum, err := processBlock(r, cmd.TenantID, cmd.BlockID, cmd.IncludeWellKnown, time.Time{}, time.Time{}, 0) |
| 210 | if err != nil { |
| 211 | if errors.Is(err, backend.ErrDoesNotExist) { |
| 212 | return fmt.Errorf("unable to analyze block: block has no block.meta because it was compacted") |
| 213 | } |
| 214 | return err |
| 215 | } |
| 216 | |
| 217 | if blockSum == nil { |
| 218 | return errors.New("failed to process block") |
| 219 | } |
| 220 | |
| 221 | if cmd.NumIntAttr == 0 { |
| 222 | cmd.NumIntAttr = cmd.NumAttr |
| 223 | } |
| 224 | |
| 225 | if cmd.IntPercentThreshold <= 0 || cmd.IntPercentThreshold >= 1 { |
| 226 | return errors.New("int percent threshold must be between 0 and 1") |
| 227 | } |
| 228 | |
| 229 | if cmd.StrPercentThreshold <= 0 || cmd.StrPercentThreshold >= 1 { |
| 230 | return errors.New("str percent threshold must be between 0 and 1") |
| 231 | } |
| 232 | |
| 233 | settings := heuristicSettings{ |
| 234 | NumStringAttr: cmd.NumAttr, |
| 235 | NumIntAttr: cmd.NumIntAttr, |
| 236 | BlobThresholdBytes: blobBytes, |
| 237 | IntThresholdPercent: cmd.IntPercentThreshold, |
| 238 | StrThresholdPercent: cmd.StrPercentThreshold, |
| 239 | } |
| 240 | |
| 241 | printSettings := printSettings{ |
| 242 | Simple: cmd.SimpleSummary, |
| 243 | Full: cmd.PrintFullSummary, |
| 244 | Jsonnet: cmd.GenerateJsonnet, |
| 245 | CliArgs: cmd.GenerateCliArgs, |
| 246 | } |
| 247 | |
| 248 | return blockSum.print(settings, printSettings) |
| 249 | } |
| 250 | |
| 251 | func processBlock(r backend.Reader, tenantID, blockID string, includeWellKnown bool, maxStartTime, minStartTime time.Time, minCompactionLvl uint32) (*blockSummary, error) { |
| 252 | id := uuid.MustParse(blockID) |
nothing calls this directly
no test coverage detected