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

[aggregator] Checking if metadata is set to default should not cause … #3198

Merged
merged 1 commit into from
Feb 9, 2021
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: 10 additions & 4 deletions src/metrics/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ func (m PipelineMetadata) Equal(other PipelineMetadata) bool {

// IsDefault returns whether this is the default standard pipeline metadata.
func (m PipelineMetadata) IsDefault() bool {
return m.AggregationID.IsDefault() &&
m.StoragePolicies.IsDefault() &&
return m.AggregationID == aggregation.DefaultID &&
len(m.StoragePolicies) == 0 &&
m.Pipeline.IsEmpty() &&
m.DropPolicy.IsDefault()
m.DropPolicy == policy.DefaultDropPolicy
}

// IsMappingRule returns whether this is a rollup rule pipeline metadata.
Expand Down Expand Up @@ -435,7 +435,13 @@ func (sms StagedMetadatas) Equal(other StagedMetadatas) bool {

// IsDefault determines whether the list of staged metadata is a default list.
func (sms StagedMetadatas) IsDefault() bool {
return len(sms) == 1 && sms[0].IsDefault()
// very ugly but need to help out the go compiler here, as function calls have a high inlining cost
return len(sms) == 1 && len(sms[0].Pipelines) == 1 &&
sms[0].CutoverNanos == 0 && !sms[0].Tombstoned &&
sms[0].Pipelines[0].AggregationID == aggregation.DefaultID &&
len(sms[0].Pipelines[0].StoragePolicies) == 0 &&
sms[0].Pipelines[0].Pipeline.IsEmpty() &&
sms[0].Pipelines[0].DropPolicy == policy.DefaultDropPolicy
}

// IsDropPolicyApplied returns whether the list of staged metadata is the
Expand Down
22 changes: 18 additions & 4 deletions src/metrics/metadata/metadata_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,32 @@ package metadata
import (
"runtime"
"testing"

"github.com/m3db/m3/src/metrics/aggregation"
"github.com/m3db/m3/src/metrics/policy"
)

func isDefault(m StagedMetadatas) bool {
return m.IsDefault()
}

func BenchmarkMetadata_IsDefault(b *testing.B) {
m := testLargeStagedMetadatas
m = append(m, testLargeStagedMetadatas...)
m := StagedMetadatas{
StagedMetadata{
CutoverNanos: 0,
Tombstoned: false,
Metadata: Metadata{
Pipelines: []PipelineMetadata{
{
AggregationID: aggregation.DefaultID,
StoragePolicies: []policy.StoragePolicy{},
},
},
},
},
}
for i := 0; i < b.N; i++ {
m[0].CutoverNanos = int64(i)
if isDefault(m) {
if !isDefault(m) {
b.Fail()
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/metrics/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,10 @@ func TestStagedMetadatasIsDefault(t *testing.T) {
}

for _, input := range inputs {
require.Equal(t, input.expected, input.metadatas.IsDefault())
input := input
t.Run(fmt.Sprintf("%v", input.metadatas), func(t *testing.T) {
require.Equal(t, input.expected, input.metadatas.IsDefault())
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/metrics/pipeline/applied/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func NewPipeline(ops []OpUnion) Pipeline {
func (p Pipeline) Len() int { return len(p.operations) }

// IsEmpty determines whether a pipeline is empty.
func (p Pipeline) IsEmpty() bool { return p.Len() == 0 }
func (p Pipeline) IsEmpty() bool { return len(p.operations) == 0 }

// At returns the operation at a given step.
func (p Pipeline) At(i int) OpUnion { return p.operations[i] }
Expand Down