-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclustermgr_searchindex.go
94 lines (82 loc) · 1.96 KB
/
clustermgr_searchindex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package gocbm
import (
"encoding/json"
"fmt"
"io"
"sync"
"time"
"github.com/couchbase/gocbcore/v9"
)
type GetIndexStatsOpts struct {
MemdAddrs []string
HTTPAddrs []string
Username string
Password string
AgentGroupConfig *gocbcore.AgentGroupConfig
IndexName string
}
func GetIndexStats(opts GetIndexStatsOpts) (*IndexStatsResponse, error) {
agentGroup, err := gocbcore.CreateAgentGroup(opts.GetAgentGroupConfig())
if err != nil {
return nil, err
}
coreReq := &gocbcore.HTTPRequest{
Service: gocbcore.FtsService,
Method: "GET",
Path: fmt.Sprintf("/api/stats/index/%s", opts.IndexName),
}
var wg = &sync.WaitGroup{}
var innerErr error
var innerData []byte
wg.Add(1)
_, err = agentGroup.DoHTTPRequest(coreReq, func(response *gocbcore.HTTPResponse, err error) {
defer wg.Done()
if err != nil {
innerErr = err
}
data, err := io.ReadAll(response.Body)
if err != nil {
innerErr = err
}
innerData = data
})
if err != nil {
return nil, err
}
wg.Wait()
if innerErr != nil {
return nil, innerErr
}
var resp IndexStatsResponse
err = json.Unmarshal(innerData, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (opts GetIndexStatsOpts) GetAgentGroupConfig() *gocbcore.AgentGroupConfig {
if opts.AgentGroupConfig != nil {
return opts.AgentGroupConfig
}
return &gocbcore.AgentGroupConfig{
AgentConfig: gocbcore.AgentConfig{
MemdAddrs: opts.MemdAddrs,
HTTPAddrs: opts.HTTPAddrs,
UserAgent: "gocb/v2.2.4", // I don't care
Auth: gocbcore.PasswordAuthProvider{
Username: opts.Username,
Password: opts.Password,
},
UseMutationTokens: true,
UseDurations: true,
UseOutOfOrderResponses: true,
UseCollections: true,
ConnectTimeout: 10000000000,
KVConnectTimeout: 7 * time.Second,
NoRootTraceSpans: true,
DefaultRetryStrategy: nil,
CircuitBreakerConfig: gocbcore.CircuitBreakerConfig{},
UseZombieLogger: true,
},
}
}