Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy-connections #191

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/cmd/monitor_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var validPanels = []panelImpl{
createContentPanel(8, "network-stats", "Network Stats", "show network stats", networkStatsContent),
createContentPanel(8, "persistence", "Persistence", "show persistence", persistenceContent),
createContentPanel(8, "proxies", "Proxy Servers", "show proxy servers", proxiesContent),
createContentPanel(8, "proxy-connections", "Proxy Connections (%SERVICE)", "show proxy connections", proxyConnectionsContent),
createContentPanel(8, "reporters", "Reporters", "show reporters", reportersContent),
createContentPanel(8, "services", "Services", "show services", servicesContent),
createContentPanel(8, "service-members", "Service Members (%SERVICE)", "show service members", serviceMembersContent),
Expand Down Expand Up @@ -738,6 +739,19 @@ var proxiesContentInternal = func(protocol string, clusterSummary clusterSummary
return strings.Split(FormatProxyServers(proxiesSummary.Proxies, protocol), "\n"), nil
}

var proxyConnectionsContent = func(dataFetcher fetcher.Fetcher, clusterSummary clusterSummaryInfo) ([]string, error) {
if serviceName == "" {
return emptyStringArray, errSelectService
}

connectionDetailsFinal, err := getProxyConnections(dataFetcher, serviceName)
if err != nil {
return emptyStringArray, err
}

return strings.Split(FormatProxyConnections(connectionDetailsFinal), "\n"), nil
}

var cacheAccessContent = func(dataFetcher fetcher.Fetcher, clusterSummary clusterSummaryInfo) ([]string, error) {
return getCacheContent(dataFetcher, "access")
}
Expand Down
120 changes: 65 additions & 55 deletions pkg/cmd/proxy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
* Copyright (c) 2021, 2024 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -183,67 +183,15 @@ var getProxyConnectionsCmd = &cobra.Command{

for {
var (
proxiesSummary = config.ProxiesSummary{}
connectionDetailsFinal = make([]config.ProxyConnection, 0)
connectionDetailsFinal []config.ProxyConnection
connectionsResult []byte
proxyResults []byte
wg sync.WaitGroup
errorSink = createErrorSink()
m = sync.RWMutex{}
)

proxyResults, err = dataFetcher.GetProxySummaryJSON()
connectionDetailsFinal, err = getProxyConnections(dataFetcher, serviceName)
if err != nil {
return err
}

if len(proxyResults) == 0 {
return fmt.Errorf("%s '%s'", proxyErrorMsg, serviceName)
}

err = json.Unmarshal(proxyResults, &proxiesSummary)
if err != nil {
return err
}

nodeIds := getProxyNodeIDs(serviceName, proxiesSummary)
nodeIdsLen := len(nodeIds)

if nodeIdsLen == 0 {
return fmt.Errorf("%s '%s'", proxyErrorMsg, serviceName)
}

wg.Add(nodeIdsLen)

// retrieve all connection details from JSON
for i := range nodeIds {
go func(nodeID string) {
defer wg.Done()
connectionDetails := config.ProxyConnections{}
data, err1 := dataFetcher.GetProxyConnectionsJSON(serviceName, nodeID)
if err1 != nil {
errorSink.AppendError(err1)
return
}
err1 = json.Unmarshal(data, &connectionDetails)
if err1 != nil {
errorSink.AppendError(err1)
return
}
// protect the slice for update
m.Lock()
defer m.Unlock()
connectionDetailsFinal = append(connectionDetailsFinal, connectionDetails.Proxies...)
}(nodeIds[i])
}

// wait for the results
wg.Wait()
errorList := errorSink.GetErrors()
if len(errorList) > 0 {
return utils.GetErrors(errorList)
}

if strings.Contains(OutputFormat, constants.JSONPATH) || OutputFormat == constants.JSON {
connectionsResult, err = json.Marshal(connectionDetailsFinal)
if err != nil {
Expand Down Expand Up @@ -277,6 +225,68 @@ var getProxyConnectionsCmd = &cobra.Command{
},
}

func getProxyConnections(dataFetcher fetcher.Fetcher, proxyService string) ([]config.ProxyConnection, error) {
var (
wg sync.WaitGroup
errorSink = createErrorSink()
m = sync.RWMutex{}
err error
connectionDetailsFinal = make([]config.ProxyConnection, 0)
proxyResults []byte
proxiesSummary = config.ProxiesSummary{}
)

proxyResults, err = dataFetcher.GetProxySummaryJSON()
if err != nil {
return connectionDetailsFinal, err
}

err = json.Unmarshal(proxyResults, &proxiesSummary)
if err != nil {
return connectionDetailsFinal, err
}

nodeIds := getProxyNodeIDs(proxyService, proxiesSummary)
nodeIdsLen := len(nodeIds)

if nodeIdsLen == 0 {
return connectionDetailsFinal, fmt.Errorf("%s '%s'", proxyErrorMsg, proxyService)
}

wg.Add(nodeIdsLen)

// retrieve all connection details from JSON
for i := range nodeIds {
go func(nodeID string) {
defer wg.Done()
connectionDetails := config.ProxyConnections{}
data, err1 := dataFetcher.GetProxyConnectionsJSON(proxyService, nodeID)
if err1 != nil {
errorSink.AppendError(err1)
return
}
err1 = json.Unmarshal(data, &connectionDetails)
if err1 != nil {
errorSink.AppendError(err1)
return
}
// protect the slice for update
m.Lock()
defer m.Unlock()
connectionDetailsFinal = append(connectionDetailsFinal, connectionDetails.Proxies...)
}(nodeIds[i])
}

// wait for the results
wg.Wait()
errorList := errorSink.GetErrors()
if len(errorList) > 0 {
return connectionDetailsFinal, utils.GetErrors(errorList)
}

return connectionDetailsFinal, nil
}

func getProxyNodeIDs(selectedService string, proxiesSummary config.ProxiesSummary) []string {
// get a list of node Id's while we search for the service name
nodeIDs := make([]string, 0)
Expand Down
Loading