Skip to content

Commit

Permalink
fix: correctly use controller when registering interest and correctly…
Browse files Browse the repository at this point in the history
… use node's ID when publishing metrics. (#3273)

* fix: correctly use controller when registering interest and ...

correctly use node's ID when publishing metrics.

* fix: use new /ceramic/interests POST endpoint

* fix: update recon tests

* fix: format
  • Loading branch information
nathanielc authored Jul 31, 2024
1 parent 8c64b14 commit e719816
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions packages/core/src/__tests__/recon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,16 @@ describe('ReconApi', () => {
const fakeInterest1 = TestUtils.randomStreamID()
await reconApi.init('testInitialCursor', [fakeInterest0, fakeInterest1])
expect(mockSendRequest).toHaveBeenCalledTimes(4)
expect(mockSendRequest.mock.calls[2][0]).toContain(fakeInterest0.toString())
expect(mockSendRequest.mock.calls[3][0]).toContain(fakeInterest1.toString())
expect(mockSendRequest).toHaveBeenCalledWith(`${RECON_URL}/ceramic/interests`, {
method: 'POST',
body: { sep: 'model', sepValue: fakeInterest0.toString() },
headers: { 'Content-Type': 'application/json' },
})
expect(mockSendRequest).toHaveBeenCalledWith(`${RECON_URL}/ceramic/interests`, {
method: 'POST',
body: { sep: 'model', sepValue: fakeInterest1.toString() },
headers: { 'Content-Type': 'application/json' },
})
reconApi.stop()
})
})
Expand All @@ -114,10 +122,11 @@ describe('ReconApi', () => {

test('should be able to register interest in a model', async () => {
await reconApi.registerInterest(MODEL)
expect(mockSendRequest).toHaveBeenCalledWith(
`${RECON_URL}/ceramic/interests/model/${MODEL.toString()}`,
{ method: 'POST', body: {}, headers: { 'Content-Type': 'application/json' } }
)
expect(mockSendRequest).toHaveBeenCalledWith(`${RECON_URL}/ceramic/interests`, {
method: 'POST',
body: { sep: 'model', sepValue: MODEL.toString() },
headers: { 'Content-Type': 'application/json' },
})
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/ceramic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,11 @@ export class Ceramic implements StreamReaderWriter, StreamStateLoader {
ceramicVersion: this._versionInfo.cliPackageVersion,
ipfsVersion: ipfsVersion.version,
intervalMS: this._metricsConfig?.metricsPublishIntervalMS || DEFAULT_PUBLISH_INTERVAL_MS,
nodeId: ipfsId.publicKey, // what makes the best ID for the node?
nodeId: ipfsId.id.toString(),
nodeName: '', // daemon.hostname is not useful
nodeAuthDID: this.did.id,
nodeIPAddr: '', // daemon.hostname is not the external name
nodePeerId: ipfsId.publicKey,
nodePeerId: ipfsId.id.toString(),
logger: this._logger,
})
this._logger.imp(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/recon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export class ReconApi extends Observable<ReconEventFeedResponse> implements IRec
}
try {
const headers = { 'Content-Type': 'application/json' }
const body = { ...(controller && { controller }) }
await this.#sendRequest(this.#url + `/ceramic/interests/model/${model.toString()}`, {
const body = { sep: 'model', sepValue: model.toString(), ...(controller && { controller }) }
await this.#sendRequest(this.#url + `/ceramic/interests`, {
method: 'POST',
headers,
body,
Expand Down

0 comments on commit e719816

Please sign in to comment.