-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathapi-logs.go
More file actions
98 lines (93 loc) · 2.79 KB
/
Copy pathapi-logs.go
File metadata and controls
98 lines (93 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Copyright (c) 2015-2025 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package madmin
import (
"context"
"encoding/json"
"errors"
"io"
"iter"
"net/http"
"time"
"github.com/minio/madmin-go/v4/log"
"github.com/tinylib/msgp/msgp"
)
// APILogOpts represents the options for fetching API logs.
//
// Wildcard syntax on Nodes / APIs / Buckets entries (case-insensitive):
//
// "xyz" → exact match
// "xyz*" → prefix match
// "*xyz" → suffix match
// "*xyz*" → contains match
// "*" → matches anything
//
// Values within a single field OR-combine; across fields filters AND.
type APILogOpts struct {
Nodes []string `json:"nodes,omitempty"`
APIs []string `json:"apis,omitempty"`
Buckets []string `json:"buckets,omitempty"`
Prefix string `json:"prefix,omitempty"`
StatusCodes []int `json:"statusCodes,omitempty"`
StatusRanges []string `json:"statusRanges,omitempty"` // e.g. "2xx", "4xx", "5xx"
Interval time.Duration `json:"interval,omitempty"`
Origins []log.Origin `json:"origins,omitempty"`
Types []log.APIType `json:"types,omitempty"`
MaxPerNode int `json:"maxPerNode,omitempty"` // Deprecated
Limit int `json:"limit,omitempty"`
}
// GetAPILogs fetches the persisted API logs from MinIO
func (adm AdminClient) GetAPILogs(ctx context.Context, opts APILogOpts) iter.Seq2[log.API, error] {
return func(yield func(log.API, error) bool) {
apiOpts, err := json.Marshal(opts)
if err != nil {
yield(log.API{}, err)
return
}
reqData := requestData{
relPath: adminAPIPrefix + "/logs/api",
content: apiOpts,
}
resp, err := adm.executeMethod(ctx, http.MethodPost, reqData)
if err != nil {
yield(log.API{}, err)
return
}
if resp.StatusCode != http.StatusOK {
yield(log.API{}, httpRespToErrorResponse(resp))
return
}
dec := msgp.NewReader(resp.Body)
for {
var info log.API
if err = info.DecodeMsg(dec); err != nil {
if errors.Is(err, io.EOF) {
break
}
continue
}
select {
case <-ctx.Done():
return
default:
yield(info, nil)
}
}
}
}