Skip to content

Commit

Permalink
[GCP] [Billing] Log an error message when the metricset finds no tabl…
Browse files Browse the repository at this point in the history
…es (#36775)

* Log an error message when we find no tables

Not finding any table is an error state for this metricset. It can
happen because the user made a mistake in the configuration file or
the service account lacks the needed permissions.

Regardless of the origin, it's a condition that we should report to the
user and give hints for troubleshooting.
  • Loading branch information
zmoog authored Nov 2, 2023
1 parent 3acd591 commit 9ad141b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions x-pack/metricbeat/module/gcp/billing/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) (err erro
return fmt.Errorf("getTables failed: %w", err)
}

// Not finding any table is an error state for this metricset.
//
// It can happen because the user made a mistake in the configuration
// file or the service account lacks the needed permissions (the API
// does not report any error if the Service Account lacks the required
// permission).
//
// Regardless of the origin, it's a condition that we should
// report to the user and give hints for troubleshooting.
if len(tableMetas) == 0 {
m.logger.Errorf("no tables found in dataset %s with pattern %s; check your settings and see if the service account has permission to list datasets", m.config.DatasetID, m.config.TablePattern)
return nil
}

var events []mb.Event
for _, tableMeta := range tableMetas {
eventsPerQuery, err := m.queryBigQuery(ctx, client, tableMeta, month, m.config.CostType)
Expand All @@ -158,6 +172,7 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) (err erro
for _, event := range events {
reporter.Event(event)
}

return nil
}

Expand Down Expand Up @@ -213,6 +228,7 @@ func getTables(ctx context.Context, client *bigquery.Client, datasetID string, t
}
}
}

return tables, nil
}

Expand Down

0 comments on commit 9ad141b

Please sign in to comment.