github.com/minio/madmin-go@v1.7.5/trace.go (about) 1 // 2 // MinIO Object Storage (c) 2021 MinIO, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 package madmin 18 19 import ( 20 "math/bits" 21 "net/http" 22 "time" 23 ) 24 25 //go:generate stringer -type=TraceType -trimprefix=Trace $GOFILE 26 27 // TraceType indicates the type of the tracing Info 28 type TraceType uint64 29 30 const ( 31 // TraceOS tracing (Golang os package calls) 32 TraceOS TraceType = 1 << iota 33 // TraceStorage tracing (MinIO Storage Layer) 34 TraceStorage 35 // TraceS3 provides tracing of S3 API calls 36 TraceS3 37 // TraceInternal tracing internal (.minio.sys/...) HTTP calls 38 TraceInternal 39 // TraceScanner will trace scan operations. 40 TraceScanner 41 // TraceDecommission will trace decommission operations. 42 TraceDecommission 43 // TraceHealing will trace healing operations. 44 TraceHealing 45 // TraceBatchReplication will trace batch replication operations. 46 TraceBatchReplication 47 // TraceRebalance will trace rebalance operations 48 TraceRebalance 49 // TraceReplicationResync will trace replication resync operations. 50 TraceReplicationResync 51 // Add more here... 52 53 // TraceAll contains all valid trace modes. 54 // This *must* be the last entry. 55 TraceAll TraceType = (1 << iota) - 1 56 ) 57 58 // Contains returns whether all flags in other is present in t. 59 func (t TraceType) Contains(other TraceType) bool { 60 return t&other == other 61 } 62 63 // Overlaps returns whether any flags in t overlaps with other. 64 func (t TraceType) Overlaps(other TraceType) bool { 65 return t&other != 0 66 } 67 68 // SingleType returns whether t has a single type set. 69 func (t TraceType) SingleType() bool { 70 // Include 71 return bits.OnesCount64(uint64(t)) == 1 72 } 73 74 // Merge will merge other into t. 75 func (t *TraceType) Merge(other TraceType) { 76 *t = *t | other 77 } 78 79 // SetIf will add other if b is true. 80 func (t *TraceType) SetIf(b bool, other TraceType) { 81 if b { 82 *t = *t | other 83 } 84 } 85 86 // Mask returns the trace type as uint32. 87 func (t TraceType) Mask() uint64 { 88 return uint64(t) 89 } 90 91 // TraceInfo - represents a trace record, additionally 92 // also reports errors if any while listening on trace. 93 type TraceInfo struct { 94 TraceType TraceType `json:"type"` 95 96 NodeName string `json:"nodename"` 97 FuncName string `json:"funcname"` 98 Time time.Time `json:"time"` 99 Path string `json:"path"` 100 Duration time.Duration `json:"dur"` 101 102 Message string `json:"msg,omitempty"` 103 Error string `json:"error,omitempty"` 104 HTTP *TraceHTTPStats `json:"http,omitempty"` 105 HealResult *HealResultItem `json:"healResult,omitempty"` 106 } 107 108 // Mask returns the trace type as uint32. 109 func (t TraceInfo) Mask() uint64 { 110 return t.TraceType.Mask() 111 } 112 113 // traceInfoLegacy - represents a trace record, additionally 114 // also reports errors if any while listening on trace. 115 // For minio versions before July 2022. 116 type traceInfoLegacy struct { 117 TraceInfo 118 119 ReqInfo *TraceRequestInfo `json:"request"` 120 RespInfo *TraceResponseInfo `json:"response"` 121 CallStats *TraceCallStats `json:"stats"` 122 123 StorageStats *struct { 124 Path string `json:"path"` 125 Duration time.Duration `json:"duration"` 126 } `json:"storageStats"` 127 OSStats *struct { 128 Path string `json:"path"` 129 Duration time.Duration `json:"duration"` 130 } `json:"osStats"` 131 } 132 133 type TraceHTTPStats struct { 134 ReqInfo TraceRequestInfo `json:"request"` 135 RespInfo TraceResponseInfo `json:"response"` 136 CallStats TraceCallStats `json:"stats"` 137 } 138 139 // TraceCallStats records request stats 140 type TraceCallStats struct { 141 InputBytes int `json:"inputbytes"` 142 OutputBytes int `json:"outputbytes"` 143 // Deprecated: Use TraceInfo.Duration (June 2022) 144 Latency time.Duration `json:"latency"` 145 TimeToFirstByte time.Duration `json:"timetofirstbyte"` 146 } 147 148 // TraceRequestInfo represents trace of http request 149 type TraceRequestInfo struct { 150 Time time.Time `json:"time"` 151 Proto string `json:"proto"` 152 Method string `json:"method"` 153 Path string `json:"path,omitempty"` 154 RawQuery string `json:"rawquery,omitempty"` 155 Headers http.Header `json:"headers,omitempty"` 156 Body []byte `json:"body,omitempty"` 157 Client string `json:"client"` 158 } 159 160 // TraceResponseInfo represents trace of http request 161 type TraceResponseInfo struct { 162 Time time.Time `json:"time"` 163 Headers http.Header `json:"headers,omitempty"` 164 Body []byte `json:"body,omitempty"` 165 StatusCode int `json:"statuscode,omitempty"` 166 }