Skip to content

Find, verify, and analyze leaked credentials

added monthly requests limit to postman api request metrics collection (#4667)

Shahzad Haiderb924c0bfbe82
diff --git a/pkg/sources/postman/metrics.go b/pkg/sources/postman/metrics.go
index 958d45bba..c6e3d1471 100644
--- a/pkg/sources/postman/metrics.go
+++ b/pkg/sources/postman/metrics.go
@@ -9,6 +9,7 @@ import (
type metrics struct {
apiRequests *prometheus.CounterVec
apiMonthlyRequestsRemaining *prometheus.GaugeVec
+ apiMonthlyRequestsLimit *prometheus.GaugeVec
}
var (
@@ -27,6 +28,14 @@ var (
Help: "Total number of Postman API requests remaining this month.",
},
[]string{"source_name"})
+
+ postmanAPIMonthlyRequestsLimit = promauto.NewGaugeVec(prometheus.GaugeOpts{
+ Namespace: common.MetricsNamespace,
+ Subsystem: common.MetricsSubsystem,
+ Name: "postman_api_monthly_requests_limit",
+ Help: "Total monthly Postman API request limit.",
+ },
+ []string{"source_name"})
)
func newMetrics(sourceName string) *metrics {
@@ -37,5 +46,8 @@ func newMetrics(sourceName string) *metrics {
apiMonthlyRequestsRemaining: postmanAPIMonthlyRequestsRemaining.MustCurryWith(map[string]string{
"source_name": sourceName,
}),
+ apiMonthlyRequestsLimit: postmanAPIMonthlyRequestsLimit.MustCurryWith(map[string]string{
+ "source_name": sourceName,
+ }),
}
}
diff --git a/pkg/sources/postman/postman_client.go b/pkg/sources/postman/postman_client.go
index e41ee8440..6ecb9f440 100644
--- a/pkg/sources/postman/postman_client.go
+++ b/pkg/sources/postman/postman_client.go
@@ -345,6 +345,10 @@ func (c *Client) handleRateLimits(ctx trContext.Context, resp *http.Response) er
return nil
}
+ c.Metrics.apiMonthlyRequestsLimit.WithLabelValues().Set(
+ float64(rateLimitTotalMonth),
+ )
+
if rateLimitTotalMonth == 0 {
ctx.Logger().V(2).Info("RateLimit-Limit-Month is zero, cannot compute usage percentage")
return nil