Skip to content

Commit

Permalink
make the configured list of AZs available to QuotaPlugin.Scrape()
Browse files Browse the repository at this point in the history
  • Loading branch information
majewsky committed Nov 7, 2023
1 parent 6a31bdd commit cfe045a
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/collector/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (c *Collector) processResourceScrapeTask(_ context.Context, task projectScr
logg.Debug("scraping %s resources for %s/%s", srv.Type, dbDomain.Name, dbProject.Name)

//perform resource scrape
resourceData, serializedMetrics, err := plugin.Scrape(project)
resourceData, serializedMetrics, err := plugin.Scrape(project, c.Cluster.Config.AvailabilityZones)
if err != nil {
task.Err = util.UnpackError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (p quotaConstraintTestPlugin) ServiceInfo(serviceType string) limes.Service
func (p quotaConstraintTestPlugin) Rates() []limesrates.RateInfo {
return nil
}
func (p quotaConstraintTestPlugin) Scrape(project KeystoneProject) (result map[string]ResourceData, serializedMetrics []byte, err error) {
func (p quotaConstraintTestPlugin) Scrape(project KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]ResourceData, serializedMetrics []byte, err error) {
return nil, nil, nil
}
func (p quotaConstraintTestPlugin) IsQuotaAcceptableForProject(project KeystoneProject, fullQuotas map[string]map[string]uint64, allServiceInfos []limes.ServiceInfo) error {
Expand Down
9 changes: 7 additions & 2 deletions internal/core/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ type QuotaPlugin interface {
//in the result map must be identical to the resource names
//from Resources().
//
//The serializedMetrics return value is persisted in the Limes DB and
//The `allAZs` list comes from the Limes config and should be used when
//building AZ-aware usage data, to ensure that each AZ-aware resource reports
//usage in all available AZs, even when the project in question does not have
//usage in every AZ.
//
//The `serializedMetrics` return value is persisted in the Limes DB and
//supplied to all subsequent RenderMetrics calls.
Scrape(project KeystoneProject) (result map[string]ResourceData, serializedMetrics []byte, err error)
Scrape(project KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]ResourceData, serializedMetrics []byte, err error)
//IsQuotaAcceptableForProject checks if the given quota set is acceptable
//for the given project, and returns nil if the quota is acceptable, or a
//human-readable error otherwise. This should only be used when the
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/archer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *archerPlugin) Rates() []limesrates.RateInfo {
}

// Scrape implements the core.QuotaPlugin interface.
func (p *archerPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *archerPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
url := p.Archer.ServiceURL("quotas", project.UUID)
var res gophercloud.Result
//nolint:bodyclose // already closed by gophercloud
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/cinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (p *cinderPlugin) ScrapeRates(project core.KeystoneProject, prevSerializedS
}

// Scrape implements the core.QuotaPlugin interface.
func (p *cinderPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, _ []byte, err error) {
func (p *cinderPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, _ []byte, err error) {
isVolumeType := make(map[string]bool)
for _, volumeType := range p.VolumeTypes {
isVolumeType[volumeType] = true
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/cronus.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *cronusPlugin) Rates() []limesrates.RateInfo {
}

// Scrape implements the core.QuotaPlugin interface.
func (p *cronusPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *cronusPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
return nil, nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/designate.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (p *designatePlugin) ScrapeRates(project core.KeystoneProject, prevSerializ
}

// Scrape implements the core.QuotaPlugin interface.
func (p *designatePlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *designatePlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
//query quotas
quotas, err := dnsGetQuota(p.DesignateV2, project.UUID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/keppel.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (p *keppelPlugin) ScrapeRates(project core.KeystoneProject, prevSerializedS
}

// Scrape implements the core.QuotaPlugin interface.
func (p *keppelPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *keppelPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
quotas, err := p.KeppelV1.GetQuota(project.UUID)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/manila.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (p *manilaPlugin) ScrapeRates(project core.KeystoneProject, prevSerializedS
}

// Scrape implements the core.QuotaPlugin interface.
func (p *manilaPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *manilaPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
quotaSets := make(map[string]manilaQuotaSetDetail)
for _, shareType := range p.ShareTypes {
stName := resolveManilaShareType(shareType, project)
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/neutron.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (p *neutronPlugin) ScrapeRates(project core.KeystoneProject, prevSerialized
}

// Scrape implements the core.QuotaPlugin interface.
func (p *neutronPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *neutronPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
data := make(map[string]core.ResourceData)

err = p.scrapeNeutronInto(data, project.UUID)
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/nova.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (p *novaPlugin) ScrapeRates(project core.KeystoneProject, prevSerializedSta
}

// Scrape implements the core.QuotaPlugin interface.
func (p *novaPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *novaPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
var limitsData struct {
Limits struct {
Absolute struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (p *swiftPlugin) ScrapeRates(project core.KeystoneProject, prevSerializedSt
}

// Scrape implements the core.QuotaPlugin interface.
func (p *swiftPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *swiftPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
account := p.Account(project.UUID)
headers, err := account.Headers()
if schwift.Is(err, http.StatusNotFound) || schwift.Is(err, http.StatusGone) {
Expand Down
2 changes: 1 addition & 1 deletion internal/test/plugins/quota_autoapproval.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (p *AutoApprovalQuotaPlugin) CollectMetrics(ch chan<- prometheus.Metric, pr
}

// Scrape implements the core.QuotaPlugin interface.
func (p *AutoApprovalQuotaPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *AutoApprovalQuotaPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
return map[string]core.ResourceData{
"approve": {UsageData: core.InAnyAZ(core.UsageData{Usage: 0}), Quota: int64(p.StaticBackendQuota)},
"noapprove": {UsageData: core.InAnyAZ(core.UsageData{Usage: 0}), Quota: int64(p.StaticBackendQuota) + 10},
Expand Down
2 changes: 1 addition & 1 deletion internal/test/plugins/quota_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (p *GenericQuotaPlugin) ScrapeRates(project core.KeystoneProject, prevSeria
}

// Scrape implements the core.QuotaPlugin interface.
func (p *GenericQuotaPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *GenericQuotaPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
if p.ScrapeFails {
return nil, nil, errors.New("Scrape failed as requested")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/test/plugins/quota_noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *NoopQuotaPlugin) CollectMetrics(ch chan<- prometheus.Metric, project co
}

// Scrape implements the core.QuotaPlugin interface.
func (p *NoopQuotaPlugin) Scrape(project core.KeystoneProject) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
func (p *NoopQuotaPlugin) Scrape(project core.KeystoneProject, allAZs []limes.AvailabilityZone) (result map[string]core.ResourceData, serializedMetrics []byte, err error) {
if p.WithEmptyResource {
result = map[string]core.ResourceData{
"things": {}, //no usage at all (this is used to test that the scraper adds a zero entry for AZ "any")
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func taskTestGetQuota(cluster *core.Cluster, args []string) {
logg.Fatal("unknown service type: %s", serviceType)
}

result, serializedMetrics, err := cluster.QuotaPlugins[serviceType].Scrape(project)
result, serializedMetrics, err := cluster.QuotaPlugins[serviceType].Scrape(project, cluster.Config.AvailabilityZones)
must.Succeed(err)

for resourceName := range result {
Expand Down

0 comments on commit cfe045a

Please sign in to comment.