Skip to content

Commit

Permalink
OM86 - Added support for micro benchmarks (#101)
Browse files Browse the repository at this point in the history
* OM86 - support for micro benchmarks
  • Loading branch information
mphanias authored Nov 30, 2023
1 parent 3315953 commit aab0b97
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
59 changes: 57 additions & 2 deletions watcher_latency.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"strings"

"github.com/prometheus/client_golang/prometheus"

log "github.com/sirupsen/logrus"
Expand All @@ -9,6 +11,8 @@ import (
type LatencyWatcher struct {
}

var LatencyBenchmarks = make(map[string]string)

func (lw *LatencyWatcher) describe(ch chan<- *prometheus.Desc) {}

func (lw *LatencyWatcher) passOneKeys() []string {
Expand All @@ -33,7 +37,7 @@ func (lw *LatencyWatcher) passTwoKeys(rawMetrics map[string]string) (latencyComm
}

if ok {
return []string{"latencies:"}
return lw.getLatenciesCommands(rawMetrics)
}

return []string{"latency:"}
Expand All @@ -56,10 +60,25 @@ func (lw *LatencyWatcher) refresh(o *Observer, infoKeys []string, rawMetrics map
}
}

// loop all the latency infokeys
for _, infoKey := range infoKeys {
err := parseSingleLatenciesKey(infoKey, rawMetrics, allowedLatenciesList, blockedLatenciessList, ch)
if err != nil {
return err
}
}

return nil
}

func parseSingleLatenciesKey(singleLatencyKey string, rawMetrics map[string]string,
allowedLatenciesList map[string]struct{},
blockedLatenciessList map[string]struct{}, ch chan<- prometheus.Metric) error {

var latencyStats map[string]StatsMap

if rawMetrics["latencies:"] != "" {
latencyStats = parseLatencyInfo(rawMetrics["latencies:"], int(config.Aerospike.LatencyBucketsCount))
latencyStats = parseLatencyInfo(rawMetrics[singleLatencyKey], int(config.Aerospike.LatencyBucketsCount))
} else {
latencyStats = parseLatencyInfoLegacy(rawMetrics["latency:"], int(config.Aerospike.LatencyBucketsCount))
}
Expand Down Expand Up @@ -99,3 +118,39 @@ func (lw *LatencyWatcher) refresh(o *Observer, infoKeys []string, rawMetrics map

return nil
}

// Utility methods
// checks if a stat can be considered for latency stat retrieval
func isStatLatencyHistRelated(stat string) bool {
// is not enable-benchmarks-storage and (enable-benchmarks-* or enable-hist-*)
return (!strings.Contains(stat, "enable-benchmarks-storage")) && (strings.Contains(stat, "enable-benchmarks-") ||
strings.Contains(stat, "enable-hist-")) // hist-proxy & hist-info - both at service level
}

func (lw *LatencyWatcher) getLatenciesCommands(rawMetrics map[string]string) []string {
var commands = []string{"latencies:"}

// Hashmap content format := namespace-<histogram-key> = <histogram-key>
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:], "-")
}

commands = append(commands, histCommand)
}

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

return commands
}
16 changes: 14 additions & 2 deletions watcher_namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ func (nw *NamespaceWatcher) refreshNamespaceStats(singleInfoKey string, infoKeys
sindexType := stats[SINDEX_TYPE]
storageEngine := stats[STORAGE_ENGINE]

// fmt.Println(" storageEngine: ", storageEngine)

// if stat is index-type or sindex-type , append addl label
if strings.HasPrefix(deviceType, INDEX_TYPE) && len(indexType) > 0 {
labels = append(labels, METRIC_LABEL_INDEX)
Expand Down Expand Up @@ -210,7 +208,21 @@ func (nw *NamespaceWatcher) refreshNamespaceStats(singleInfoKey string, infoKeys
// push to prom-channel
pushToPrometheus(asMetric, pv, labels, labelValues, ch)
}

// 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) {
delete(LatencyBenchmarks, nsName+"-"+stat)

if pv == 1 {
LatencyBenchmarks[nsName+"-"+stat] = 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"

}

Expand Down
10 changes: 10 additions & 0 deletions watcher_node_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,15 @@ func (sw *StatsWatcher) handleRefresh(o *Observer, nodeRawMetrics string, cluste

pushToPrometheus(asMetric, pv, labels, labelsValues, ch)

// 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)

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

}
}

0 comments on commit aab0b97

Please sign in to comment.