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

default tar filename has extra dash in custom metric mode #31

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Filename has extra dash in custom metric mode
Changes were made as per feedback
karishma.lalani committed Oct 7, 2024
commit aa8dd4842faf5e2cc5599c954ed3fa0ebdb4d7c6
51 changes: 25 additions & 26 deletions promdump/promdump.go
Original file line number Diff line number Diff line change
@@ -646,39 +646,30 @@ func addToArchive(tw *tar.Writer, filename string) error {
}

func generateDefaultTarFilename() string {
var prefix string

// Define a regular expression to match the node_prefix key-value pair in the metric string
re := regexp.MustCompile(`node_prefix="([^"]+)"`)
var filename string

// Try to extract node_prefix from the metric
if *metric != "" {
matches := re.FindStringSubmatch(*metric)
if len(matches) > 1 {
prefix = matches[1] // Use the captured node_prefix value
}
}
// Start with the default prefix "promdump"
filename = "promdump"

// If node_prefix is not found in metric, use nodePrefix flag
if prefix == "" && *nodePrefix != "" {
prefix = *nodePrefix
}
// Check if nodePrefix is provided and append it to the filename if not empty
if nodePrefix != nil && *nodePrefix != "" {

Choose a reason for hiding this comment

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

The nodePrefix != nil portion of this conditional is spurious. This condition will always be true since it's a pointer to a (possibly nil) string. Simplify this to if *nodePrefix != "" {.

filename = fmt.Sprintf("%s-%s", filename, *nodePrefix)

// If neither is available, use a default prefix
if prefix == "" {
return fmt.Sprintf("promdump-%s.tar", time.Now().Format("20060102-150405"))
}

// Generate the filename based on the compression type
switch *tarCompression {
case "gzip":
return fmt.Sprintf("promdump-%s-%s.tar.gz", prefix, time.Now().Format("20060102-150405"))
case "bzip2":
return fmt.Sprintf("promdump-%s-%s.tar.bz2", prefix, time.Now().Format("20060102-150405"))
default:
return fmt.Sprintf("promdump-%s-%s.tar", prefix, time.Now().Format("20060102-150405"))
// Append the timestamp
filename = fmt.Sprintf("%s-%s", filename, time.Now().Format("20060102-150405"))
if tarCompression != nil {
switch *tarCompression {
case "gzip":
return filename + ".tar.gz"
case "bzip2":
return filename + ".tar.bz2"
}
}

// Default to ".tar" if no compression type is specified
return filename + ".tar"
}

func getBatch(ctx context.Context, promApi v1.API, metric string, beginTS time.Time, endTS time.Time, periodDur time.Duration, batchDur time.Duration) ([]*model.SampleStream, error) {
@@ -1427,6 +1418,14 @@ func main() {
}
}
}
if *out != "" {

_, err := cleanFiles(*out, customMetricCount, false)
if err != nil {
log.Printf("Error cleaning files : %v", err)
}

}
Comment on lines +1424 to +1431

Choose a reason for hiding this comment

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

Please keep changes to one issue per PR.

} else {
logger.Println("main: preserving metric export files because the --keep_files flag is set")
}