Skip to content

Limits Header extension: add support for metric hierarchies with more than 2 levels#122

Merged
bors[bot] merged 8 commits intomasterfrom
limits-header-ext-with-multi-level-hierarchies
Sep 3, 2019
Merged

Limits Header extension: add support for metric hierarchies with more than 2 levels#122
bors[bot] merged 8 commits intomasterfrom
limits-header-ext-with-multi-level-hierarchies

Conversation

@davidor
Copy link
Copy Markdown
Contributor

@davidor davidor commented Sep 3, 2019

This is part of #114 . It adapts the limits header extension to work with metric hierarchies of more than 2 levels.

@davidor davidor force-pushed the limits-header-ext-with-multi-level-hierarchies branch from 5b282e6 to 3649a88 Compare September 3, 2019 14:19
@davidor davidor marked this pull request as ready for review September 3, 2019 14:21
@davidor davidor requested a review from unleashed September 3, 2019 14:21
Comment thread test/unit/metric_test.rb Outdated
assert_true metrics.each_with_index.all? do |metric, idx|
ascendants = Metric.ascendants(service_id, metric.name)

if idx == 0
Copy link
Copy Markdown
Contributor Author

@davidor davidor Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified using take(idx).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, are you changing it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Comment thread lib/3scale/backend/metric.rb Outdated
end
end

# Returns the "ascendants" of a metric, that is, its parents,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can a metric have multiple parents?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, this was meant to correct the parents to parent, grandparent, ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. The description is not accurate 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 👍


parents_of_metric.reduce(parents_of_metric) do |acc, parent|
acc + ascendants(service_id, parent)
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered using parents_of_metric.each and pushing to it as you go for a more readable and performant version avoiding recursion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow. Can you expand a bit?

Copy link
Copy Markdown
Contributor Author

@davidor davidor Sep 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the exact same code as descendants - have you checked out how to DRY this up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't come up with anything that makes the code more readable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me feel uneasy, but oh well.

Comment thread test/unit/metric_test.rb Outdated
assert_true metrics.each_with_index.all? do |metric, idx|
ascendants = Metric.ascendants(service_id, metric.name)

if idx == 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, are you changing it?

@davidor davidor force-pushed the limits-header-ext-with-multi-level-hierarchies branch from 3649a88 to fc15a4d Compare September 3, 2019 14:52
@davidor davidor force-pushed the limits-header-ext-with-multi-level-hierarchies branch from fc15a4d to 446ab36 Compare September 3, 2019 14:59
@davidor
Copy link
Copy Markdown
Contributor Author

davidor commented Sep 3, 2019

bors r=@unleashed

bors Bot added a commit that referenced this pull request Sep 3, 2019
122: Limits Header extension: add support for metric hierarchies with more than 2 levels r=unleashed a=davidor

This is part of #114 . It adapts the limits header extension to work with metric hierarchies of more than 2 levels.

Co-authored-by: David Ortiz <z.david.ortiz@gmail.com>
@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Sep 3, 2019

Build succeeded

@bors bors Bot merged commit 446ab36 into master Sep 3, 2019
@bors bors Bot deleted the limits-header-ext-with-multi-level-hierarchies branch September 3, 2019 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants