Skip to content

Commit

Permalink
Bug fix for OCP clustermetadata indexing (kube-burner#612)
Browse files Browse the repository at this point in the history
## Type of change

- [ ] Refactor
- [ ] New feature
- [x] Bug fix
- [ ] Optimization
- [ ] Documentation Update

## Description
Fixing leftover bug
through:kube-burner#602, which was
not publishing clusterMetadata due to nil value being populated in
indexer variable.

## Testing
Tested integrating with OCP wrapper. My own release verified in this PR:
https://github.com/kube-burner/kube-burner-ocp/pull/33/files

Signed-off-by: Vishnu Challa <[email protected]>
Co-authored-by: Vishnu Challa <[email protected]>
  • Loading branch information
vishnuchalla and Vishnu Challa authored Mar 25, 2024
1 parent 20073fa commit 686d837
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pkg/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func NewPrometheusClient(configSpec config.Spec, url string, auth Auth, step tim

// ScrapeJobsMetrics gets all prometheus metrics required and handles them
func (p *Prometheus) ScrapeJobsMetrics(jobList ...Job) error {
if len(p.indexers) == 0 {
log.Debug("Indexing not required for this run")
return nil
}
docsToIndex := make(map[string][]interface{})
start := jobList[0].Start
end := jobList[len(jobList)-1].End
Expand Down
12 changes: 7 additions & 5 deletions pkg/util/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ func ProcessMetricsScraperConfig(scraperConfig ScraperConfig) Scraper {
}
metadata := make(map[string]interface{})
for pos, indexer := range scraperConfig.ConfigSpec.Indexers {
log.Infof("📁 Creating indexer: %s", indexer.Type)
idx, err := indexers.NewIndexer(indexer.IndexerConfig)
if err != nil {
log.Fatalf("Error creating indexer %d: %v", pos, err.Error())
if indexer.Type != "" {
log.Infof("📁 Creating indexer: %s", indexer.Type)
idx, err := indexers.NewIndexer(indexer.IndexerConfig)
if err != nil {
log.Fatalf("Error creating indexer %d: %v", pos, err.Error())
}
indexerList = append(indexerList, *idx)
}
indexerList = append(indexerList, *idx)
}
if scraperConfig.UserMetaData != "" {
metadata, err = util.ReadUserMetadata(scraperConfig.UserMetaData)
Expand Down
7 changes: 3 additions & 4 deletions pkg/workloads/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const (
)

var ConfigSpec config.Spec
var indexer *indexers.Indexer

// NewWorkloadHelper initializes workloadHelper
func NewWorkloadHelper(config Config, embedConfig embed.FS, kubeClientProvider *config.KubeClientProvider) WorkloadHelper {
Expand Down Expand Up @@ -107,7 +106,7 @@ func (wh *WorkloadHelper) Run(workload string, metricsProfiles []string, alertsP
log.Error(err)
}
wh.Metadata.Passed = rc == 0
if indexer != nil {
for _, indexer := range metricsScraper.IndexerList {
IndexMetadata(indexer, wh.Metadata)
}
log.Info("👋 Exiting kube-burner ", wh.UUID)
Expand Down Expand Up @@ -141,10 +140,10 @@ func ExtractWorkload(embedConfig embed.FS, configDir string, workload string, ro
}

// IndexMetadata indexes metadata using given indexer.
func IndexMetadata(indexer *indexers.Indexer, metadata BenchmarkMetadata) {
func IndexMetadata(indexer indexers.Indexer, metadata BenchmarkMetadata) {
log.Info("Indexing cluster metadata document")
metadata.EndDate = time.Now().UTC()
msg, err := (*indexer).Index([]interface{}{metadata}, indexers.IndexingOpts{
msg, err := (indexer).Index([]interface{}{metadata}, indexers.IndexingOpts{
MetricName: metadata.MetricName,
})
if err != nil {
Expand Down

0 comments on commit 686d837

Please sign in to comment.