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 persist API #1575

Merged
merged 1 commit into from
Jan 31, 2024
Merged

Add persist API #1575

merged 1 commit into from
Jan 31, 2024

Conversation

TBonnin
Copy link
Collaborator

@TBonnin TBonnin commented Jan 30, 2024

First commit implementing the persist API.
The goal is to remove the database dependency for the runner. Writing customers data (batchSave/.../activityLogs/lastSyncDate) will go through this API
All of it behind a feature flag

Next PR: take care of removing db dependency for proxy.

Issue ticket number and link

https://linear.app/nango/issue/NAN-270/persist-api

Checklist before requesting a review (skip if just adding/editing APIs & templates)

  • I added tests, otherwise the reason is:
  • I added observability, otherwise the reason is: will do in follow up PR
  • I added analytics, otherwise the reason is:

steps[step - 1]?.();
};
}
}
Copy link
Collaborator Author

@TBonnin TBonnin Jan 30, 2024

Choose a reason for hiding this comment

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

ideally I would like to have a real in-memory database that can be used in tests. But knex in-memory solution is to use sqlite which doesn't support our schema.
So for now I am just mocking the db queries

} else {
next();
}
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do we want some sort of authorization mechanism to make sure requests are legit and actually made from a runner?

Copy link
Member

Choose a reason for hiding this comment

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

If the persist service is a private service then I don't think that is necessary yet.

@TBonnin TBonnin force-pushed the tbonnin/persist-1 branch 3 times, most recently from 1549099 to bbf9399 Compare January 30, 2024 13:34
}),
body: z.object({
activityLogId: z.number(),
level: z.enum(['info', 'debug', 'error', 'warn', 'http', 'verbose', 'silly']),

This comment was marked as resolved.

@TBonnin TBonnin force-pushed the tbonnin/persist-1 branch 14 times, most recently from 2da6a86 to 4534a44 Compare January 31, 2024 09:36
docker buildx imagetools create nangohq/nango-persist:${{ github.sha }} --tag nangohq/nango-persist:${{ inputs.stage }}
- name: Deploy persist
run: |
SERVICE_ID=${{ fromJson('{ production: "srv-XXXXXXXXXXXXX", staging: "srv-cmsfiqqcn0vc73bhcod0" }')[inputs.stage] }}
Copy link
Member

Choose a reason for hiding this comment

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

We have this prod value now right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep. let me update it

export const server = express();
server.use(express.json());

// logging middleware
Copy link
Member

Choose a reason for hiding this comment

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

can the non helpful comments be removed?

console.log(`[Persist] ${req.method} ${req.path} ${res.statusCode}`);
});

// routes
Copy link
Member

Choose a reason for hiding this comment

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

^ remove

);
server.put('/environment/:environmentId/connection/:connectionId/sync/:syncId/job/:syncJobId/records', validateRecordsRequest, persistController.updateRecords);

// error handling middleware
Copy link
Member

Choose a reason for hiding this comment

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

^ remove

@khaliqgant khaliqgant self-requested a review January 31, 2024 10:01
Copy link
Member

@khaliqgant khaliqgant 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. Couple of non blocking comments and the note to add the persist server address in the github action

The goal is to remove the database dependency for the runner.
Writing customers data (batchSave/.../activityLogs/lastSyncDate) will go
through this API
@TBonnin TBonnin merged commit 900fe1b into master Jan 31, 2024
32 checks passed
@TBonnin TBonnin deleted the tbonnin/persist-1 branch January 31, 2024 10:13
type LogLevel = 'info' | 'debug' | 'error' | 'warn' | 'http' | 'verbose' | 'silly';
import axios from 'axios';
import { getPersistAPIUrl } from '../utils/utils.js';
import type { LogLevel } from '../models/Activity.js';
Copy link
Member

Choose a reason for hiding this comment

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

@TBonnin FYI any type needs to not be imported which is why all the types are in this file. This causes this error as reported in Slack

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