-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathapi-logs.go
More file actions
86 lines (81 loc) · 2.32 KB
/
api-logs.go
File metadata and controls
86 lines (81 loc) · 2.32 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
//
// 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 the APILogOpts
type APILogOpts struct {
Node string `json:"node,omitempty"`
API string `json:"api,omitempty"`
Bucket string `json:"bucket,omitempty"`
Prefix string `json:"prefix,omitempty"`
StatusCode int `json:"statusCode,omitempty"`
Interval time.Duration `json:"interval,omitempty"`
Origin log.Origin `json:"origin,omitempty"`
Type log.APIType `json:"type,omitempty"`
MaxPerNode int `json:"maxPerNode,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)
}
}
}
}