Skip to content

Commit

Permalink
Merge pull request #15 from s3lph/feat-versions
Browse files Browse the repository at this point in the history
feat: add spaceapi_validation_versions metric indicating all versions supported by an endpoint
  • Loading branch information
s3lph authored Feb 1, 2025
2 parents 5859dfc + ee9472c commit 3fb24ef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/prometheus/procfs v0.0.11 // indirect
github.com/robfig/cron v1.2.0
github.com/rs/cors v1.7.0
github.com/spaceapi-community/go-spaceapi-validator-client v0.0.0-20200104101806-0433af38010f
github.com/spaceapi-community/go-spaceapi-validator-client v1.2.0
goji.io v2.0.2+incompatible
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect
Expand Down
2 changes: 2 additions & 0 deletions collector/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spaceapi-community/go-spaceapi-validator-client v0.0.0-20200104101806-0433af38010f h1:8HjPc6E2+qGxbJTEvEMbtbHEdpCx+2ind2Vio4OTN2M=
github.com/spaceapi-community/go-spaceapi-validator-client v0.0.0-20200104101806-0433af38010f/go.mod h1:Ck0OJ8C10sWvtKTGD63n9A1qEETdJe0k0XLZFIOcbkw=
github.com/spaceapi-community/go-spaceapi-validator-client v1.2.0 h1:ig3KxosKgCrRHZJcLeFf5GvJwl6j0O+/XDQO75TFioU=
github.com/spaceapi-community/go-spaceapi-validator-client v1.2.0/go.mod h1:AerddkhNG7XdxqCcjK7P1bk1473uGCsqN81T8wuHY7E=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
42 changes: 27 additions & 15 deletions collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,24 @@ var (
},
[]string{"route", "attribute"},
)
spaceValidationVersionsGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "spaceapi_validation_version",
Help: "SpaceAPI versions implemented by an endpoint",
},
[]string{"route", "version"},
)
)

type ValidateUrlV2Response struct {
Valid bool `json:"valid"`
IsHttps bool `json:"isHttps"`
HttpsForward bool `json:"httpsForward"`
Reachable bool `json:"reachable"`
Cors bool `json:"cors"`
ContentType bool `json:"contentType"`
CertValid bool `json:"certValid"`
Valid bool `json:"valid"`
IsHttps bool `json:"isHttps"`
HttpsForward bool `json:"httpsForward"`
Reachable bool `json:"reachable"`
Cors bool `json:"cors"`
ContentType bool `json:"contentType"`
CertValid bool `json:"certValid"`
CheckedVersions []string `json:"checkedVersions"`
}

type entry struct {
Expand Down Expand Up @@ -95,6 +103,7 @@ func main() {
prometheus.MustRegister(staticFileScrapCounter)
prometheus.MustRegister(spaceRequestSummary)
prometheus.MustRegister(spaceValidationGauge)
prometheus.MustRegister(spaceValidationVersionsGauge)
spaceApiDirectory = make(map[string]entry)

directorySuccessfullyLoaded := loadPersistentDirectory()
Expand Down Expand Up @@ -279,7 +288,9 @@ func validateEntry(ctx context.Context, url string) (spaceapivalidatorclient.Val
defer spaceValidationGauge.With(prometheus.Labels{"route": url, "attribute": "ContentType"}).Set(b2i[response.ContentType])
defer spaceValidationGauge.With(prometheus.Labels{"route": url, "attribute": "CertValid"}).Set(b2i[response.CertValid])
defer spaceValidationGauge.With(prometheus.Labels{"route": url, "attribute": "Valid"}).Set(b2i[response.Valid])

for _, v := range response.CheckedVersions {
defer spaceValidationVersionsGauge.With(prometheus.Labels{"route": url, "version": v}).Set(1)
}
return response, nil
}

Expand All @@ -299,13 +310,14 @@ func buildEntry(ctx context.Context, url string, c chan entry) {
}

entry.ValidationResult = ValidateUrlV2Response{
Valid: response.Valid,
IsHttps: response.IsHttps,
HttpsForward: response.HttpsForward,
Reachable: response.Reachable,
Cors: response.Cors,
ContentType: response.ContentType,
CertValid: response.CertValid,
Valid: response.Valid,
IsHttps: response.IsHttps,
HttpsForward: response.HttpsForward,
Reachable: response.Reachable,
Cors: response.Cors,
ContentType: response.ContentType,
CertValid: response.CertValid,
CheckedVersions: response.CheckedVersions,
}
entry.Valid = response.Valid
entry.LastSeen = time.Now().Unix()
Expand Down

0 comments on commit 3fb24ef

Please sign in to comment.