mirror of
https://github.com/pgsty/minio.git
synced 2026-07-19 04:00:25 +03:00
add validation test for v3 metrics for all its endpoints (#20094)
add unit test for v3 metrics for all its exposed endpoints
Bonus:
- support OpenMetrics encoding
- adds boot time for prometheus
- continueOnError is better to serve as
much metrics as possible.
This commit is contained in:
@@ -35,6 +35,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
jwtgo "github.com/golang-jwt/jwt/v4"
|
||||
"github.com/minio/minio-go/v7/pkg/set"
|
||||
xhttp "github.com/minio/minio/internal/http"
|
||||
"github.com/minio/pkg/v3/policy"
|
||||
@@ -122,6 +123,9 @@ func runAllTests(suite *TestSuiteCommon, c *check) {
|
||||
suite.TestObjectMultipartListError(c)
|
||||
suite.TestObjectValidMD5(c)
|
||||
suite.TestObjectMultipart(c)
|
||||
suite.TestMetricsV3Handler(c)
|
||||
suite.TestBucketSQSNotificationWebHook(c)
|
||||
suite.TestBucketSQSNotificationAMQP(c)
|
||||
suite.TearDownSuite(c)
|
||||
}
|
||||
|
||||
@@ -189,6 +193,36 @@ func (s *TestSuiteCommon) TearDownSuite(c *check) {
|
||||
s.testServer.Stop()
|
||||
}
|
||||
|
||||
const (
|
||||
defaultPrometheusJWTExpiry = 100 * 365 * 24 * time.Hour
|
||||
)
|
||||
|
||||
func (s *TestSuiteCommon) TestMetricsV3Handler(c *check) {
|
||||
jwt := jwtgo.NewWithClaims(jwtgo.SigningMethodHS512, jwtgo.StandardClaims{
|
||||
ExpiresAt: time.Now().UTC().Add(defaultPrometheusJWTExpiry).Unix(),
|
||||
Subject: s.accessKey,
|
||||
Issuer: "prometheus",
|
||||
})
|
||||
|
||||
token, err := jwt.SignedString([]byte(s.secretKey))
|
||||
c.Assert(err, nil)
|
||||
|
||||
for _, cpath := range globalMetricsV3CollectorPaths {
|
||||
request, err := newTestSignedRequest(http.MethodGet, s.endPoint+minioReservedBucketPath+metricsV3Path+string(cpath),
|
||||
0, nil, s.accessKey, s.secretKey, s.signer)
|
||||
c.Assert(err, nil)
|
||||
|
||||
request.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
// execute the request.
|
||||
response, err := s.client.Do(request)
|
||||
c.Assert(err, nil)
|
||||
|
||||
// assert the http response status code.
|
||||
c.Assert(response.StatusCode, http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TestSuiteCommon) TestBucketSQSNotificationWebHook(c *check) {
|
||||
// Sample bucket notification.
|
||||
bucketNotificationBuf := `<NotificationConfiguration><QueueConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>images/</Value></FilterRule></S3Key></Filter><Id>1</Id><Queue>arn:minio:sqs:us-east-1:444455556666:webhook</Queue></QueueConfiguration></NotificationConfiguration>`
|
||||
|
||||
Reference in New Issue
Block a user