github.com/opensearch-project/opensearch-go/v2@v2.3.0/opensearchapi/api.cat.thread_pool.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // 3 // The OpenSearch Contributors require contributions made to 4 // this file be licensed under the Apache-2.0 license or a 5 // compatible open source license. 6 // 7 // Modifications Copyright OpenSearch Contributors. See 8 // GitHub history for details. 9 10 // Licensed to Elasticsearch B.V. under one or more contributor 11 // license agreements. See the NOTICE file distributed with 12 // this work for additional information regarding copyright 13 // ownership. Elasticsearch B.V. licenses this file to you under 14 // the Apache License, Version 2.0 (the "License"); you may 15 // not use this file except in compliance with the License. 16 // You may obtain a copy of the License at 17 // 18 // http://www.apache.org/licenses/LICENSE-2.0 19 // 20 // Unless required by applicable law or agreed to in writing, 21 // software distributed under the License is distributed on an 22 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 23 // KIND, either express or implied. See the License for the 24 // specific language governing permissions and limitations 25 // under the License. 26 27 package opensearchapi 28 29 import ( 30 "context" 31 "net/http" 32 "strconv" 33 "strings" 34 "time" 35 ) 36 37 func newCatThreadPoolFunc(t Transport) CatThreadPool { 38 return func(o ...func(*CatThreadPoolRequest)) (*Response, error) { 39 var r = CatThreadPoolRequest{} 40 for _, f := range o { 41 f(&r) 42 } 43 return r.Do(r.ctx, t) 44 } 45 } 46 47 // ----- API Definition ------------------------------------------------------- 48 49 // CatThreadPool returns cluster-wide thread pool statistics per node. 50 // By default the active, queue and rejected statistics are returned for all thread pools. 51 // 52 // 53 type CatThreadPool func(o ...func(*CatThreadPoolRequest)) (*Response, error) 54 55 // CatThreadPoolRequest configures the Cat Thread Pool API request. 56 // 57 type CatThreadPoolRequest struct { 58 ThreadPoolPatterns []string 59 60 Format string 61 H []string 62 Help *bool 63 Local *bool 64 MasterTimeout time.Duration 65 ClusterManagerTimeout time.Duration 66 S []string 67 Size string 68 V *bool 69 70 Pretty bool 71 Human bool 72 ErrorTrace bool 73 FilterPath []string 74 75 Header http.Header 76 77 ctx context.Context 78 } 79 80 // Do executes the request and returns response or error. 81 // 82 func (r CatThreadPoolRequest) Do(ctx context.Context, transport Transport) (*Response, error) { 83 var ( 84 method string 85 path strings.Builder 86 params map[string]string 87 ) 88 89 method = "GET" 90 91 path.Grow(1 + len("_cat") + 1 + len("thread_pool") + 1 + len(strings.Join(r.ThreadPoolPatterns, ","))) 92 path.WriteString("/") 93 path.WriteString("_cat") 94 path.WriteString("/") 95 path.WriteString("thread_pool") 96 if len(r.ThreadPoolPatterns) > 0 { 97 path.WriteString("/") 98 path.WriteString(strings.Join(r.ThreadPoolPatterns, ",")) 99 } 100 101 params = make(map[string]string) 102 103 if r.Format != "" { 104 params["format"] = r.Format 105 } 106 107 if len(r.H) > 0 { 108 params["h"] = strings.Join(r.H, ",") 109 } 110 111 if r.Help != nil { 112 params["help"] = strconv.FormatBool(*r.Help) 113 } 114 115 if r.Local != nil { 116 params["local"] = strconv.FormatBool(*r.Local) 117 } 118 119 if r.MasterTimeout != 0 { 120 params["master_timeout"] = formatDuration(r.MasterTimeout) 121 } 122 123 if r.ClusterManagerTimeout != 0 { 124 params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout) 125 } 126 127 if len(r.S) > 0 { 128 params["s"] = strings.Join(r.S, ",") 129 } 130 131 if r.Size != "" { 132 params["size"] = r.Size 133 } 134 135 if r.V != nil { 136 params["v"] = strconv.FormatBool(*r.V) 137 } 138 139 if r.Pretty { 140 params["pretty"] = "true" 141 } 142 143 if r.Human { 144 params["human"] = "true" 145 } 146 147 if r.ErrorTrace { 148 params["error_trace"] = "true" 149 } 150 151 if len(r.FilterPath) > 0 { 152 params["filter_path"] = strings.Join(r.FilterPath, ",") 153 } 154 155 req, err := newRequest(method, path.String(), nil) 156 if err != nil { 157 return nil, err 158 } 159 160 if len(params) > 0 { 161 q := req.URL.Query() 162 for k, v := range params { 163 q.Set(k, v) 164 } 165 req.URL.RawQuery = q.Encode() 166 } 167 168 if len(r.Header) > 0 { 169 if len(req.Header) == 0 { 170 req.Header = r.Header 171 } else { 172 for k, vv := range r.Header { 173 for _, v := range vv { 174 req.Header.Add(k, v) 175 } 176 } 177 } 178 } 179 180 if ctx != nil { 181 req = req.WithContext(ctx) 182 } 183 184 res, err := transport.Perform(req) 185 if err != nil { 186 return nil, err 187 } 188 189 response := Response{ 190 StatusCode: res.StatusCode, 191 Body: res.Body, 192 Header: res.Header, 193 } 194 195 return &response, nil 196 } 197 198 // WithContext sets the request context. 199 // 200 func (f CatThreadPool) WithContext(v context.Context) func(*CatThreadPoolRequest) { 201 return func(r *CatThreadPoolRequest) { 202 r.ctx = v 203 } 204 } 205 206 // WithThreadPoolPatterns - a list of regular-expressions to filter the thread pools in the output. 207 // 208 func (f CatThreadPool) WithThreadPoolPatterns(v ...string) func(*CatThreadPoolRequest) { 209 return func(r *CatThreadPoolRequest) { 210 r.ThreadPoolPatterns = v 211 } 212 } 213 214 // WithFormat - a short version of the accept header, e.g. json, yaml. 215 // 216 func (f CatThreadPool) WithFormat(v string) func(*CatThreadPoolRequest) { 217 return func(r *CatThreadPoolRequest) { 218 r.Format = v 219 } 220 } 221 222 // WithH - comma-separated list of column names to display. 223 // 224 func (f CatThreadPool) WithH(v ...string) func(*CatThreadPoolRequest) { 225 return func(r *CatThreadPoolRequest) { 226 r.H = v 227 } 228 } 229 230 // WithHelp - return help information. 231 // 232 func (f CatThreadPool) WithHelp(v bool) func(*CatThreadPoolRequest) { 233 return func(r *CatThreadPoolRequest) { 234 r.Help = &v 235 } 236 } 237 238 // WithLocal - return local information, do not retrieve the state from cluster-manager node (default: false). 239 // 240 func (f CatThreadPool) WithLocal(v bool) func(*CatThreadPoolRequest) { 241 return func(r *CatThreadPoolRequest) { 242 r.Local = &v 243 } 244 } 245 246 // WithMasterTimeout - explicit operation timeout for connection to cluster-manager node. 247 // 248 // Deprecated: To promote inclusive language, use WithClusterManagerTimeout instead. 249 // 250 func (f CatThreadPool) WithMasterTimeout(v time.Duration) func(*CatThreadPoolRequest) { 251 return func(r *CatThreadPoolRequest) { 252 r.MasterTimeout = v 253 } 254 } 255 256 // WithClusterManagerTimeout - explicit operation timeout for connection to cluster-manager node. 257 // 258 func (f CatThreadPool) WithClusterManagerTimeout(v time.Duration) func(*CatThreadPoolRequest) { 259 return func(r *CatThreadPoolRequest) { 260 r.ClusterManagerTimeout = v 261 } 262 } 263 264 // WithS - comma-separated list of column names or column aliases to sort by. 265 // 266 func (f CatThreadPool) WithS(v ...string) func(*CatThreadPoolRequest) { 267 return func(r *CatThreadPoolRequest) { 268 r.S = v 269 } 270 } 271 272 // WithSize - the multiplier in which to display values. 273 // 274 func (f CatThreadPool) WithSize(v string) func(*CatThreadPoolRequest) { 275 return func(r *CatThreadPoolRequest) { 276 r.Size = v 277 } 278 } 279 280 // WithV - verbose mode. display column headers. 281 // 282 func (f CatThreadPool) WithV(v bool) func(*CatThreadPoolRequest) { 283 return func(r *CatThreadPoolRequest) { 284 r.V = &v 285 } 286 } 287 288 // WithPretty makes the response body pretty-printed. 289 // 290 func (f CatThreadPool) WithPretty() func(*CatThreadPoolRequest) { 291 return func(r *CatThreadPoolRequest) { 292 r.Pretty = true 293 } 294 } 295 296 // WithHuman makes statistical values human-readable. 297 // 298 func (f CatThreadPool) WithHuman() func(*CatThreadPoolRequest) { 299 return func(r *CatThreadPoolRequest) { 300 r.Human = true 301 } 302 } 303 304 // WithErrorTrace includes the stack trace for errors in the response body. 305 // 306 func (f CatThreadPool) WithErrorTrace() func(*CatThreadPoolRequest) { 307 return func(r *CatThreadPoolRequest) { 308 r.ErrorTrace = true 309 } 310 } 311 312 // WithFilterPath filters the properties of the response body. 313 // 314 func (f CatThreadPool) WithFilterPath(v ...string) func(*CatThreadPoolRequest) { 315 return func(r *CatThreadPoolRequest) { 316 r.FilterPath = v 317 } 318 } 319 320 // WithHeader adds the headers to the HTTP request. 321 // 322 func (f CatThreadPool) WithHeader(h map[string]string) func(*CatThreadPoolRequest) { 323 return func(r *CatThreadPoolRequest) { 324 if r.Header == nil { 325 r.Header = make(http.Header) 326 } 327 for k, v := range h { 328 r.Header.Add(k, v) 329 } 330 } 331 } 332 333 // WithOpaqueID adds the X-Opaque-Id header to the HTTP request. 334 // 335 func (f CatThreadPool) WithOpaqueID(s string) func(*CatThreadPoolRequest) { 336 return func(r *CatThreadPoolRequest) { 337 if r.Header == nil { 338 r.Header = make(http.Header) 339 } 340 r.Header.Set("X-Opaque-Id", s) 341 } 342 }