Skip to content

Commit

Permalink
modify per offline discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
yachang committed May 7, 2019
1 parent 74d2c0f commit dad5c5d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
48 changes: 27 additions & 21 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ func Annotate(w http.ResponseWriter, r *http.Request) {
return
}

if result.Geo.Latitude != 0 {
metrics.ResponseWithLatitude.Inc()
}
if result.Geo.Longitude != 0 {
metrics.ResponseWithLongitude.Inc()
}
if result.Network != nil && len(result.Network.Systems) > 0 && len(result.Network.Systems[0].ASNs) > 0 && result.Network.Systems[0].ASNs[0] != 0 {
metrics.ResponseWithASN.Inc()
if result.Geo.Latitude == 0 || result.Geo.Longitude == 0 {
metrics.ResponseMissingAnnotation.WithLabelValues("geo").Inc()
}
} else {
if result.Geo.Latitude == 0 || result.Geo.Longitude == 0 {
metrics.ResponseMissingAnnotation.WithLabelValues("both").Inc()
} else {
metrics.ResponseMissingAnnotation.WithLabelValues("asn").Inc()
}
}

encodedResult, err := json.Marshal(result)
Expand Down Expand Up @@ -286,14 +288,16 @@ func handleOld(w http.ResponseWriter, tStart time.Time, jsonBuffer []byte) {
responseMap = make(map[string]*api.GeoData)
}
for _, anno := range responseMap {
if anno.Geo.Latitude != 0 {
metrics.ResponseWithLatitude.Inc()
}
if anno.Geo.Longitude != 0 {
metrics.ResponseWithLongitude.Inc()
}
if anno.Network != nil && len(anno.Network.Systems) > 0 && len(anno.Network.Systems[0].ASNs) > 0 && anno.Network.Systems[0].ASNs[0] != 0 {
metrics.ResponseWithASN.Inc()
if anno.Geo.Latitude == 0 || anno.Geo.Longitude == 0 {
metrics.ResponseMissingAnnotation.WithLabelValues("geo").Inc()
}
} else {
if anno.Geo.Latitude == 0 || anno.Geo.Longitude == 0 {
metrics.ResponseMissingAnnotation.WithLabelValues("both").Inc()
} else {
metrics.ResponseMissingAnnotation.WithLabelValues("asn").Inc()
}
}
}
encodedResult, err := json.Marshal(responseMap)
Expand Down Expand Up @@ -332,14 +336,16 @@ func handleV2(w http.ResponseWriter, tStart time.Time, jsonBuffer []byte) {
}
}
for _, anno := range response.Annotations {
if anno.Geo.Latitude != 0 {
metrics.ResponseWithLatitude.Inc()
}
if anno.Geo.Longitude != 0 {
metrics.ResponseWithLongitude.Inc()
}
if anno.Network != nil && len(anno.Network.Systems) > 0 && len(anno.Network.Systems[0].ASNs) > 0 && anno.Network.Systems[0].ASNs[0] != 0 {
metrics.ResponseWithASN.Inc()
if anno.Geo.Latitude == 0 || anno.Geo.Longitude == 0 {
metrics.ResponseMissingAnnotation.WithLabelValues("geo").Inc()
}
} else {
if anno.Geo.Latitude == 0 || anno.Geo.Longitude == 0 {
metrics.ResponseMissingAnnotation.WithLabelValues("both").Inc()
} else {
metrics.ResponseMissingAnnotation.WithLabelValues("asn").Inc()
}
}
}
encodedResult, err := json.Marshal(response)
Expand Down
19 changes: 7 additions & 12 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ var (
Name: "annotator_Annotation_Requests_total",
Help: "The total number of annotation service requests.",
})
ResponseWithLatitude = promauto.NewCounter(prometheus.CounterOpts{
Name: "annotator_Annotation_Response_with_latitude_total",
Help: "The total number of annotation responses with not-null latitude field.",
})
ResponseWithLongitude = promauto.NewCounter(prometheus.CounterOpts{
Name: "annotator_Annotation_Response_with_Longitude_total",
Help: "The total number of annotation responses with not-null Longitude field.",
})
ResponseWithASN = promauto.NewCounter(prometheus.CounterOpts{
Name: "annotator_Annotation_Response_with_Asn_total",
Help: "The total number of annotation responses with asn field.",
})
// Measure the number of IPs w/ missing anottaion fields. missing type
// could be "geo", "asn", "both".
ResponseMissingAnnotation = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "annotator_Annotation_Response_Missing_Annotation_total",
Help: "The total number of annotation responses with missing annotation field.",
}, []string{"missing_type"})

TotalLookups = promauto.NewCounter(prometheus.CounterOpts{
Name: "annotator_Annotation_Lookups_total",
Help: "The total number of ip lookups.",
Expand Down

0 comments on commit dad5c5d

Please sign in to comment.