Skip to content

Commit 5df19fe

Browse files
author
Praveenrajmani
committed
add more opts
1 parent 7981314 commit 5df19fe

File tree

3 files changed

+26
-49
lines changed

3 files changed

+26
-49
lines changed

api-events.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,39 @@ import (
2525
"errors"
2626
"io"
2727
"net/http"
28-
"net/url"
28+
"time"
2929

3030
"github.com/minio/madmin-go/v3/event"
3131
)
3232

33+
// APIEventOpts represents the options for the APIEventOpts
34+
type APIEventOpts struct {
35+
Node string
36+
API string
37+
Bucket string
38+
Object string
39+
StatusCode int
40+
Interval time.Duration
41+
}
42+
3343
// GetAPIEvents fetches the persisted API events from MinIO
34-
func (adm AdminClient) GetAPIEvents(ctx context.Context, node string, api string) <-chan event.API {
44+
func (adm AdminClient) GetAPIEvents(ctx context.Context, opts APIEventOpts) (<-chan event.API, error) {
45+
apiOpts, err := json.Marshal(opts)
46+
if err != nil {
47+
return nil, err
48+
}
3549
eventCh := make(chan event.API)
36-
37-
// Only success, start a routine to start reading line by line.
3850
go func(eventCh chan<- event.API) {
3951
defer close(eventCh)
40-
urlValues := make(url.Values)
41-
urlValues.Set("node", node)
42-
urlValues.Set("api", api)
4352
reqData := requestData{
44-
relPath: adminAPIPrefix + "/events/api",
45-
queryValues: urlValues,
53+
relPath: adminAPIPrefix + "/events/api",
54+
content: apiOpts,
4655
}
47-
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
56+
resp, err := adm.executeMethod(ctx, http.MethodPost, reqData)
4857
if err != nil {
4958
closeResponse(resp)
5059
return
5160
}
52-
5361
if resp.StatusCode != http.StatusOK {
5462
return
5563
}
@@ -68,8 +76,7 @@ func (adm AdminClient) GetAPIEvents(ctx context.Context, node string, api string
6876
case eventCh <- info:
6977
}
7078
}
71-
7279
}(eventCh)
7380

74-
return eventCh
81+
return eventCh, nil
7582
}

event/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type API struct {
5252

5353
// CallInfo represents the info for the external call
5454
type CallInfo struct {
55-
HttpStatusCode int `json:"httpStatusCode,omitempty"`
55+
HTTPStatusCode int `json:"httpStatusCode,omitempty"`
5656
InputBytes int64 `json:"rx"`
5757
OutputBytes int64 `json:"tx"`
5858
HeaderBytes int64 `json:"txHeaders,omitempty"`

examples/api-events.go

+5-35
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,12 @@ func main() {
1919
if err != nil {
2020
log.Fatalln(err)
2121
}
22-
// madmClnt.SetCustomTransport(&http.Transport{
23-
// Proxy: http.ProxyFromEnvironment,
24-
// DialContext: (&net.Dialer{
25-
// Timeout: 5 * time.Second,
26-
// KeepAlive: 15 * time.Second,
27-
// FallbackDelay: 100 * time.Millisecond,
28-
// }).DialContext,
29-
// MaxIdleConns: 1024,
30-
// MaxIdleConnsPerHost: 1024,
31-
// ResponseHeaderTimeout: 60 * time.Second,
32-
// IdleConnTimeout: 60 * time.Second,
33-
// TLSHandshakeTimeout: 10 * time.Second,
34-
// ExpectContinueTimeout: 1 * time.Second,
35-
// // Set this value so that the underlying transport round-tripper
36-
// // doesn't try to auto decode the body of objects with
37-
// // content-encoding set to `gzip`.
38-
// //
39-
// // Refer:
40-
// // https://golang.org/src/net/http/transport.go?h=roundTrip#L1843
41-
// DisableCompression: true,
42-
// TLSClientConfig: &tls.Config{
43-
// // Can't use SSLv3 because of POODLE and BEAST
44-
// // Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
45-
// // Can't use TLSv1.1 because of RC4 cipher usage
46-
// MinVersion: tls.VersionTLS12,
47-
// InsecureSkipVerify: true,
48-
// },
49-
// })
22+
eventCh, err := madmClnt.GetAPIEvents(context.Background(), madmin.APIEventOpts{})
23+
if err != nil {
24+
log.Fatalln(err)
25+
}
5026

51-
eventCh := madmClnt.GetAPIEvents(context.Background(), "", "PutObject")
52-
i := 1
5327
for event := range eventCh {
54-
fmt.Printf("count: %d\n", i)
55-
i++
56-
fmt.Println("************************")
57-
fmt.Println(event)
58-
fmt.Println("************************")
28+
fmt.Printf("Event: %+v\n", event)
5929
}
6030
}

0 commit comments

Comments
 (0)