Skip to content

Commit

Permalink
add filters and complete readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gmllt committed Feb 12, 2025
1 parent e1bad98 commit 6513275
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ usage: cf_exporter --cf.api_url=CF.API_URL --cf.deployment-name=CF.DEPLOYMENT-NA
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--bbs.api_url=BBS.API_URL BBS API URL ($CF_EXPORTER_BBS_API_URL)
--bbs.ca_file=BBS.CA_FILE BBS CA File ($CF_EXPORTER_BBS_CA_FILE)
--bbs.cert_file=BBS.CERT_FILE
BBS Cert File ($CF_EXPORTER_BBS_CERT_FILE)
--bbs.key_file=BBS.KEY_FILE
BBS Key File ($CF_EXPORTER_BBS_KEY_FILE)
--bbs.skip_ssl_verify Disable SSL Verify for BBS ($CF_EXPORTER_BBS_SKIP_SSL_VERIFY)
--bbs.timeout=5 BBS API Timeout ($CF_EXPORTER_BBS_TIMEOUT)
--cf.api_url=CF.API_URL Cloud Foundry API URL ($CF_EXPORTER_CF_API_URL)
--cf.username=CF.USERNAME Cloud Foundry Username ($CF_EXPORTER_CF_USERNAME)
--cf.password=CF.PASSWORD Cloud Foundry Password ($CF_EXPORTER_CF_PASSWORD)
Expand Down
2 changes: 1 addition & 1 deletion fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *Fetcher) workInit() {
c.worker.PushIf("service_route_bindings", c.fetchServiceRouteBindings, filters.ServiceRouteBindings)
c.worker.PushIf("users", c.fetchUsers, filters.Events)
c.worker.PushIf("events", c.fetchEvents, filters.Events)
c.worker.Push("actual_lrps", c.fetchActualLRPs)
c.worker.PushIf("actual_lrps", c.fetchActualLRPs, filters.ActualLRPs)
}

func (c *Fetcher) fetch() *models.CFObjects {
Expand Down
24 changes: 24 additions & 0 deletions fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var _ = ginkgo.Describe("Fetcher", func() {
"spaces",
"space_quotas",
"applications",
"droplets",
"domains",
"process",
"routes",
Expand All @@ -54,6 +55,7 @@ var _ = ginkgo.Describe("Fetcher", func() {
"service_bindings",
"service_route_bindings",
"segments",
"actual_lrps",
}
})
ginkgo.It("plans all jobs", func() {
Expand All @@ -71,6 +73,7 @@ var _ = ginkgo.Describe("Fetcher", func() {
"spaces",
"space_quotas",
"applications",
"droplets",
"domains",
"process",
"routes",
Expand All @@ -88,6 +91,7 @@ var _ = ginkgo.Describe("Fetcher", func() {
"segments",
"users",
"events",
"actual_lrps",
}
})
ginkgo.It("plans all jobs", func() {
Expand Down Expand Up @@ -225,5 +229,25 @@ var _ = ginkgo.Describe("Fetcher", func() {
})
})

ginkgo.When("droplets filter is set", func() {
ginkgo.BeforeEach(func() {
active = []string{filters.Droplets}
expected = []string{"info", "droplets"}
})
ginkgo.It("plans only specific jobs", func() {
gomega.Ω(jobs).Should(gomega.ConsistOf(expected))
})
})

ginkgo.When("actual_lrps filter is set", func() {
ginkgo.BeforeEach(func() {
active = []string{filters.ActualLRPs}
expected = []string{"info", "actual_lrps"}
})
ginkgo.It("plans only specific jobs", func() {
gomega.Ω(jobs).Should(gomega.ConsistOf(expected))
})
})

})
})
4 changes: 4 additions & 0 deletions filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

const (
ActualLRPs = "actual_lrps"
Applications = "applications"
Droplets = "droplets"
Buildpacks = "buildpacks"
Expand All @@ -27,6 +28,7 @@ const (

var (
All = []string{
ActualLRPs,
Applications,
Droplets,
Buildpacks,
Expand Down Expand Up @@ -54,6 +56,7 @@ type Filter struct {
func NewFilter(active ...string) (*Filter, error) {
filter := &Filter{
activated: map[string]bool{
ActualLRPs: true,
Applications: true,
Droplets: true,
Buildpacks: true,
Expand Down Expand Up @@ -86,6 +89,7 @@ func NewFilter(active ...string) (*Filter, error) {
func (f *Filter) setActive(active []string) error {
// override default states with all disabled
f.activated = map[string]bool{
ActualLRPs: false,
Applications: false,
Droplets: false,
Buildpacks: false,
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var (
).Envar("CF_EXPORTER_CF_DEPLOYMENT_NAME").Required().String()

filterCollectors = kingpin.Flag(
"filter.collectors", "Comma separated collectors to filter (Applications,Buildpacks,Events,IsolationSegments,Organizations,Routes,SecurityGroups,ServiceBindings,ServiceInstances,ServicePlans,Services,Spaces,Stacks,Tasks,ActualLRPs). If not set, all collectors except Events and Tasks are enabled ($CF_EXPORTER_FILTER_COLLECTORS)",
"filter.collectors", "Comma separated collectors to filter (ActualLRPs,Applications,Buildpacks,Events,IsolationSegments,Organizations,Routes,SecurityGroups,ServiceBindings,ServiceInstances,ServicePlans,Services,Spaces,Stacks,Tasks,ActualLRPs). If not set, all collectors except Events and Tasks are enabled ($CF_EXPORTER_FILTER_COLLECTORS)",
).Envar("CF_EXPORTER_FILTER_COLLECTORS").Default("").String()

metricsNamespace = kingpin.Flag(
Expand Down

0 comments on commit 6513275

Please sign in to comment.