Skip to content

Commit

Permalink
Merge pull request #94 from github/hugodorea/adds-get-hot-threads-method
Browse files Browse the repository at this point in the history
adds GetHotThreads to es client
  • Loading branch information
hugodorea authored Aug 5, 2022
2 parents 52b6235 + 82f76f4 commit 7a2cf52
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.44.2
version: v1.46.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
10 changes: 10 additions & 0 deletions es.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,3 +1513,13 @@ func (c *Client) ReloadSecureSettingsWithPassword(password string) (ReloadSecure

return response, nil
}

// GetHotThreads allows to get the current hot threads on each node in the cluster
func (c *Client) GetHotThreads() (string, error) {
body, err := handleErrWithBytes(c.buildGetRequest("_nodes/hot_threads"))
if err != nil {
return "", err
}

return string(body), nil
}
31 changes: 31 additions & 0 deletions es_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2042,3 +2042,34 @@ func TestReloadSecureSettingsWithPassword(t *testing.T) {
t.Errorf("Expected to parse bad node response correctly, got %#v", goodNode)
}
}

func TestGetHotThreads(t *testing.T) {
testSetup := &ServerSetup{
Method: "GET",
Path: "/_nodes/hot_threads",
Response: `
::: {Mister Sinister}{c0k7r8tKS0CGObWF7yzgQQ}{127.0.0.1}{127.0.0.1:9300}
Hot threads at 2022-08-04T20:30:34.357Z, interval=500ms, busiestThreads=3, ignoreIdleThreads=true:
0.0% (172.8micros out of 500ms) cpu usage by thread 'elasticsearch[Mister Sinister][transport_client_timer][T#1]{Hashed wheel timer #1}'
10/10 snapshots sharing following 5 elements
[email protected]/java.lang.Thread.sleep(Native Method)
app//org.jboss.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:445)
app//org.jboss.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:364)
app//org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
[email protected]/java.lang.Thread.run(Thread.java:829)`,
}

host, port, ts := setupTestServers(t, []*ServerSetup{testSetup})
defer ts.Close()
client := NewClient(host, port)

hotThreads, err := client.GetHotThreads()
if err != nil {
t.Fatalf("Unexpected error expected nil, got %s", err)
}

if hotThreads != testSetup.Response {
t.Errorf("Unexpected response. got %v want %v", hotThreads, testSetup.Response)
}
}

0 comments on commit 7a2cf52

Please sign in to comment.