api.nodes.hot_threads.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // Licensed to Elasticsearch B.V. under one or more contributor
  2. // license agreements. See the NOTICE file distributed with
  3. // this work for additional information regarding copyright
  4. // ownership. Elasticsearch B.V. licenses this file to you under
  5. // the Apache License, Version 2.0 (the "License"); you may
  6. // not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. //
  18. // Code generated from specification version 7.17.10: DO NOT EDIT
  19. package esapi
  20. import (
  21. "context"
  22. "net/http"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. func newNodesHotThreadsFunc(t Transport) NodesHotThreads {
  28. return func(o ...func(*NodesHotThreadsRequest)) (*Response, error) {
  29. var r = NodesHotThreadsRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // NodesHotThreads returns information about hot threads on each node in the cluster.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html.
  40. type NodesHotThreads func(o ...func(*NodesHotThreadsRequest)) (*Response, error)
  41. // NodesHotThreadsRequest configures the Nodes Hot Threads API request.
  42. type NodesHotThreadsRequest struct {
  43. NodeID []string
  44. IgnoreIdleThreads *bool
  45. Interval time.Duration
  46. Snapshots *int
  47. Sort string
  48. Threads *int
  49. Timeout time.Duration
  50. DocumentType string
  51. Pretty bool
  52. Human bool
  53. ErrorTrace bool
  54. FilterPath []string
  55. Header http.Header
  56. ctx context.Context
  57. }
  58. // Do executes the request and returns response or error.
  59. func (r NodesHotThreadsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  60. var (
  61. method string
  62. path strings.Builder
  63. params map[string]string
  64. )
  65. method = "GET"
  66. path.Grow(1 + len("_cluster") + 1 + len("nodes") + 1 + len(strings.Join(r.NodeID, ",")) + 1 + len("hot_threads"))
  67. path.WriteString("/")
  68. path.WriteString("_cluster")
  69. path.WriteString("/")
  70. path.WriteString("nodes")
  71. if len(r.NodeID) > 0 {
  72. path.WriteString("/")
  73. path.WriteString(strings.Join(r.NodeID, ","))
  74. }
  75. path.WriteString("/")
  76. path.WriteString("hot_threads")
  77. params = make(map[string]string)
  78. if r.IgnoreIdleThreads != nil {
  79. params["ignore_idle_threads"] = strconv.FormatBool(*r.IgnoreIdleThreads)
  80. }
  81. if r.Interval != 0 {
  82. params["interval"] = formatDuration(r.Interval)
  83. }
  84. if r.Snapshots != nil {
  85. params["snapshots"] = strconv.FormatInt(int64(*r.Snapshots), 10)
  86. }
  87. if r.Sort != "" {
  88. params["sort"] = r.Sort
  89. }
  90. if r.Threads != nil {
  91. params["threads"] = strconv.FormatInt(int64(*r.Threads), 10)
  92. }
  93. if r.Timeout != 0 {
  94. params["timeout"] = formatDuration(r.Timeout)
  95. }
  96. if r.DocumentType != "" {
  97. params["type"] = r.DocumentType
  98. }
  99. if r.Pretty {
  100. params["pretty"] = "true"
  101. }
  102. if r.Human {
  103. params["human"] = "true"
  104. }
  105. if r.ErrorTrace {
  106. params["error_trace"] = "true"
  107. }
  108. if len(r.FilterPath) > 0 {
  109. params["filter_path"] = strings.Join(r.FilterPath, ",")
  110. }
  111. req, err := newRequest(method, path.String(), nil)
  112. if err != nil {
  113. return nil, err
  114. }
  115. if len(params) > 0 {
  116. q := req.URL.Query()
  117. for k, v := range params {
  118. q.Set(k, v)
  119. }
  120. req.URL.RawQuery = q.Encode()
  121. }
  122. if len(r.Header) > 0 {
  123. if len(req.Header) == 0 {
  124. req.Header = r.Header
  125. } else {
  126. for k, vv := range r.Header {
  127. for _, v := range vv {
  128. req.Header.Add(k, v)
  129. }
  130. }
  131. }
  132. }
  133. if ctx != nil {
  134. req = req.WithContext(ctx)
  135. }
  136. res, err := transport.Perform(req)
  137. if err != nil {
  138. return nil, err
  139. }
  140. response := Response{
  141. StatusCode: res.StatusCode,
  142. Body: res.Body,
  143. Header: res.Header,
  144. }
  145. return &response, nil
  146. }
  147. // WithContext sets the request context.
  148. func (f NodesHotThreads) WithContext(v context.Context) func(*NodesHotThreadsRequest) {
  149. return func(r *NodesHotThreadsRequest) {
  150. r.ctx = v
  151. }
  152. }
  153. // WithNodeID - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes.
  154. func (f NodesHotThreads) WithNodeID(v ...string) func(*NodesHotThreadsRequest) {
  155. return func(r *NodesHotThreadsRequest) {
  156. r.NodeID = v
  157. }
  158. }
  159. // WithIgnoreIdleThreads - don't show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue (default: true).
  160. func (f NodesHotThreads) WithIgnoreIdleThreads(v bool) func(*NodesHotThreadsRequest) {
  161. return func(r *NodesHotThreadsRequest) {
  162. r.IgnoreIdleThreads = &v
  163. }
  164. }
  165. // WithInterval - the interval for the second sampling of threads.
  166. func (f NodesHotThreads) WithInterval(v time.Duration) func(*NodesHotThreadsRequest) {
  167. return func(r *NodesHotThreadsRequest) {
  168. r.Interval = v
  169. }
  170. }
  171. // WithSnapshots - number of samples of thread stacktrace (default: 10).
  172. func (f NodesHotThreads) WithSnapshots(v int) func(*NodesHotThreadsRequest) {
  173. return func(r *NodesHotThreadsRequest) {
  174. r.Snapshots = &v
  175. }
  176. }
  177. // WithSort - the sort order for 'cpu' type (default: total).
  178. func (f NodesHotThreads) WithSort(v string) func(*NodesHotThreadsRequest) {
  179. return func(r *NodesHotThreadsRequest) {
  180. r.Sort = v
  181. }
  182. }
  183. // WithThreads - specify the number of threads to provide information for (default: 3).
  184. func (f NodesHotThreads) WithThreads(v int) func(*NodesHotThreadsRequest) {
  185. return func(r *NodesHotThreadsRequest) {
  186. r.Threads = &v
  187. }
  188. }
  189. // WithTimeout - explicit operation timeout.
  190. func (f NodesHotThreads) WithTimeout(v time.Duration) func(*NodesHotThreadsRequest) {
  191. return func(r *NodesHotThreadsRequest) {
  192. r.Timeout = v
  193. }
  194. }
  195. // WithDocumentType - the type to sample (default: cpu).
  196. func (f NodesHotThreads) WithDocumentType(v string) func(*NodesHotThreadsRequest) {
  197. return func(r *NodesHotThreadsRequest) {
  198. r.DocumentType = v
  199. }
  200. }
  201. // WithPretty makes the response body pretty-printed.
  202. func (f NodesHotThreads) WithPretty() func(*NodesHotThreadsRequest) {
  203. return func(r *NodesHotThreadsRequest) {
  204. r.Pretty = true
  205. }
  206. }
  207. // WithHuman makes statistical values human-readable.
  208. func (f NodesHotThreads) WithHuman() func(*NodesHotThreadsRequest) {
  209. return func(r *NodesHotThreadsRequest) {
  210. r.Human = true
  211. }
  212. }
  213. // WithErrorTrace includes the stack trace for errors in the response body.
  214. func (f NodesHotThreads) WithErrorTrace() func(*NodesHotThreadsRequest) {
  215. return func(r *NodesHotThreadsRequest) {
  216. r.ErrorTrace = true
  217. }
  218. }
  219. // WithFilterPath filters the properties of the response body.
  220. func (f NodesHotThreads) WithFilterPath(v ...string) func(*NodesHotThreadsRequest) {
  221. return func(r *NodesHotThreadsRequest) {
  222. r.FilterPath = v
  223. }
  224. }
  225. // WithHeader adds the headers to the HTTP request.
  226. func (f NodesHotThreads) WithHeader(h map[string]string) func(*NodesHotThreadsRequest) {
  227. return func(r *NodesHotThreadsRequest) {
  228. if r.Header == nil {
  229. r.Header = make(http.Header)
  230. }
  231. for k, v := range h {
  232. r.Header.Add(k, v)
  233. }
  234. }
  235. }
  236. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  237. func (f NodesHotThreads) WithOpaqueID(s string) func(*NodesHotThreadsRequest) {
  238. return func(r *NodesHotThreadsRequest) {
  239. if r.Header == nil {
  240. r.Header = make(http.Header)
  241. }
  242. r.Header.Set("X-Opaque-Id", s)
  243. }
  244. }