Skip to content

Commit 8d8a1eb

Browse files
add logger/audit message data structure
1 parent c172a47 commit 8d8a1eb

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

logger/audit/entry.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2015-2025 MinIO, Inc.
2+
//
3+
// This file is part of MinIO Object Storage stack
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package audit
19+
20+
import "time"
21+
22+
// ObjectVersion object version key/versionId
23+
type ObjectVersion struct {
24+
ObjectName string `json:"objectName"`
25+
VersionID string `json:"versionId,omitempty"`
26+
}
27+
28+
// Entry - audit entry logs.
29+
type Entry struct {
30+
Version string `json:"version"`
31+
DeploymentID string `json:"deploymentid,omitempty"`
32+
Time time.Time `json:"time"`
33+
Event string `json:"event"`
34+
35+
// Class of audit message - S3, admin ops, bucket management
36+
Type string `json:"type,omitempty"`
37+
38+
// deprecated replaced by 'Event', kept here for some
39+
// time for backward compatibility with k8s Operator.
40+
Trigger string `json:"trigger"`
41+
API struct {
42+
Name string `json:"name,omitempty"`
43+
Bucket string `json:"bucket,omitempty"`
44+
Object string `json:"object,omitempty"`
45+
Objects []ObjectVersion `json:"objects,omitempty"`
46+
Status string `json:"status,omitempty"`
47+
StatusCode int `json:"statusCode,omitempty"`
48+
InputBytes int64 `json:"rx"`
49+
OutputBytes int64 `json:"tx"`
50+
HeaderBytes int64 `json:"txHeaders,omitempty"`
51+
TimeToFirstByte string `json:"timeToFirstByte,omitempty"`
52+
TimeToFirstByteInNS string `json:"timeToFirstByteInNS,omitempty"`
53+
TimeToResponse string `json:"timeToResponse,omitempty"`
54+
TimeToResponseInNS string `json:"timeToResponseInNS,omitempty"`
55+
} `json:"api"`
56+
RemoteHost string `json:"remotehost,omitempty"`
57+
RequestID string `json:"requestID,omitempty"`
58+
UserAgent string `json:"userAgent,omitempty"`
59+
ReqPath string `json:"requestPath,omitempty"`
60+
ReqHost string `json:"requestHost,omitempty"`
61+
ReqClaims map[string]interface{} `json:"requestClaims,omitempty"`
62+
ReqQuery map[string]string `json:"requestQuery,omitempty"`
63+
ReqHeader map[string]string `json:"requestHeader,omitempty"`
64+
RespHeader map[string]string `json:"responseHeader,omitempty"`
65+
Tags map[string]interface{} `json:"tags,omitempty"`
66+
67+
AccessKey string `json:"accessKey,omitempty"`
68+
ParentUser string `json:"parentUser,omitempty"`
69+
70+
Error string `json:"error,omitempty"`
71+
}

logger/log/entry.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright (c) 2015-2025 MinIO, Inc.
2+
//
3+
// This file is part of MinIO Object Storage stack
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package log
19+
20+
import (
21+
"strings"
22+
"time"
23+
24+
"github.com/minio/madmin-go/v3"
25+
)
26+
27+
// ObjectVersion object version key/versionId
28+
type ObjectVersion struct {
29+
ObjectName string `json:"objectName"`
30+
VersionID string `json:"versionId,omitempty"`
31+
}
32+
33+
// Args - defines the arguments for the API.
34+
type Args struct {
35+
Bucket string `json:"bucket,omitempty"`
36+
Object string `json:"object,omitempty"`
37+
VersionID string `json:"versionId,omitempty"`
38+
Objects []ObjectVersion `json:"objects,omitempty"`
39+
Metadata map[string]string `json:"metadata,omitempty"`
40+
}
41+
42+
// Trace - defines the trace.
43+
type Trace struct {
44+
Message string `json:"message,omitempty"`
45+
Source []string `json:"source,omitempty"`
46+
Variables map[string]interface{} `json:"variables,omitempty"`
47+
}
48+
49+
// API - defines the api type and its args.
50+
type API struct {
51+
Name string `json:"name,omitempty"`
52+
Args *Args `json:"args,omitempty"`
53+
}
54+
55+
// Entry - defines fields and values of each log entry.
56+
type Entry struct {
57+
Site string `json:"site,omitempty"`
58+
DeploymentID string `json:"deploymentid,omitempty"`
59+
Level madmin.LogKind `json:"level"`
60+
LogKind madmin.LogKind `json:"errKind,omitempty"` // Deprecated Jan 2024
61+
Time time.Time `json:"time"`
62+
API *API `json:"api,omitempty"`
63+
RemoteHost string `json:"remotehost,omitempty"`
64+
Host string `json:"host,omitempty"`
65+
RequestID string `json:"requestID,omitempty"`
66+
UserAgent string `json:"userAgent,omitempty"`
67+
Message string `json:"message,omitempty"`
68+
Trace *Trace `json:"error,omitempty"`
69+
}
70+
71+
// Info holds console log messages
72+
type Info struct {
73+
Entry
74+
ConsoleMsg string
75+
NodeName string `json:"node"`
76+
Err error `json:"-"`
77+
}
78+
79+
// Mask returns the mask based on the error level.
80+
func (l Info) Mask() uint64 {
81+
return l.Level.LogMask().Mask()
82+
}
83+
84+
// SendLog returns true if log pertains to node specified in args.
85+
func (l Info) SendLog(node string, logKind madmin.LogMask) bool {
86+
if logKind.Contains(l.Level.LogMask()) {
87+
return node == "" || strings.EqualFold(node, l.NodeName) && !l.Time.IsZero()
88+
}
89+
return false
90+
}

0 commit comments

Comments
 (0)