Skip to content
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

[Feature] Add elastic client #10

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

GROwen
Copy link
Contributor

@GROwen GROwen commented Feb 19, 2024

Motivation

Need to clean-up stale indices on the Elastic Cloud development deployment.

Changes

  1. Adds the elastic-cloud command and delete-stale sub-command

@GROwen GROwen self-assigned this Feb 19, 2024
for k, i := range list {
if strings.Contains(k, "elasticsearch_index") {
now := time.Now().UnixMilli()
created, err := strconv.ParseInt(i.IndexItem.IndexDetail.CreationDate, 10, 64)
Copy link
Contributor Author

@GROwen GROwen Feb 19, 2024

Choose a reason for hiding this comment

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

Using the creation date is a very rudimentary way of identifying stale indices because it does not identify the last time an index was updated.

I believe it may be possible to use data from the shards API to determine how 'fresh' an index is based on refresh, write or read metrics.

However because content is ephemeral and these are development indices we don't need to be too concerned about destructive requests.

@GROwen GROwen marked this pull request as ready for review February 20, 2024 00:12
README.md Outdated
> Variables are deployment specific - make sure the deployment you are targeting is not a production deployment.

* EC_API_KEY - Generated from the deployments Kibana settings
* EC_CLOUD_ID - Found on the deployments Elastic Cloud 'manage' page
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be better as a flag or argument instead of an envvar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because they're creds I thought it safer to keep them stored as env vars but I suppose we could set them as env vars and reference them in the argument. Am I being too cautious in not allowing a user to expose those vars directly in an arg on the cli (and therefore making it available in their shell history)?

main.go Outdated
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "force",
Usage: "Execute any mutations",
Copy link
Contributor

@nicksantamaria nicksantamaria Feb 20, 2024

Choose a reason for hiding this comment

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

Usage text should probably be more like skips all confirmation prompts and immediately executes mutations.

@GROwen
Copy link
Contributor Author

GROwen commented Feb 21, 2024

@nicksantamaria I've refactored the inputs so the API_KEY is now an env var and Cloud ID a flag. I've also added the age of the indices to target as flag.

Ready for review again.

@nicksantamaria
Copy link
Contributor

@GROwen see #11

Suggested changes for feature/add-elastic-client
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.

2 participants