Skip to content

Commit 337713f

Browse files
committed
remove usage of /v2/spaces/:space_guid/summary
1 parent 71eb8b8 commit 337713f

File tree

6 files changed

+56
-69
lines changed

6 files changed

+56
-69
lines changed

collectors/applications.go

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewApplicationsCollector(
5353
Help: "Buildpack used by an Application.",
5454
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
5555
},
56-
[]string{"application_id", "application_name", "buildpack_name"},
56+
[]string{"application_id", "application_name", "buildpack_name", "detected_buildpack"},
5757
)
5858

5959
applicationInstancesMetric := prometheus.NewGaugeVec(
@@ -242,30 +242,37 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
242242
return fmt.Errorf("could not find org with guid '%s'", orgRel.GUID)
243243
}
244244

245-
appSum, ok := objs.AppSummaries[application.GUID]
246-
if !ok {
247-
return fmt.Errorf("could not find app summary with guid '%s'", application.GUID)
248-
}
249-
250-
// 1.
251-
detectedBuildpack := appSum.DetectedBuildpack
252-
if len(detectedBuildpack) == 0 {
253-
detectedBuildpack = appSum.Buildpack
254-
}
255-
256-
// 2.
257-
buildpack := appSum.Buildpack
258-
if len(buildpack) == 0 {
259-
buildpack = appSum.DetectedBuildpack
245+
detectedBuildpack := ""
246+
buildpack := ""
247+
stackGUID := ""
248+
for _, stack := range objs.Stacks {
249+
if stack.Name == application.Lifecycle.Data.Stack {
250+
stackGUID = stack.GUID
251+
break
252+
}
260253
}
261-
262-
// 3. Use the droplet data for the buildpack metric
263-
for _, bp := range application.Lifecycle.Data.Buildpacks {
264-
c.applicationBuildpackMetric.WithLabelValues(
265-
application.GUID,
266-
application.Name,
267-
bp,
268-
).Set(float64(1))
254+
if dropletGUID := application.Relationships[constant.RelationshipTypeCurrentDroplet].GUID; dropletGUID != "" {
255+
if droplet, ok := objs.Droplets[dropletGUID]; ok {
256+
// 1.
257+
detectedBuildpack = droplet.Buildpacks[0].DetectOutput
258+
// 2.
259+
buildpack = droplet.Buildpacks[0].BuildpackName
260+
if len(detectedBuildpack) == 0 {
261+
detectedBuildpack = buildpack
262+
}
263+
if len(buildpack) == 0 {
264+
buildpack = detectedBuildpack
265+
}
266+
// 3.Use the droplet data for the buildpack metric
267+
for _, bp := range droplet.Buildpacks {
268+
c.applicationBuildpackMetric.WithLabelValues(
269+
application.GUID,
270+
application.Name,
271+
bp.BuildpackName,
272+
bp.DetectOutput,
273+
).Set(float64(1))
274+
}
275+
}
269276
}
270277

271278
c.applicationInfoMetric.WithLabelValues(
@@ -277,7 +284,7 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
277284
organization.Name,
278285
space.GUID,
279286
space.Name,
280-
appSum.StackID,
287+
stackGUID,
281288
string(application.State),
282289
).Set(float64(1))
283290

@@ -291,15 +298,14 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
291298
string(application.State),
292299
).Set(float64(process.Instances.Value))
293300

294-
runningInstances := appSum.RunningInstances
295301
// Use bbs data if available
302+
runningInstances := 0
296303
if len(objs.ProcessActualLRPs) > 0 {
297-
runningsInstances := 0
298-
lrps, ok := objs.ProcessActualLRPs[process.GUID]
304+
LRPs, ok := objs.ProcessActualLRPs[process.GUID]
299305
if ok {
300-
for _, lrp := range lrps {
306+
for _, lrp := range LRPs {
301307
if lrp.State == "RUNNING" {
302-
runningsInstances++
308+
runningInstances++
303309
}
304310
}
305311
}

fetcher/fetcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (c *Fetcher) workInit() {
6767
c.worker.PushIf("spaces", c.fetchSpaces, filters.Applications, filters.Spaces)
6868
c.worker.PushIf("space_quotas", c.fetchSpaceQuotas, filters.Spaces)
6969
c.worker.PushIf("applications", c.fetchApplications, filters.Applications)
70+
c.worker.PushIf("droplets", c.fetchDroplets, filters.Droplets)
7071
c.worker.PushIf("domains", c.fetchDomains, filters.Domains)
7172
c.worker.PushIf("process", c.fetchProcesses, filters.Applications)
7273
c.worker.PushIf("routes", c.fetchRoutes, filters.Routes)

fetcher/fetcher_handlers.go

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package fetcher
22

33
import (
4-
"fmt"
54
"regexp"
65
"time"
76

87
models2 "code.cloudfoundry.org/bbs/models"
98

109
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
1110
"code.cloudfoundry.org/cli/resources"
12-
"github.com/cloudfoundry/cf_exporter/filters"
1311
"github.com/cloudfoundry/cf_exporter/models"
1412
log "github.com/sirupsen/logrus"
1513
)
@@ -74,33 +72,10 @@ func (c *Fetcher) fetchOrgQuotas(session *SessionExt, _ *BBSClient, entry *model
7472
// summary fetching attempt. See cloudfoundry/cf_exporter#85
7573
func (c *Fetcher) fetchSpaces(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error {
7674
spaces, _, _, err := session.V3().GetSpaces(LargeQuery)
77-
if err != nil {
78-
return err
79-
}
80-
81-
loadIndex(entry.Spaces, spaces, func(r resources.Space) string { return r.GUID })
82-
total := len(spaces)
83-
for idx := 0; idx < total; idx++ {
84-
space := spaces[idx]
85-
name := fmt.Sprintf("space_summaries %04d/%04d (%s)", idx, total, space.GUID)
86-
c.worker.PushIf(name, func(session *SessionExt, bbs *BBSClient, entry *models.CFObjects) error {
87-
spaceSum, err := session.GetSpaceSummary(space.GUID)
88-
if err == nil {
89-
c.Lock()
90-
entry.SpaceSummaries[spaceSum.GUID] = *spaceSum
91-
for _, app := range spaceSum.Apps {
92-
entry.AppSummaries[app.GUID] = app
93-
}
94-
c.Unlock()
95-
} else {
96-
log.WithError(err).Warnf("could not fetch space '%s' summary", space.GUID)
97-
}
98-
// 1
99-
return nil
100-
}, filters.Applications)
75+
if err == nil {
76+
loadIndex(entry.Spaces, spaces, func(r resources.Space) string { return r.GUID })
10177
}
102-
103-
return nil
78+
return err
10479
}
10580

10681
func (c *Fetcher) fetchSpaceQuotas(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error {
@@ -169,6 +144,14 @@ func (c *Fetcher) fetchSecurityGroups(session *SessionExt, _ *BBSClient, entry *
169144
return err
170145
}
171146

147+
func (c *Fetcher) fetchDroplets(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error {
148+
droplets, _, err := session.V3().GetDroplets(LargeQuery)
149+
if err == nil {
150+
loadIndex(entry.Droplets, droplets, func(r resources.Droplet) string { return r.GUID })
151+
}
152+
return err
153+
}
154+
172155
func (c *Fetcher) fetchStacks(session *SessionExt, _ *BBSClient, entry *models.CFObjects) error {
173156
stacks, _, err := session.V3().GetStacks(LargeQuery)
174157
if err == nil {

filters/filters.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
const (
99
Applications = "applications"
10+
Droplets = "droplets"
1011
Buildpacks = "buildpacks"
1112
Domains = "domains"
1213
Events = "events"
@@ -22,12 +23,12 @@ const (
2223
Spaces = "spaces"
2324
Stacks = "stacks"
2425
Tasks = "tasks"
25-
InstancesRunning = "instances_running"
2626
)
2727

2828
var (
2929
All = []string{
3030
Applications,
31+
Droplets,
3132
Buildpacks,
3233
Domains,
3334
Events,
@@ -54,6 +55,7 @@ func NewFilter(active ...string) (*Filter, error) {
5455
filter := &Filter{
5556
activated: map[string]bool{
5657
Applications: true,
58+
Droplets: true,
5759
Buildpacks: true,
5860
Domains: true,
5961
IsolationSegments: true,
@@ -69,7 +71,6 @@ func NewFilter(active ...string) (*Filter, error) {
6971
Stacks: true,
7072
Tasks: false,
7173
Events: false,
72-
InstancesRunning: false,
7374
},
7475
}
7576

@@ -86,6 +87,7 @@ func (f *Filter) setActive(active []string) error {
8687
// override default states with all disabled
8788
f.activated = map[string]bool{
8889
Applications: false,
90+
Droplets: false,
8991
Buildpacks: false,
9092
Domains: false,
9193
IsolationSegments: false,
@@ -101,7 +103,6 @@ func (f *Filter) setActive(active []string) error {
101103
Stacks: false,
102104
Tasks: false,
103105
Events: false,
104-
InstancesRunning: false,
105106
}
106107

107108
// enable only given filters

main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/prometheus/client_golang/prometheus/promhttp"
1515
"github.com/prometheus/common/version"
1616
log "github.com/sirupsen/logrus"
17-
kingpin "gopkg.in/alecthomas/kingpin.v2"
17+
"gopkg.in/alecthomas/kingpin.v2"
1818
)
1919

2020
var (
@@ -195,9 +195,6 @@ func main() {
195195
SkipCertVerify: *bbsSkipSSLValidation,
196196
}
197197

198-
log.Infof("cfConfig: %+v", cfConfig)
199-
log.Infof("bbsConfig: %+v", bbsConfig)
200-
201198
active := []string{}
202199
if len(*filterCollectors) != 0 {
203200
active = strings.Split(*filterCollectors, ",")

models/model.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type CFObjects struct {
1717
Spaces map[string]resources.Space `json:"spaces"`
1818
SpaceQuotas map[string]Quota `json:"space_quotas"`
1919
Apps map[string]Application `json:"apps"`
20+
Droplets map[string]resources.Droplet `json:"droplets"`
2021
Processes map[string]resources.Process `json:"process"`
2122
Tasks map[string]Task `json:"tasks"`
2223
Routes map[string]resources.Route `json:"routes"`
@@ -26,13 +27,12 @@ type CFObjects struct {
2627
SecurityGroups map[string]resources.SecurityGroup `json:"security_groups"`
2728
Stacks map[string]resources.Stack `json:"stacks"`
2829
Buildpacks map[string]resources.Buildpack `json:"buildpacks"`
30+
BuildpacksByName map[string]resources.Buildpack `json:"builpacks_by_name"`
2931
Domains map[string]resources.Domain `json:"domains"`
3032
ServiceBrokers map[string]resources.ServiceBroker `json:"service_brokers"`
3133
ServiceOfferings map[string]resources.ServiceOffering `json:"service_offerings"`
3234
ServicePlans map[string]resources.ServicePlan `json:"service_plans"`
3335
ServiceBindings map[string]resources.ServiceCredentialBinding `json:"service_bindings"`
34-
SpaceSummaries map[string]SpaceSummary `json:"space_summaries"`
35-
AppSummaries map[string]AppSummary `json:"app_summaries"`
3636
AppProcesses map[string][]resources.Process `json:"app_processes"`
3737
ProcessActualLRPs map[string][]*models.ActualLRP `json:"process_actual_lrps"`
3838
Events map[string]Event `json:"events"`
@@ -159,6 +159,7 @@ func NewCFObjects() *CFObjects {
159159
Spaces: map[string]resources.Space{},
160160
SpaceQuotas: map[string]Quota{},
161161
Apps: map[string]Application{},
162+
Droplets: map[string]resources.Droplet{},
162163
Processes: map[string]resources.Process{},
163164
Tasks: map[string]Task{},
164165
Routes: map[string]resources.Route{},
@@ -173,8 +174,6 @@ func NewCFObjects() *CFObjects {
173174
ServiceOfferings: map[string]resources.ServiceOffering{},
174175
ServicePlans: map[string]resources.ServicePlan{},
175176
ServiceBindings: map[string]resources.ServiceCredentialBinding{},
176-
SpaceSummaries: map[string]SpaceSummary{},
177-
AppSummaries: map[string]AppSummary{},
178177
AppProcesses: map[string][]resources.Process{},
179178
ProcessActualLRPs: map[string][]*models.ActualLRP{},
180179
Users: map[string]resources.User{},

0 commit comments

Comments
 (0)