Skip to content

Commit 3fb24ef

Browse files
authored
Merge pull request #15 from s3lph/feat-versions
feat: add spaceapi_validation_versions metric indicating all versions supported by an endpoint
2 parents 5859dfc + ee9472c commit 3fb24ef

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

collector/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/prometheus/procfs v0.0.11 // indirect
1111
github.com/robfig/cron v1.2.0
1212
github.com/rs/cors v1.7.0
13-
github.com/spaceapi-community/go-spaceapi-validator-client v0.0.0-20200104101806-0433af38010f
13+
github.com/spaceapi-community/go-spaceapi-validator-client v1.2.0
1414
goji.io v2.0.2+incompatible
1515
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
1616
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect

collector/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
7373
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
7474
github.com/spaceapi-community/go-spaceapi-validator-client v0.0.0-20200104101806-0433af38010f h1:8HjPc6E2+qGxbJTEvEMbtbHEdpCx+2ind2Vio4OTN2M=
7575
github.com/spaceapi-community/go-spaceapi-validator-client v0.0.0-20200104101806-0433af38010f/go.mod h1:Ck0OJ8C10sWvtKTGD63n9A1qEETdJe0k0XLZFIOcbkw=
76+
github.com/spaceapi-community/go-spaceapi-validator-client v1.2.0 h1:ig3KxosKgCrRHZJcLeFf5GvJwl6j0O+/XDQO75TFioU=
77+
github.com/spaceapi-community/go-spaceapi-validator-client v1.2.0/go.mod h1:AerddkhNG7XdxqCcjK7P1bk1473uGCsqN81T8wuHY7E=
7678
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7779
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7880
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

collector/main.go

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,24 @@ var (
4747
},
4848
[]string{"route", "attribute"},
4949
)
50+
spaceValidationVersionsGauge = prometheus.NewGaugeVec(
51+
prometheus.GaugeOpts{
52+
Name: "spaceapi_validation_version",
53+
Help: "SpaceAPI versions implemented by an endpoint",
54+
},
55+
[]string{"route", "version"},
56+
)
5057
)
5158

5259
type ValidateUrlV2Response struct {
53-
Valid bool `json:"valid"`
54-
IsHttps bool `json:"isHttps"`
55-
HttpsForward bool `json:"httpsForward"`
56-
Reachable bool `json:"reachable"`
57-
Cors bool `json:"cors"`
58-
ContentType bool `json:"contentType"`
59-
CertValid bool `json:"certValid"`
60+
Valid bool `json:"valid"`
61+
IsHttps bool `json:"isHttps"`
62+
HttpsForward bool `json:"httpsForward"`
63+
Reachable bool `json:"reachable"`
64+
Cors bool `json:"cors"`
65+
ContentType bool `json:"contentType"`
66+
CertValid bool `json:"certValid"`
67+
CheckedVersions []string `json:"checkedVersions"`
6068
}
6169

6270
type entry struct {
@@ -95,6 +103,7 @@ func main() {
95103
prometheus.MustRegister(staticFileScrapCounter)
96104
prometheus.MustRegister(spaceRequestSummary)
97105
prometheus.MustRegister(spaceValidationGauge)
106+
prometheus.MustRegister(spaceValidationVersionsGauge)
98107
spaceApiDirectory = make(map[string]entry)
99108

100109
directorySuccessfullyLoaded := loadPersistentDirectory()
@@ -279,7 +288,9 @@ func validateEntry(ctx context.Context, url string) (spaceapivalidatorclient.Val
279288
defer spaceValidationGauge.With(prometheus.Labels{"route": url, "attribute": "ContentType"}).Set(b2i[response.ContentType])
280289
defer spaceValidationGauge.With(prometheus.Labels{"route": url, "attribute": "CertValid"}).Set(b2i[response.CertValid])
281290
defer spaceValidationGauge.With(prometheus.Labels{"route": url, "attribute": "Valid"}).Set(b2i[response.Valid])
282-
291+
for _, v := range response.CheckedVersions {
292+
defer spaceValidationVersionsGauge.With(prometheus.Labels{"route": url, "version": v}).Set(1)
293+
}
283294
return response, nil
284295
}
285296

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

301312
entry.ValidationResult = ValidateUrlV2Response{
302-
Valid: response.Valid,
303-
IsHttps: response.IsHttps,
304-
HttpsForward: response.HttpsForward,
305-
Reachable: response.Reachable,
306-
Cors: response.Cors,
307-
ContentType: response.ContentType,
308-
CertValid: response.CertValid,
313+
Valid: response.Valid,
314+
IsHttps: response.IsHttps,
315+
HttpsForward: response.HttpsForward,
316+
Reachable: response.Reachable,
317+
Cors: response.Cors,
318+
ContentType: response.ContentType,
319+
CertValid: response.CertValid,
320+
CheckedVersions: response.CheckedVersions,
309321
}
310322
entry.Valid = response.Valid
311323
entry.LastSeen = time.Now().Unix()

0 commit comments

Comments
 (0)