Skip to content

Commit

Permalink
ref: batch size percent CLI configuration
Browse files Browse the repository at this point in the history
this makes the loadCert batch size configuration via the
`--batch-size-percent` variable with a default value of 1%. I found that
to be pretty good on my large Vault installation
  • Loading branch information
wbollock committed Aug 24, 2023
1 parent 5949f86 commit 85eb9dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"time"

log "github.com/aarnaud/vault-pki-exporter/pkg/logger"
"github.com/aarnaud/vault-pki-exporter/pkg/vault"
vaultMon "github.com/aarnaud/vault-pki-exporter/pkg/vault-mon"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"time"
)

var version string
Expand Down Expand Up @@ -60,6 +61,11 @@ func init() {
if err := viper.BindPFlag("refresh_interval", flags.Lookup("refresh-interval")); err != nil {
log.Fatal(err)
}

flags.Float64("batch-size-percent", 1, "loadCerts batch size percentage")
if err := viper.BindPFlag("batch_size_percent", flags.Lookup("batch-size-percent")); err != nil {
log.Fatal(err)
}
}

func main() {
Expand Down
8 changes: 5 additions & 3 deletions pkg/vault-mon/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ func (pki *PKI) loadCerts(loadCertsDuration prometheus.Histogram) error {
// reset expired certs to avoid counter creep
pki.expiredCertsCounter = 0

// Determine batch size based on the length of serialsList.Keys.
// todo make batch size CLI configurable
batchSize := len(serialsList.Keys) / 20 // 5% of the total certificates in each batch
// determine batch size dynamically based on the length of serialsList.Keys
batchSizePercentage := viper.GetFloat64("batch_size_percent")

// Calculate the batch size using floating-point division, then round to the nearest integer
batchSize := int(float64(len(serialsList.Keys)) * (batchSizePercentage / 100.0))
if batchSize < 1 {
batchSize = 1
}
Expand Down

0 comments on commit 85eb9dc

Please sign in to comment.