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

feat: log geo location info to InfluxDB #339

Merged
merged 15 commits into from
Jun 28, 2024

Conversation

PatrickNercessian
Copy link
Contributor

@PatrickNercessian PatrickNercessian commented Jun 5, 2024

No description provided.

@PatrickNercessian
Copy link
Contributor Author

Seems the build-api step is failing because it's missing the GLIF_TOKEN env variable. Not sure how my changes would have caused this

@PatrickNercessian
Copy link
Contributor Author

Link to roadmap issue: space-meridian/roadmap#112

api/lib/telemetry.js Outdated Show resolved Hide resolved
api/lib/network-management.js Outdated Show resolved Hide resolved
api/lib/network-management.js Outdated Show resolved Hide resolved
api/lib/network-management.js Outdated Show resolved Hide resolved
api/package.json Outdated Show resolved Hide resolved
api/lib/inet-grouping.js Outdated Show resolved Hide resolved
common/telemetry.js Show resolved Hide resolved
api/test/inet-grouping.test.js Outdated Show resolved Hide resolved
api/lib/inet-grouping.js Outdated Show resolved Hide resolved
api/lib/inet-grouping.js Outdated Show resolved Hide resolved
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

You are making great progress!

The implementation looks good at the high level, let's improve the details now.

* @param {import('node:http').IncomingMessage} req
* @param {string} stationId
* @param {string} inetGroup
* @param {function} recordTelemetryFn
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you want a new file like in spark-evaluate for the typings? Or just have it in telemetry.js or network-info-logger.js?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer to add common/typings.d.ts file for consistency with the rest of our projects.

Copy link
Member

Choose a reason for hiding this comment

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

In other places, we use the variable/argument name recordTelemetry. Please do the same here for consistency.

api/index.js Outdated Show resolved Hide resolved
common/telemetry.js Outdated Show resolved Hide resolved

import { assertApproximately } from '../../test-helpers/assert.js'

const { DATABASE_URL } = process.env

after(telemetry.close)
after(async () => { await telemetry.publishWriteClient.close() })
Copy link
Member

Choose a reason for hiding this comment

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

IIRC, we are calling close to prevent the write client from blocking the process from exiting.

Ideally, tests should not write any telemetry, they should mock the recordTelemetryFn, as we already do in other tests.

Alternatively, the telemetry module should implement a close function to close all writers.

For example (may not work out of the box):

// usage here - no change
after(telemetry.close)

// implementation in common/telemetry
export const close = async () => {
  await Promise.all([
    publishWriteClient.close(), 
    apiWriterClient.close(), 
    //etc.
  ])
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This closing logic was already present I think, this change is just to bring it in line with the new telemetry file.

If we want to change this, maybe it's better scoped in a different PR?

Copy link
Member

Choose a reason for hiding this comment

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

I see your point.

The problem I am trying to prevent is that with your changes in place, the test suite does not exit cleanly, because there are background active writers.

Before your change, when executing the tests in publish/test/test.js, only one writer was created and this writer was closed by this after line.

With your changes in place, executing this test file creates more than on writer, but we close only one of them. As a result, the test suite never exits.

I confirmed this by running the following command:

npm t -w api -- -i -g "getRoundStartEpoch|startRoundTracker"

We want to rework this test file anyway; it should not write any telemetry, as I mentioned before. Essentially, we want to port filecoin-station/voyager-api#22 to this repo.

I am going to make two smaller changes: fix this test file to use a mocked telemetry recorder and introduce common/typings.d.ts file as discussed in #339 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

See #354

In the end, I did not need common/typings.d.ts, so I am leaving that change for you to make in this pull request.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
after(async () => { await telemetry.publishWriteClient.close() })

api/test/network-info-logger.test.js Show resolved Hide resolved
api/test/network-info-logger.test.js Outdated Show resolved Hide resolved
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Almost there! 🤩

Sorry about the merge conflicts I created by my two PRs and left for you to resolve. 🙈

Besides the comment below, there are a couple of unresolved conversations above; please look at them, too.

api/test/network-info-logger.test.js Outdated Show resolved Hide resolved
@@ -1,7 +1,7 @@
// This file is shared with voyager-api/voyager-publish
// Helpers in this file must not have anything project-specific like measurement fields

import { Point } from '../publish/lib/telemetry.js'
import { Point } from '../common/telemetry.js'

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 6332977

api/lib/network-info-logger.js Outdated Show resolved Hide resolved
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

@juliangruber hindsight please 🙏🏻

@@ -51,6 +52,9 @@ try {
process.exit(1)
}

// Clear the station IDs seen by the network info logger every 24 hours
setInterval(clearNetworkInfoStationIdsSeen, 1000 * 60 * 60 * 24)
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

@bajtos bajtos dismissed juliangruber’s stale review June 28, 2024 07:01

comments were addressed

@bajtos bajtos mentioned this pull request Jun 28, 2024
@bajtos
Copy link
Member

bajtos commented Jun 28, 2024

I created #360 to run the test on CI under my account, all passed 👍🏻

@bajtos bajtos merged commit 25f8e74 into filecoin-station:main Jun 28, 2024
15 of 16 checks passed
@bajtos bajtos changed the title feat: log IP Group and location info to InfluxDB feat: log geo location info to InfluxDB Jun 28, 2024
Copy link
Member

@juliangruber juliangruber left a comment

Choose a reason for hiding this comment

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

lgtm!

@PatrickNercessian PatrickNercessian deleted the feat-log-network-info branch July 1, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ done
Development

Successfully merging this pull request may close these issues.

3 participants