Skip to content

New APIs for Promgen #578

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

New APIs for Promgen #578

wants to merge 17 commits into from

Conversation

hoangpn
Copy link
Contributor

@hoangpn hoangpn commented Mar 14, 2025

Add APIs that now allow users to fully interact with Promgen via the API. This includes:

  • Retrieving, creating, editing, and deleting Services
  • Retrieving, creating, editing, and deleting Projects
  • Retrieving, creating, editing, and deleting Farms
  • Retrieving, creating, editing, and deleting Notifiers and Rules associated with a Service or Project
  • Retrieving and updating information related to Projects such as Exporters, URLs
  • Retrieving Shard information
  • Retrieving Audit history
  • Retrieving User information

The new APIs have the prefix /rest/v2. The API Specification for these new APIs can be accessed through the menu Misc -> API v2.
This specification flow the Open API Standard, therefore users can download YAML file and import it to many tools such as Swagger Editor or Postman.
image

Non-GET APIs require authentication. Each user's token can be obtained by accessing the Profile page.
image

These APIs have separate rate limit thresholds set for IP addresses (for unauthenticated users) and user_id (for authenticated users).
https://github.com/line/promgen/pull/578/files#diff-f81908c759379ab44e3e0e2ffbc41d8c559e648d7c30df301d6cc6bcaac85208R206-R213

Detailed data about the request/response of the APIs can also be logged when setting.ENABLE_API_LOGGING=True is configured.
https://github.com/line/promgen/pull/578/files#diff-f81908c759379ab44e3e0e2ffbc41d8c559e648d7c30df301d6cc6bcaac85208R247

@hoangpn hoangpn requested a review from a team as a code owner March 14, 2025 08:13
@hoangpn hoangpn force-pushed the feature/new_apis branch 10 times, most recently from 6e95e31 to aef3f79 Compare March 26, 2025 04:10
@hoangpn hoangpn force-pushed the feature/new_apis branch 4 times, most recently from 99d5e1a to e8fa273 Compare March 27, 2025 02:40
@hoangpn hoangpn changed the title [WIP] Feature/new apis New APIs for Promgen Mar 27, 2025
@hoangpn hoangpn force-pushed the feature/new_apis branch 3 times, most recently from c58a8c5 to 7981f71 Compare April 1, 2025 09:43
@hoangpn hoangpn force-pushed the feature/new_apis branch 4 times, most recently from 73415b2 to 05bc663 Compare April 3, 2025 10:44
hoangpn added 7 commits April 10, 2025 08:52
When accessing APIs created by Promgen's Django REST Framework, users will need a Token
for authentication. We have added a new panel on the Profile page that allows users to
create and manage their own tokens.
We plan to add version v2 to Promgen's API. We have chosen drf-spectacular as
the OpenAPI 3 Schema Generation for these new APIs.
We also use Rapidoc for the OpenAPI Spec Documentation.
Users must be authenticated before making any REST calls to Promgen's APIs.
We changed the default permission class of Django REST Framework
from DjangoModelPermissionsOrAnonReadOnly to DjangoModelPermissions.
- Add v2 Router for v2 APIs.
- Create rest_v2.py file with base functions: RuleMixin, NotifierMixin and PromgenPagination.
 We have added several APIs for retrieving User data.
- List User
- Get the User data based on the current Token
We have added several APIs for retrieving and filtering Audit Log data.
We have added several APIs for retrieving and updating Notifier, as well as Notifier's filters.
hoangpn added 10 commits April 10, 2025 10:38
We have added several APIs for retrieving, updating and deleting Rule.
We have added several APIs for interacting with Farm, as well as Farm's hosts.
We have added several APIs for retrieving Exporter data.
We have added several APIs for retrieving URL data.
We have added several APIs to help users easily manage Projects
and objects related to each project, such as notifiers, rules, exporters, and URLs.
We have added several APIs to help users easily manage Services
and objects related to each service, includes notifiers and rules.
We have added several APIs for retrieving Shard data and the list of projects for each shard.
Add a custom exception handler to wrap all exceptions that are not handled
by the REST framework's default exception handler into a JSON response
with a 500 Internal Server Error HTTP status code.
We add two limits to the number of requests from authenticated users and non-authenticated users
to prevent the APIs from being overloaded.
We have added middleware logging for request/response to API calls via v2 APIs. The logging
information includes the IP address, user (if authenticated), request details, and response details.
Enabling or disabling this logging can be configured through setting.ENABLE_API_LOGGING.
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.

1 participant