Skip to content

feat(topic): add retention size flag for topic create#563

Merged
rkpattnaik780 merged 4 commits intomainfrom
topic_bytes
Apr 13, 2021
Merged

feat(topic): add retention size flag for topic create#563
rkpattnaik780 merged 4 commits intomainfrom
topic_bytes

Conversation

@rkpattnaik780
Copy link
Contributor

Description

topic create should have a flag for setting the retention size.

fixes #523

Verification Steps

  1. Create topics using both normal and interactive mode.
  2. Normal mode should support a --retention-bytes flag.
  3. Interactive mode should prompt for retention size.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

❯ rhoas kafka topic list
  NAME (6)         PARTITIONS   RETENTION TIME (MS)   RETENTION SIZE (BYTES)  
 ---------------- ------------ --------------------- ------------------------        
  topic-4                 100   604800000             -2                      
  topic-5                   1   604800000             -2                    

I should not be able to enter -2 as a value.

This flag will also be needed in the update command.

// ValidateMessageRetentionPeriod validates the value (bytes) of the retention size
// the valid values can range from [-1,...]
func ValidateMessageRetentionSize(v interface{}) error {
retentionSizeStr := fmt.Sprintf("%v", v)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: fmt.Sprintf is slow in comparison to other string conversions methods.

https://gist.github.com/evalphobia/caee1602969a640a4530

}))
cmd.Flags().Int32Var(&opts.partitions, "partitions", 1, localizer.MustLocalizeFromID("kafka.topic.common.input.partitions.description"))
cmd.Flags().IntVar(&opts.retentionMs, "retention-ms", defaultRetentionPeriodMS, localizer.MustLocalizeFromID("kafka.topic.common.input.retentionMs.description"))
cmd.Flags().IntVar(&opts.retentionBytes, "retention-bytes", defaultRetentionSize, localizer.MustLocalizeFromID("kafka.topic.common.input.retentionBytes.description"))
Copy link
Contributor

Choose a reason for hiding this comment

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

The flag value is not being validated anywhere, I can submit invalid values

return nil
}

// ValidateMessageRetentionPeriod validates the value (bytes) of the retention size
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ValidateMessageRetentionPeriod validates the value (bytes) of the retention size
// ValidateMessageRetentionSize validates the value (bytes) of the retention size

@rkpattnaik780
Copy link
Contributor Author

❯ rhoas kafka topic list
  NAME (6)         PARTITIONS   RETENTION TIME (MS)   RETENTION SIZE (BYTES)  
 ---------------- ------------ --------------------- ------------------------        
  topic-4                 100   604800000             -2                      
  topic-5                   1   604800000             -2                    

I should not be able to enter -2 as a value.

This flag will also be needed in the update command.

was thinking to add this to update command in a separate PR.

@craicoverflow
Copy link
Contributor

Okay.

@rkpattnaik780 rkpattnaik780 changed the title feat(topic create): add flag for retention size feat(topic): add flag for retention size Apr 13, 2021
@craicoverflow craicoverflow self-requested a review April 13, 2021 13:34
@craicoverflow craicoverflow changed the title feat(topic): add flag for retention size feat(topic): add retention size flag for topic create Apr 13, 2021
@rkpattnaik780 rkpattnaik780 merged commit 30eb221 into main Apr 13, 2021
@rkpattnaik780 rkpattnaik780 deleted the topic_bytes branch April 13, 2021 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add retention size flag to create topic command

2 participants