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

Add IP metrics to REST #2174

Merged
merged 17 commits into from
Jun 28, 2021
Merged

Add IP metrics to REST #2174

merged 17 commits into from
Jun 28, 2021

Conversation

ijungmann
Copy link
Contributor

@ijungmann ijungmann commented Jun 24, 2021

Detailed description:
Add a metric to track which IPs hit which endpoints.

The intention is to use this metric for environments where we have whitelisted IPs and already know who is accessing the API, it is not meant for public environments.

Which issue(s) this PR fixes:
Fixes #2130

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann ijungmann added this to the Mirror 0.37.0 milestone Jun 24, 2021
@ijungmann ijungmann added enhancement Type: New feature P2 rest Area: REST API labels Jun 24, 2021
@codecov
Copy link

codecov bot commented Jun 24, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@305413f). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2174   +/-   ##
=======================================
  Coverage        ?   81.82%           
  Complexity      ?     2130           
=======================================
  Files           ?      414           
  Lines           ?    11131           
  Branches        ?      945           
=======================================
  Hits            ?     9108           
  Misses          ?     1714           
  Partials        ?      309           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 305413f...687f89e. Read the comment docs.

Ian Jungmann added 5 commits June 24, 2021 15:34
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann
Copy link
Contributor Author

A sample of what the metrics will look like (tested locally).
ip_count_bucket{le="0.1",endpoint="/api/v1/transactions/:id",ip="::1"} 0 ip_count_bucket{le="5",endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_bucket{le="15",endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_bucket{le="50",endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_bucket{le="100",endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_bucket{le="500",endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_bucket{le="+Inf",endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_sum{endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_count{endpoint="/api/v1/transactions/:id",ip="::1"} 1 ip_count_bucket{le="0.1",endpoint="/api/v1/accounts",ip="::1"} 0 ip_count_bucket{le="5",endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_bucket{le="15",endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_bucket{le="50",endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_bucket{le="100",endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_bucket{le="500",endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_bucket{le="+Inf",endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_sum{endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_count{endpoint="/api/v1/accounts",ip="::1"} 1 ip_count_bucket{le="0.1",endpoint="/api/v1/accounts/:id",ip="::1"} 0 ip_count_bucket{le="5",endpoint="/api/v1/accounts/:id",ip="::1"} 1 ip_count_bucket{le="15",endpoint="/api/v1/accounts/:id",ip="::1"} 1 ip_count_bucket{le="50",endpoint="/api/v1/accounts/:id",ip="::1"} 1 ip_count_bucket{le="100",endpoint="/api/v1/accounts/:id",ip="::1"} 1 ip_count_bucket{le="500",endpoint="/api/v1/accounts/:id",ip="::1"} 1 ip_count_bucket{le="+Inf",endpoint="/api/v1/accounts/:id",ip="::1"} 1 ip_count_sum{endpoint="/api/v1/accounts/:id",ip="::1"} 1 ip_count_count{endpoint="/api/v1/accounts/:id",ip="::1"} 1

@ijungmann ijungmann marked this pull request as ready for review June 25, 2021 04:52
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann ijungmann requested a review from a team June 25, 2021 17:30
Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Clarification requests

hedera-mirror-rest/server.js Show resolved Hide resolved
hedera-mirror-rest/middleware/metricsHandler.js Outdated Show resolved Hide resolved
hedera-mirror-rest/transactions.js Outdated Show resolved Hide resolved
hedera-mirror-rest/middleware/metricsHandler.js Outdated Show resolved Hide resolved
hedera-mirror-rest/middleware/metricsHandler.js Outdated Show resolved Hide resolved
Ian Jungmann added 2 commits June 25, 2021 16:05
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann
Copy link
Contributor Author

After changes, this is the look:
hedera_mirror_rest_request_count{endpoint="/api/v1/transactions",ip="eff8e7ca506627fe15dda5e0e512fcaad70b6d520f37cc76597fdb4f2d83a1a3"} 2 hedera_mirror_rest_request_count{endpoint="/api/v1/transactions/:id",ip="eff8e7ca506627fe15dda5e0e512fcaad70b6d520f37cc76597fdb4f2d83a1a3"} 2 hedera_mirror_rest_request_count{endpoint="/api/v1/tokens",ip="eff8e7ca506627fe15dda5e0e512fcaad70b6d520f37cc76597fdb4f2d83a1a3"} 1 hedera_mirror_rest_request_count{endpoint="/api/v1/tokens/:id/balances",ip="eff8e7ca506627fe15dda5e0e512fcaad70b6d520f37cc76597fdb4f2d83a1a3"} 1

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@@ -1,8 +1,11722 @@
{
"name": "hedera-mirror-rest",
"version": "0.37.0-SNAPSHOT",
"lockfileVersion": 1,
"lockfileVersion": 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix

Ian Jungmann added 2 commits June 28, 2021 12:45
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Comment on lines +737 to +757
describe('Utils ipMask tests', () => {
test('Verify ipV4', () => {
const maskedIp = utils.ipMask('12.214.31.144');
expect(maskedIp).toStrictEqual('12.214.31.0');
});
test('Verify ipV6', () => {
const maskedIp = utils.ipMask('2001:0db8:85a3:a13c:0000:8a2e:0370:7334');
expect(maskedIp).toStrictEqual('2001:db8:85a3::');
});
test('Verify ipV6 short form back', () => {
const maskedIp = utils.ipMask('1::');
expect(maskedIp).toStrictEqual('1::');
});
test('Verify ipV6 short form front', () => {
const maskedIp = utils.ipMask('::ffff');
expect(maskedIp).toStrictEqual('::');
});
test('Verify ipV6 dual', () => {
const maskedIp = utils.ipMask('2001:db8:3333:4444:5555:6666:1.2.3.4');
expect(maskedIp).toStrictEqual('2001:db8:3333::0.0.0.0');
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These IPs were taken from examples for the library, some made up, none are sensitive.

steven-sheehy
steven-sheehy previously approved these changes Jun 28, 2021
Copy link
Member

@steven-sheehy steven-sheehy left a comment

Choose a reason for hiding this comment

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

LGTM

xin-hedera
xin-hedera previously approved these changes Jun 28, 2021
Copy link
Collaborator

@xin-hedera xin-hedera left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@ijungmann ijungmann dismissed stale reviews from xin-hedera and steven-sheehy via ab06b0d June 28, 2021 19:26
Nana-EC
Nana-EC previously approved these changes Jun 28, 2021
Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
xin-hedera
xin-hedera previously approved these changes Jun 28, 2021
Copy link
Collaborator

@xin-hedera xin-hedera left a comment

Choose a reason for hiding this comment

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

LGTM

steven-sheehy
steven-sheehy previously approved these changes Jun 28, 2021
Nana-EC
Nana-EC previously approved these changes Jun 28, 2021
Signed-off-by: Ian Jungmann <ian.jungmann@hedera.com>
@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2021

@ijungmann ijungmann merged commit 0e4e0d0 into main Jun 28, 2021
@ijungmann ijungmann deleted the Add_rest_ip_metrics branch June 28, 2021 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature P2 rest Area: REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REST API metrics by client IP
4 participants