Skip to content

Commit

Permalink
Completed buildpack metric
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspd authored and gmllt committed Jun 18, 2024
1 parent e90f88a commit c407029
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/dist
/cf_exporter
*.tar.gz
.env
5 changes: 4 additions & 1 deletion collectors/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewApplicationsCollector(
Help: "Buildpack used by an Application.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "buildpack"},
[]string{"application_id", "application_name", "buildpack", "detect_output", "buildpack_name", "version"},
)

applicationInstancesMetric := prometheus.NewGaugeVec(
Expand Down Expand Up @@ -266,6 +266,9 @@ func (c ApplicationsCollector) reportApp(application models.Application, objs *m
application.GUID,
application.Name,
bp.Name,
bp.DetectOutput,
bp.BuildpackName,
bp.Version,
).Set(float64(1))
}
}
Expand Down
25 changes: 24 additions & 1 deletion fetcher/sessionext.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"

"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"github.com/bosh-prometheus/cf_exporter/models"
Expand Down Expand Up @@ -191,12 +192,34 @@ func (s SessionExt) ListDroplets() ([]models.Droplet, error) {
if data.Pagination.Next.Href == "" {
break
}
url = data.Pagination.Next.Href
nextURL, err := getNextURL(url, data.Pagination.Next.Href)
if err != nil {
return nil, err
}
url = nextURL
}

return droplets, nil
}

func getNextURL(currentURL, nextHref string) (string, error) {
parsedNext, err := url.Parse(nextHref)
if err != nil {
return "", err
}
if parsedNext.IsAbs() {
return parsedNext.String(), nil
}

parsedCurrent, err := url.Parse(currentURL)
if err != nil {
return "", err
}

resolved := parsedCurrent.ResolveReference(parsedNext)
return resolved.String(), nil
}

// Local Variables:
// ispell-local-dictionary: "american"
// End:
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down
2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ github.com/imdario/mergo
# github.com/jessevdk/go-flags v1.5.0
## explicit; go 1.15
github.com/jessevdk/go-flags
# github.com/joho/godotenv v1.5.1
## explicit; go 1.12
# github.com/json-iterator/go v1.1.12
## explicit; go 1.12
github.com/json-iterator/go
Expand Down

0 comments on commit c407029

Please sign in to comment.