Skip to content

Commit

Permalink
feat: keyperfmetrics collector infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Jul 31, 2024
1 parent 676647f commit f9f82fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
12 changes: 6 additions & 6 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Rest struct {
Client *rest.Client
Prop *prop
endpoints []*EndPoint
IsIgnoreUnknownFieldsEnabled bool
isIgnoreUnknownFieldsEnabled bool
}

type EndPoint struct {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (r *Rest) Fields(prop *prop) []string {
fields := prop.Fields
if prop.IsPublic {
// applicable for public API only
if !r.IsIgnoreUnknownFieldsEnabled || !r.isValidFormat(prop) {
if !r.isIgnoreUnknownFieldsEnabled || !r.isValidFormat(prop) {
fields = []string{"*"}
}
}
Expand Down Expand Up @@ -349,9 +349,9 @@ func (r *Rest) PollCounter() (map[string]*matrix.Matrix, error) {
}
// Check the version if it is 9.11.1 then pass relevant fields and not *
if v {
r.IsIgnoreUnknownFieldsEnabled = true
r.isIgnoreUnknownFieldsEnabled = true
} else {
r.IsIgnoreUnknownFieldsEnabled = false
r.isIgnoreUnknownFieldsEnabled = false
}
r.updateHref()
parseD := time.Since(startTime)
Expand All @@ -368,7 +368,7 @@ func (r *Rest) updateHref() {
Fields(r.Fields(r.Prop)).
Filter(r.Prop.Filter).
ReturnTimeout(r.Prop.ReturnTimeOut).
IsIgnoreUnknownFieldsEnabled(r.IsIgnoreUnknownFieldsEnabled).
IsIgnoreUnknownFieldsEnabled(r.isIgnoreUnknownFieldsEnabled).
Build()

for _, e := range r.endpoints {
Expand All @@ -377,7 +377,7 @@ func (r *Rest) updateHref() {
Fields(r.Fields(e.prop)).
Filter(r.filter(e)).
ReturnTimeout(r.Prop.ReturnTimeOut).
IsIgnoreUnknownFieldsEnabled(r.IsIgnoreUnknownFieldsEnabled).
IsIgnoreUnknownFieldsEnabled(r.isIgnoreUnknownFieldsEnabled).
Build()
}
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/collectors/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func TestFields(t *testing.T) {
{
name: "Test with valid fields and no hidden fields",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: true,
isIgnoreUnknownFieldsEnabled: true,
},
p: &prop{
Fields: []string{
Expand All @@ -288,7 +288,7 @@ func TestFields(t *testing.T) {
{
name: "Test with invalid fields and no hidden fields",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: true,
isIgnoreUnknownFieldsEnabled: true,
},
p: &prop{
Fields: []string{
Expand All @@ -303,7 +303,7 @@ func TestFields(t *testing.T) {
{
name: "Test with valid fields and hidden fields",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: true,
isIgnoreUnknownFieldsEnabled: true,
},
p: &prop{
Fields: []string{
Expand All @@ -328,7 +328,7 @@ func TestFields(t *testing.T) {
{
name: "Test with valid fields and hidden fields and prior versions to 9.11.1",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: false,
isIgnoreUnknownFieldsEnabled: false,
},
p: &prop{
Fields: []string{
Expand All @@ -351,7 +351,7 @@ func TestFields(t *testing.T) {
{
name: "Test with valid fields and no hidden fields for private API",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: false,
isIgnoreUnknownFieldsEnabled: false,
},
p: &prop{
Fields: []string{
Expand All @@ -370,7 +370,7 @@ func TestFields(t *testing.T) {
{
name: "Test with invalid fields and no hidden fields, ignore unknown fields disabled",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: false,
isIgnoreUnknownFieldsEnabled: false,
},
p: &prop{
Fields: []string{
Expand All @@ -385,7 +385,7 @@ func TestFields(t *testing.T) {
{
name: "Test with invalid fields and no hidden fields for private API",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: true,
isIgnoreUnknownFieldsEnabled: true,
},
p: &prop{
Fields: []string{
Expand All @@ -404,7 +404,7 @@ func TestFields(t *testing.T) {
{
name: "Test with valid fields and hidden fields for private API",
r: &Rest{
IsIgnoreUnknownFieldsEnabled: true,
isIgnoreUnknownFieldsEnabled: true,
},
p: &prop{
Fields: []string{
Expand Down
15 changes: 8 additions & 7 deletions cmd/collectors/zapiperf/zapiperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (
objWorkloadClass = "user_defined|system_defined"
objWorkloadVolumeClass = "autovolume"
BILLION = 1_000_000_000
timestampMetricName = "timestamp"
)

var workloadDetailMetrics = []string{"resource_latency"}
Expand Down Expand Up @@ -396,7 +397,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) {
curMat := prevMat.Clone(matrix.With{Data: false, Metrics: true, Instances: true, ExportInstances: false})
curMat.Reset()

timestamp := curMat.GetMetric("timestamp")
timestamp := curMat.GetMetric(timestampMetricName)
if timestamp == nil {
return nil, errs.New(errs.ErrConfig, "missing timestamp metric") // @TODO errconfig??
}
Expand Down Expand Up @@ -775,7 +776,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) {

// calculate timestamp delta first since many counters require it for postprocessing.
// Timestamp has "raw" property, so it isn't post-processed automatically
if _, err = curMat.Delta("timestamp", prevMat, z.Logger); err != nil {
if _, err = curMat.Delta(timestampMetricName, prevMat, z.Logger); err != nil {
z.Logger.Error().Err(err).Msg("(timestamp) calculate delta:")
// @TODO terminate since other counters will be incorrect
}
Expand Down Expand Up @@ -842,7 +843,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) {
if property == "average" || property == "percent" {

if strings.HasSuffix(metric.GetName(), "latency") {
skips, err = curMat.DivideWithThreshold(key, metric.GetComment(), z.latencyIoReqd, cachedData, prevMat, "timestamp", z.Logger)
skips, err = curMat.DivideWithThreshold(key, metric.GetComment(), z.latencyIoReqd, cachedData, prevMat, timestampMetricName, z.Logger)
} else {
skips, err = curMat.Divide(key, metric.GetComment())
}
Expand Down Expand Up @@ -874,7 +875,7 @@ func (z *ZapiPerf) PollData() (map[string]*matrix.Matrix, error) {
// calculate rates (which we deferred to calculate averages/percents first)
for i, metric := range orderedMetrics {
if metric.GetProperty() == "rate" {
if skips, err = curMat.Divide(orderedKeys[i], "timestamp"); err != nil {
if skips, err = curMat.Divide(orderedKeys[i], timestampMetricName); err != nil {
z.Logger.Error().Err(err).
Int("i", i).
Str("key", orderedKeys[i]).
Expand Down Expand Up @@ -1185,8 +1186,8 @@ func (z *ZapiPerf) PollCounter() (map[string]*matrix.Matrix, error) {
// Create an artificial metric to hold timestamp of each instance data.
// The reason we don't keep a single timestamp for the whole data
// is because we might get instances in different batches
if !oldMetrics.Has("timestamp") {
m, err := mat.NewMetricFloat64("timestamp")
if !oldMetrics.Has(timestampMetricName) {
m, err := mat.NewMetricFloat64(timestampMetricName)
if err != nil {
z.Logger.Error().Err(err).Msg("add timestamp metric")
}
Expand Down Expand Up @@ -1275,7 +1276,7 @@ func (z *ZapiPerf) PollCounter() (map[string]*matrix.Matrix, error) {
for key := range oldMetrics.Iter() {
// temporary fix: prevent removing array counters
// @TODO
if key != "timestamp" && !strings.Contains(key, ".") {
if key != timestampMetricName && !strings.Contains(key, ".") {
mat.RemoveMetric(key)
z.Logger.Debug().Msgf("removed metric [%s]", key)
}
Expand Down

0 comments on commit f9f82fe

Please sign in to comment.