Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Jan 5, 2024
1 parent 01c380c commit aa1eeb8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 8 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,16 @@ func NewClientWithPolicyAndHost(policy *ClientPolicy, hosts ...*Host) (*Client,

// Metrics

func (clnt *Client) EnableMetrics(policy *MetricsPolicy) {
clnt.cluster.enableMetrics(policy)
// Enable extended periodic cluster and node latency metrics.
func (clnt *Client) EnableMetrics(policy *MetricsPolicy) error {
err := clnt.cluster.enableMetrics(policy)
if err != nil {
return err
}
return nil
}

// Disable extended periodic cluster and node latency metrics.
func (clnt *Client) DisableMetrics() {
clnt.cluster.disableMetrics()
}
Expand Down
14 changes: 9 additions & 5 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,16 @@ func NewCluster(policy *ClientPolicy, hosts []*Host) (*Cluster, Error) {
return newCluster, err
}

func (clstr *Cluster) enableMetrics(policy *MetricsPolicy) {
func (clstr *Cluster) enableMetrics(policy *MetricsPolicy) error {
if clstr.metricsEnabled {
clstr.metricsListener.onDisable(clstr)
// Disable the old metrics listener
err := clstr.metricsListener.onDisable(clstr)
if err != nil {
return err
}
}

var listener MetricsListener = *policy.listener
var listener MetricsListener = policy.listener

if listener == nil {
listener = &MetricsWriter{dir: policy.reportDir}
Expand Down Expand Up @@ -452,7 +456,7 @@ func (clstr *Cluster) tend() Error {
}

if clstr.metricsEnabled && clstr.tendCount%clstr.metricsPolicy.interval == 0 {
(*clstr.metricsListener).onSnapshot(clstr)
clstr.metricsListener.onSnapshot(clstr)
}

return nil
Expand Down Expand Up @@ -830,7 +834,7 @@ func (clstr *Cluster) removeNodes(nodesToRemove []*Node) {
})

if clstr.metricsEnabled {
err := (*clstr.metricsListener).onNodeClose(node)
err := clstr.metricsListener.onNodeClose(node)
if err != nil {
logger.Logger.Warn("Write metrics failed on " + node.name + ": " + err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion metrics_policy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aerospike

type MetricsPolicy struct {
listener *MetricsListener
listener MetricsListener
reportDir string
interval int
latencyColumns int
Expand Down

0 comments on commit aa1eeb8

Please sign in to comment.