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

fix: only send metrics if there is data to send. (#58) #66

Merged
merged 1 commit into from Dec 16, 2021

Conversation

rarruda
Copy link
Collaborator

@rarruda rarruda commented Nov 13, 2021

We want to preserve the backend from having to work, when there is no work to be done.

@coveralls
Copy link

coveralls commented Nov 13, 2021

Pull Request Test Coverage Report for Build 1589092239

  • 59 of 62 (95.16%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+5.8%) to 96.181%

Changes Missing Coverage Covered Lines Changed/Added Lines %
spec/unleash/metrics_reporter_spec.rb 45 46 97.83%
lib/unleash/client.rb 0 2 0.0%
Totals Coverage Status
Change from base Build 1577747545: 5.8%
Covered Lines: 1486
Relevant Lines: 1545

💛 - Coveralls

@rarruda rarruda requested a review from ivarconr December 2, 2021 22:23
@rarruda rarruda force-pushed the fix/58/only_send_metrics_if_strictly_needed branch from 1432bd3 to 5cb50ab Compare December 2, 2021 23:39
@rarruda rarruda requested review from chriswk and sighphyre and removed request for ivarconr, chriswk and sighphyre December 3, 2021 06:49
@rarruda rarruda force-pushed the fix/58/only_send_metrics_if_strictly_needed branch from 5cb50ab to ac4bde9 Compare December 5, 2021 23:36
Comment on lines 89 to 99
expect(WebMock).to have_requested(:post, 'http://test-url/client/metrics')
.with(
body: hash_including(
appName: "my-test-app",
instanceId: "rspec/test"
)
)
.with { |req|
hash = JSON.parse(req.body)

[
DateTime.parse(hash['bucket']['stop']) >= DateTime.parse(hash['bucket']['start']),
hash['bucket']['toggles']['featureA']['yes'] == 3,
hash['bucket']['toggles']['featureA']['no'] == 2,
hash['bucket']['toggles']['featureB']['yes'] == 1
].all?(true)
}
Copy link

Choose a reason for hiding this comment

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

[rubocop] <Lint/AmbiguousBlockAssociation> reported by reviewdog 🐶
Parenthesize the param `have_requested(:post, 'http://test-url/client/metrics')
.with(
body: hash_including(
appName: "my-test-app",
instanceId: "rspec/test"
)
)
.with { |req|
hash = JSON.parse(req.body)

    [
      DateTime.parse(hash['bucket']['stop']) >= DateTime.parse(hash['bucket']['start']),
      hash['bucket']['toggles']['featureA']['yes'] == 3,
      hash['bucket']['toggles']['featureA']['no'] == 2,
      hash['bucket']['toggles']['featureB']['yes'] == 1
    ].all?(true)
  }` to make sure that the block will be associated with the `have_requested(:post, 'http://test-url/client/metrics')
  .with(
    body: hash_including(
      appName: "my-test-app",
      instanceId: "rspec/test"
    )
  )
  .with` method call.

Comment on lines 89 to 99
expect(WebMock).to have_requested(:post, 'http://test-url/client/metrics')
.with(
body: hash_including(
appName: "my-test-app",
instanceId: "rspec/test"
)
)
.with { |req|
hash = JSON.parse(req.body)

[
DateTime.parse(hash['bucket']['stop']) >= DateTime.parse(hash['bucket']['start']),
hash['bucket']['toggles']['featureA']['yes'] == 3,
hash['bucket']['toggles']['featureA']['no'] == 2,
hash['bucket']['toggles']['featureB']['yes'] == 1
].all?(true)
}
Copy link

Choose a reason for hiding this comment

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

[rubocop] <Lint/AmbiguousBlockAssociation> reported by reviewdog 🐶
Parenthesize the param `have_requested(:post, 'http://test-url/client/metrics')
.with(
body: hash_including(
appName: "my-test-app",
instanceId: "rspec/test"
)
)
.with { |req|
hash = JSON.parse(req.body)

    [
      DateTime.parse(hash['bucket']['stop']) >= DateTime.parse(hash['bucket']['start']),
      hash['bucket']['toggles']['featureA']['yes'] == 3,
      hash['bucket']['toggles']['featureA']['no'] == 2,
      hash['bucket']['toggles']['featureB']['yes'] == 1
    ].all?(true)
  }` to make sure that the block will be associated with the `have_requested(:post, 'http://test-url/client/metrics')
  .with(
    body: hash_including(
      appName: "my-test-app",
      instanceId: "rspec/test"
    )
  )
  .with` method call.


metrics_reporter.post

expect(WebMock).to have_requested(:post, 'http://test-url/client/metrics')
Copy link

Choose a reason for hiding this comment

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

Lint/AmbiguousBlockAssociation: Parenthesize the param `have_requested(:post, 'http://test-url/client/metrics')
.with(
body: hash_including(
appName: "my-test-app",
instanceId: "rspec/test"
)
)
.with { |req|
hash = JSON.parse(req.body)

    [
      DateTime.parse(hash['bucket']['stop']) >= DateTime.parse(hash['bucket']['start']),
      hash['bucket']['toggles']['featureA']['yes'] == 3,
      hash['bucket']['toggles']['featureA']['no'] == 2,
      hash['bucket']['toggles']['featureB']['yes'] == 1
    ].all?(true)
  }` to make sure that the block will be associated with the `have_requested(:post, 'http://test-url/client/metrics')
  .with(
    body: hash_including(
      appName: "my-test-app",
      instanceId: "rspec/test"
    )
  )
  .with` method call.

(at-me in a reply with help or ignore)

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

Looks good

We want to preserve the backend from having to work, when there is no work to be done.
@rarruda rarruda force-pushed the fix/58/only_send_metrics_if_strictly_needed branch from c010b0c to 090b803 Compare December 16, 2021 19:23
@rarruda rarruda merged commit ea72260 into master Dec 16, 2021
@rarruda rarruda deleted the fix/58/only_send_metrics_if_strictly_needed branch December 16, 2021 19:26
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.

None yet

4 participants