Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilvirus committed Dec 17, 2024
2 parents b7454fc + b7133c5 commit 9620a55
Show file tree
Hide file tree
Showing 22 changed files with 2,180 additions and 1,949 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
aerospike-prometheus-exporter

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/procfs v0.12.0
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.1
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.1 h1:Ou41VVR3nMWWmTiEUnj0OlsgOSCUFgsPAOl6jRIcVtQ=
github.com/sirupsen/logrus v1.9.1/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/commons/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Constants, common variables and helper functions
const (
TESTS_DEFAULT_CONFIG_FILE = "tests_data/default_ape.toml"
TESTS_USERS_CONFIG_FILE = "tests_data/users_ape.toml"
TESTS_USERS_PKI_CONFIG_FILE = "tests_data/users_pki_ape.toml"
TESTS_MOCK_CONFIG_FILE = "tests_data/mock_ape.toml"
TESTS_DEFAULT_GAUGE_LIST_FILE = "configs/gauge_stats_list.toml"
)
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (c *Config) ValidateAndUpdate(md toml.MetaData) {
if c.Aerospike.AuthMode == "" {
c.Aerospike.AuthMode = "internal"
}
c.Aerospike.AuthMode = strings.ToLower(strings.TrimSpace(c.Aerospike.AuthMode))

if c.Aerospike.Timeout == 0 {
c.Aerospike.Timeout = 5
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/config/tests/gauge_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
GAUGES_NAMESPACES_COUNT = 99
GAUGES_NAMESPACES_COUNT = 110
GAUGES_NODE_STATS_COUNT = 69
GAUGES_SETS_COUNT = 9
GAUGES_SINDEX_COUNT = 13
Expand Down
4 changes: 1 addition & 3 deletions internal/pkg/dataprovider/aero_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func initializeAndConnectAerospikeServer() (*aero.Connection, error) {
clientPolicy.User = string(username)
clientPolicy.Password = string(password)

authMode := strings.ToLower(strings.TrimSpace(config.Cfg.Aerospike.AuthMode))

switch authMode {
switch config.Cfg.Aerospike.AuthMode {
case "internal", "":
clientPolicy.AuthMode = aero.AuthModeInternal
case "external":
Expand Down
30 changes: 12 additions & 18 deletions internal/pkg/statprocessors/sp_latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,23 @@ func (lw *LatencyStatsProcessor) getLatenciesCommands(rawMetrics map[string]stri

// below latency-command are added to the auto-enabled list, i.e. latencies: command
// re-repl is auto-enabled, but not coming as part of latencies: list, hence we are adding it explicitly
//
// Hashmap content format := namespace-<histogram-key> = <0/1>
for latencyHistName := range LatencyBenchmarks {
histTokens := strings.Split(latencyHistName, "-")

histCommand := "latencies:hist="

// service-enable-benchmarks-fabric or ns-enable-benchmarks-ops-sub or service-enable-hist-info
if histTokens[0] != "service" {
histCommand = histCommand + "{" + histTokens[0] + "}-"
}

if strings.Contains(latencyHistName, "enable-benchmarks-") {
histCommand = histCommand + strings.Join(histTokens[2:], "-")
} else {
histCommand = histCommand + strings.Join(histTokens[3:], "-")
// command will be like
// latencies:hist={NAMESPACE}-proxy / latencies:hist={NAMESPACE}-benchmarks-read
// latencies:hist=info

for nsName := range NamespaceLatencyBenchmarks {
for _, latencyCommand := range NamespaceLatencyBenchmarks[nsName] {
histCommand := "latencies:hist=" + latencyCommand
commands = append(commands, histCommand)
}
}

for _, latencyCommand := range ServiceLatencyBenchmarks {
histCommand := "latencies:hist=" + latencyCommand
commands = append(commands, histCommand)
}

log.Tracef("latency-passtwokeys:%s", commands)
log.Tracef("latency-getLatenciesCommands:%s", commands)

return commands
}
Expand Down Expand Up @@ -126,7 +121,6 @@ func parseSingleLatenciesKey(singleLatencyKey string, rawMetrics map[string]stri

// log.Tracef("latency-stats:%+v", latencyStats)
log.Tracef("latencies-stats:%+v:%+v", singleLatencyKey, rawMetrics[singleLatencyKey])

var latencyMetricsToSend = []AerospikeStat{}

for namespaceName, nsLatencyStats := range latencyStats {
Expand Down
43 changes: 21 additions & 22 deletions internal/pkg/statprocessors/sp_namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ func (nw *NamespaceStatsProcessor) PassOneKeys() []string {

func (nw *NamespaceStatsProcessor) PassTwoKeys(rawMetrics map[string]string) []string {
s := rawMetrics[KEY_NS_METADATA]
list := strings.Split(s, ";")
nsList := strings.Split(s, ";")

log.Tracef("namespaces:%s", s)

var infoKeys []string
for _, k := range list {
for _, ns := range nsList {
// infoKey ==> namespace/test, namespace/bar
infoKeys = append(infoKeys, KEY_NS_NAMESPACE+"/"+k)
infoKeys = append(infoKeys, KEY_NS_NAMESPACE+"/"+ns)
if NamespaceLatencyBenchmarks[ns] == nil {
NamespaceLatencyBenchmarks[ns] = make(map[string]string)
}
}

if nw.canSendIndexPressureInfoKey() {
Expand Down Expand Up @@ -228,32 +231,28 @@ func (nw *NamespaceStatsProcessor) refreshNamespaceStats(singleInfoKey string, i
nsMetricsToSend = append(nsMetricsToSend, asMetric)
}

// below code section is to ensure ns+latencies combination is handled during LatencyWatcher
//
// check and if latency benchmarks stat - is it enabled (bool true==1 and false==0 after conversion)
if isStatLatencyHistRelated(stat) {
// remove old value as microbenchmark may get enabled / disable on-the-fly at server so we cannot rely on value
delete(LatencyBenchmarks, nsName+"-"+stat)

if pv == 1 {
LatencyBenchmarks[nsName+"-"+stat] = stat
}
}

// below code section is to ensure ns+latencies combination is handled during LatencyWatcher
//
// check and if latency benchmarks stat - is it enabled (bool true==1 and false==0 after conversion)
// below code section is to ensure latencies combination is handled during LatencyWatcher
if isStatLatencyHistRelated(stat) {
delete(LatencyBenchmarks, nsName+"-"+stat)

// pv==1 means histogram is enabled
if pv == 1 {
LatencyBenchmarks[nsName+"-"+stat] = stat
latencySubcommand := "{" + nsName + "}-" + stat
if strings.Contains(latencySubcommand, "enable-") {
latencySubcommand = strings.ReplaceAll(latencySubcommand, "enable-", "")
}
// some histogram stats has 'hist-' in the config, but the latency command does not expect hist- when issue the command
if strings.Contains(latencySubcommand, "hist-") {
latencySubcommand = strings.ReplaceAll(latencySubcommand, "hist-", "")
}
NamespaceLatencyBenchmarks[nsName][stat] = latencySubcommand
} else {
// pv==0 means histogram is disabled
delete(NamespaceLatencyBenchmarks[nsName], stat)
}
}

}
// append default re-repl, as this auto-enabled, but not coming as part of latencies, we need this as namespace is available only here
LatencyBenchmarks[nsName+"-latency-hist-re-repl"] = "{" + nsName + "}-re-repl"
NamespaceLatencyBenchmarks[nsName]["re-repl"] = "{" + nsName + "}-" + "re-repl"

return nsMetricsToSend
}
Expand Down
20 changes: 16 additions & 4 deletions internal/pkg/statprocessors/sp_node_stats.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package statprocessors

import (
"strings"

"github.com/aerospike/aerospike-prometheus-exporter/internal/pkg/commons"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -87,11 +89,21 @@ func (sw *NodeStatsProcessor) handleRefresh(nodeRawMetrics string) []AerospikeSt
// check and if latency benchmarks stat, is it enabled (bool true==1 and false==0 after conversion)
if isStatLatencyHistRelated(stat) {

// remove old value as microbenchmark may get enabled / disable on-the-fly at server so we cannot rely on value
delete(LatencyBenchmarks, "service-"+stat)

// pv==1 means histogram is enabled
if pv == 1 {
LatencyBenchmarks["service-"+stat] = stat
latencySubcommand := stat
if strings.Contains(latencySubcommand, "enable-") {
latencySubcommand = strings.ReplaceAll(latencySubcommand, "enable-", "")
}
// some histogram stats has 'hist-' in the config, but the latency command does not expect hist- when issue the command
if strings.Contains(latencySubcommand, "hist-") {
latencySubcommand = strings.ReplaceAll(latencySubcommand, "hist-", "")
}

ServiceLatencyBenchmarks[stat] = latencySubcommand
} else {
// pv==0 means histogram is disabled
delete(ServiceLatencyBenchmarks, stat)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/statprocessors/sp_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func (uw *UserStatsProcessor) PassTwoKeys(rawMetrics map[string]string) []string
func (uw *UserStatsProcessor) Refresh(infoKeys []string, rawMetrics map[string]string) ([]AerospikeStat, error) {

// check if security configurations are enabled
if config.Cfg.Aerospike.User == "" && config.Cfg.Aerospike.Password == "" {
if config.Cfg.Aerospike.AuthMode != "pki" &&
(config.Cfg.Aerospike.User == "" && config.Cfg.Aerospike.Password == "") {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/statprocessors/sp_xdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (xw *XdrStatsProcessor) handleRefresh(infoKeyToProcess string, xdrRawMetric
dynamicStatname := metricPrefix + stat

if !exists {
allowed := isMetricAllowed(commons.CTX_USERS, stat)
allowed := isMetricAllowed(commons.CTX_XDR, stat)
asMetric = NewAerospikeStat(commons.CTX_XDR, dynamicStatname, allowed)
xw.xdrMetrics[stat] = asMetric
}
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/statprocessors/statsprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var (
Service, ClusterName, Build string
)

var LatencyBenchmarks = make(map[string]string)
var ServiceLatencyBenchmarks = make(map[string]string)
var NamespaceLatencyBenchmarks = make(map[string]map[string]string)

type StatProcessor interface {
PassOneKeys() []string
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/statprocessors/tests/sp_latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func latency_runTestcase(t *testing.T) {
assert.Nil(t, err, "Error while latencyWatcher.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while latencyWatcher.PassTwokeys, RawMetrics is EMPTY ")

statprocessors.ClusterName = arrRawMetrics[statprocessors.Infokey_ClusterName]
statprocessors.Build = arrRawMetrics[statprocessors.Infokey_Build]
statprocessors.Service = arrRawMetrics[statprocessors.Infokey_Service]

// check the output with setsWatcher
latencyMetrics, err := latencyWatcher.Refresh(passTwoOutputs, arrRawMetrics)
assert.Nil(t, err, "Error while latencyWatcher.Refresh with passTwoOutputs ")
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/statprocessors/tests/sp_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func namespace_runTestcase(t *testing.T) {
assert.Nil(t, err, "Error while NamespaceWatcher.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while NamespaceWatcher.PassTwokeys, RawMetrics is EMPTY ")

statprocessors.ClusterName = arrRawMetrics[statprocessors.Infokey_ClusterName]
statprocessors.Build = arrRawMetrics[statprocessors.Infokey_Build]
statprocessors.Service = arrRawMetrics[statprocessors.Infokey_Service]

// check the output with NamespaceWatcher
nsMetrics, err := nsWatcher.Refresh(passTwokeyOutputs, arrRawMetrics)
assert.Nil(t, err, "Error while NamespaceWatcher.Refresh with passTwokeyOutputs ")
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/statprocessors/tests/sp_node_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func node_runTestcase(t *testing.T) {
assert.Nil(t, err, "Error while NodeStatsWatcher.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while NamespaceWatcher.PassTwokeys, RawMetrics is EMPTY ")

statprocessors.ClusterName = arrRawMetrics[statprocessors.Infokey_ClusterName]
statprocessors.Build = arrRawMetrics[statprocessors.Infokey_Build]
statprocessors.Service = arrRawMetrics[statprocessors.Infokey_Service]

// check the output with NodeStatsWatcher
nodeMetrics, err := nodeWatcher.Refresh(passTwoOutputs, arrRawMetrics)
assert.Nil(t, err, "Error while NodeStatsWatcher.Refresh with passTwoOutputs ")
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/statprocessors/tests/sp_sets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func sets_runTestcase(t *testing.T) {
assert.Nil(t, err, "Error while setsWatcher.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while setsWatcher.PassTwokeys, RawMetrics is EMPTY ")

statprocessors.ClusterName = arrRawMetrics[statprocessors.Infokey_ClusterName]
statprocessors.Build = arrRawMetrics[statprocessors.Infokey_Build]
statprocessors.Service = arrRawMetrics[statprocessors.Infokey_Service]

// check the output with setsWatcher
setsMetrics, err := setsWatcher.Refresh(passTwoOutputs, arrRawMetrics)
assert.Nil(t, err, "Error while setsWatcher.Refresh with passTwoOutputs ")
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/statprocessors/tests/sp_sindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func sindex_runTestcase(t *testing.T) {
assert.Nil(t, err, "Error while sindexMetrics.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while sindexMetrics.PassTwokeys, RawMetrics is EMPTY ")

statprocessors.ClusterName = arrRawMetrics[statprocessors.Infokey_ClusterName]
statprocessors.Build = arrRawMetrics[statprocessors.Infokey_Build]
statprocessors.Service = arrRawMetrics[statprocessors.Infokey_Service]

// check the output with sindexWatcher
sindexMetrics, err := sindexWatcher.Refresh(passTwoOutputs, arrRawMetrics)
assert.Nil(t, err, "Error while sindexMetrics.Refresh with passTwoOutputs ")
Expand Down
47 changes: 47 additions & 0 deletions internal/pkg/statprocessors/tests/sp_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func users_runTestcase(t *testing.T) {
assert.Nil(t, err, "Error while usersWatcher.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while usersWatcher.PassTwokeys, RawMetrics is EMPTY ")

statprocessors.ClusterName = arrRawMetrics[statprocessors.Infokey_ClusterName]
statprocessors.Build = arrRawMetrics[statprocessors.Infokey_Build]
statprocessors.Service = arrRawMetrics[statprocessors.Infokey_Service]

// check the output with usersWatcher
usersMetrics, err := usersWatcher.Refresh(passTwoOutputs, arrRawMetrics)
assert.Nil(t, err, "Error while usersWatcher.Refresh with passTwoOutputs ")
Expand All @@ -96,3 +100,46 @@ func users_runTestcase(t *testing.T) {
}

}

func Test_Users_TestPKI(t *testing.T) {

fmt.Println("initializing config ... Test_Users_TestPKI")

// initialize config and gauge-lists
commons.InitConfigurations(commons.GetWatchersConfigFile(commons.TESTS_USERS_PKI_CONFIG_FILE))

users_runTestcase(t)
}

func Test_Users_Not_Configured(t *testing.T) {

fmt.Println("initializing config ... Test_Users_Not_Configured")

// initialize config and gauge-lists
commons.InitConfigurations(commons.GetWatchersConfigFile(commons.TESTS_DEFAULT_CONFIG_FILE))

// Check passoneKeys
usersWatcher := &statprocessors.UserStatsProcessor{}
nwPassOneKeys := usersWatcher.PassOneKeys()
passOneOutput, _ := dataprovider.GetProvider().RequestInfo(nwPassOneKeys)
fmt.Println("users_runTestcase: passOneOutput: ", passOneOutput)
passTwoOutputs := usersWatcher.PassTwoKeys(passOneOutput)

// append common keys
infoKeys := []string{statprocessors.Infokey_ClusterName, statprocessors.Infokey_Service, statprocessors.Infokey_Build}
passTwoOutputs = append(passTwoOutputs, infoKeys...)

arrRawMetrics, err := dataprovider.GetProvider().RequestInfo(passTwoOutputs)
assert.Nil(t, err, "Error while usersWatcher.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while usersWatcher.PassTwokeys, RawMetrics is EMPTY ")

statprocessors.ClusterName = arrRawMetrics[statprocessors.Infokey_ClusterName]
statprocessors.Build = arrRawMetrics[statprocessors.Infokey_Build]
statprocessors.Service = arrRawMetrics[statprocessors.Infokey_Service]

// check the output with usersWatcher
usersMetrics, err := usersWatcher.Refresh(passTwoOutputs, arrRawMetrics)
assert.Nil(t, err, "Error while usersWatcher.Refresh with passTwoOutputs ")
assert.Empty(t, usersMetrics, "Error while usersWatcher.Refresh, usersWatcher is EMPTY ")

}
4 changes: 4 additions & 0 deletions internal/pkg/statprocessors/tests/sp_xdr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func xdr_runTestcase(t *testing.T) {
passTwoOutputs = append(passTwoOutputs, infoKeys...)
arrRawMetrics, err := dataprovider.GetProvider().RequestInfo(passTwoOutputs)

statprocessors.ClusterName = passOneOutput[statprocessors.Infokey_ClusterName]
statprocessors.Build = passOneOutput[statprocessors.Infokey_Build]
statprocessors.Service = passOneOutput[statprocessors.Infokey_Service]

assert.Nil(t, err, "Error while XdrWatcher.PassTwokeys ")
assert.NotEmpty(t, arrRawMetrics, "Error while XdrWatcher.PassTwokeys, RawMetrics is EMPTY ")

Expand Down
Loading

0 comments on commit 9620a55

Please sign in to comment.