github.com/minio/madmin-go/v3@v3.0.51/trace.go (about) 1 // 2 // Copyright (c) 2015-2022 MinIO, Inc. 3 // 4 // This file is part of MinIO Object Storage stack 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as 8 // published by the Free Software Foundation, either version 3 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package madmin 21 22 import ( 23 "math/bits" 24 "net/http" 25 "time" 26 ) 27 28 //go:generate stringer -type=TraceType -trimprefix=Trace $GOFILE 29 30 // TraceType indicates the type of the tracing Info 31 type TraceType uint64 32 33 const ( 34 // TraceOS tracing (Golang os package calls) 35 TraceOS TraceType = 1 << iota 36 // TraceStorage tracing (MinIO Storage Layer) 37 TraceStorage 38 // TraceS3 provides tracing of S3 API calls 39 TraceS3 40 // TraceInternal tracing internal (.minio.sys/...) HTTP calls 41 TraceInternal 42 // TraceScanner will trace scan operations. 43 TraceScanner 44 // TraceDecommission will trace decommission operations. 45 TraceDecommission 46 // TraceHealing will trace healing operations. 47 TraceHealing 48 // TraceBatchReplication will trace batch replication operations. 49 TraceBatchReplication 50 // TraceBatchKeyRotation will trace batch keyrotation operations. 51 TraceBatchKeyRotation 52 // TraceBatchExpire will trace batch expiration operations. 53 TraceBatchExpire 54 // TraceRebalance will trace rebalance operations 55 TraceRebalance 56 // TraceReplicationResync will trace replication resync operations. 57 TraceReplicationResync 58 // TraceBootstrap will trace events during MinIO cluster bootstrap 59 TraceBootstrap 60 // TraceFTP will trace events from MinIO FTP Server 61 TraceFTP 62 // TraceILM will trace events during MinIO ILM operations 63 TraceILM 64 // Add more here... 65 66 // TraceAll contains all valid trace modes. 67 // This *must* be the last entry. 68 TraceAll TraceType = (1 << iota) - 1 69 ) 70 71 const ( 72 // TraceBatch will trace all batch operations. 73 TraceBatch = TraceBatchReplication | TraceBatchKeyRotation | TraceBatchExpire // |TraceBatch<NextFeature> 74 ) 75 76 // Contains returns whether all flags in other is present in t. 77 func (t TraceType) Contains(other TraceType) bool { 78 return t&other == other 79 } 80 81 // Overlaps returns whether any flags in t overlaps with other. 82 func (t TraceType) Overlaps(other TraceType) bool { 83 return t&other != 0 84 } 85 86 // SingleType returns whether t has a single type set. 87 func (t TraceType) SingleType() bool { 88 // Include 89 return bits.OnesCount64(uint64(t)) == 1 90 } 91 92 // Merge will merge other into t. 93 func (t *TraceType) Merge(other TraceType) { 94 *t = *t | other 95 } 96 97 // SetIf will add other if b is true. 98 func (t *TraceType) SetIf(b bool, other TraceType) { 99 if b { 100 *t = *t | other 101 } 102 } 103 104 // Mask returns the trace type as uint32. 105 func (t TraceType) Mask() uint64 { 106 return uint64(t) 107 } 108 109 // TraceInfo - represents a trace record, additionally 110 // also reports errors if any while listening on trace. 111 type TraceInfo struct { 112 TraceType TraceType `json:"type"` 113 114 NodeName string `json:"nodename"` 115 FuncName string `json:"funcname"` 116 Time time.Time `json:"time"` 117 Path string `json:"path"` 118 Duration time.Duration `json:"dur"` 119 120 Message string `json:"msg,omitempty"` 121 Error string `json:"error,omitempty"` 122 Custom map[string]string `json:"custom,omitempty"` 123 HTTP *TraceHTTPStats `json:"http,omitempty"` 124 HealResult *HealResultItem `json:"healResult,omitempty"` 125 } 126 127 // Mask returns the trace type as uint32. 128 func (t TraceInfo) Mask() uint64 { 129 return t.TraceType.Mask() 130 } 131 132 // traceInfoLegacy - represents a trace record, additionally 133 // also reports errors if any while listening on trace. 134 // For minio versions before July 2022. 135 type traceInfoLegacy struct { 136 TraceInfo 137 138 ReqInfo *TraceRequestInfo `json:"request"` 139 RespInfo *TraceResponseInfo `json:"response"` 140 CallStats *TraceCallStats `json:"stats"` 141 142 StorageStats *struct { 143 Path string `json:"path"` 144 Duration time.Duration `json:"duration"` 145 } `json:"storageStats"` 146 OSStats *struct { 147 Path string `json:"path"` 148 Duration time.Duration `json:"duration"` 149 } `json:"osStats"` 150 } 151 152 type TraceHTTPStats struct { 153 ReqInfo TraceRequestInfo `json:"request"` 154 RespInfo TraceResponseInfo `json:"response"` 155 CallStats TraceCallStats `json:"stats"` 156 } 157 158 // TraceCallStats records request stats 159 type TraceCallStats struct { 160 InputBytes int `json:"inputbytes"` 161 OutputBytes int `json:"outputbytes"` 162 // Deprecated: Use TraceInfo.Duration (June 2022) 163 Latency time.Duration `json:"latency"` 164 TimeToFirstByte time.Duration `json:"timetofirstbyte"` 165 } 166 167 // TraceRequestInfo represents trace of http request 168 type TraceRequestInfo struct { 169 Time time.Time `json:"time"` 170 Proto string `json:"proto"` 171 Method string `json:"method"` 172 Path string `json:"path,omitempty"` 173 RawQuery string `json:"rawquery,omitempty"` 174 Headers http.Header `json:"headers,omitempty"` 175 Body []byte `json:"body,omitempty"` 176 Client string `json:"client"` 177 } 178 179 // TraceResponseInfo represents trace of http request 180 type TraceResponseInfo struct { 181 Time time.Time `json:"time"` 182 Headers http.Header `json:"headers,omitempty"` 183 Body []byte `json:"body,omitempty"` 184 StatusCode int `json:"statuscode,omitempty"` 185 }