Skip to content

Commit

Permalink
3023 monitoring (#735)
Browse files Browse the repository at this point in the history
* feat: adding monitoring for the v2 version of the api

* feat: update workflow with new parameter for 'get_unmonitored_urls' + fix monitoring config
  • Loading branch information
nutrina authored Nov 18, 2024
1 parent c40f5a1 commit f014a95
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
CERAMIC_CACHE_ADDRESS: ${{ env.CERAMIC_CACHE_ADDRESS }}

run:
python manage.py get_unmonitored_urls --base-url https://api.scorer.gitcoin.co/
python manage.py get_unmonitored_urls --base-url https://api.scorer.gitcoin.co/ --base-url-xyz https://api.passport.xyz/

ui-test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_generic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
CERAMIC_CACHE_JWT_TOKEN: ${{ env.CERAMIC_CACHE_JWT_TOKEN }}
CERAMIC_CACHE_ADDRESS: ${{ env.CERAMIC_CACHE_ADDRESS }}

run: python manage.py get_unmonitored_urls --base-url https://api.scorer.gitcoin.co/ ${{ inputs.uptime-robot-monitor-dry-run }}
run: python manage.py get_unmonitored_urls --base-url https://api.scorer.gitcoin.co/ --base-url-xyz https://api.passport.xyz/ ${{ inputs.uptime-robot-monitor-dry-run }}

- name: Run API unittests
working-directory: ./api
Expand Down
8 changes: 7 additions & 1 deletion api/registry/management/commands/get_unmonitored_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def add_arguments(self, parser):
help="Base URL for the site (uptime robot URLs will be filtered using this)",
required=True,
)
parser.add_argument(
"--base-url-xyz",
type=str,
help="Base URL for the XYZ host (uptime robot URLs will be filtered using this)",
required=True,
)
parser.add_argument(
"--allow-paused",
type=bool,
Expand Down Expand Up @@ -89,7 +95,7 @@ def get_unmonitored_urls(self, kwargs, auto_check_monitors):
num_missing_config = 0
num_skipped_namespaces = 0
num_skipped_endpoints = 0
config = get_config(kwargs["base_url"])
config = get_config(kwargs["base_url"], kwargs["base_url_xyz"])
for api in apis:
openapi = OpenAPISchema(api=api, path_prefix="")
paths = openapi.get("paths", {})
Expand Down
42 changes: 31 additions & 11 deletions api/registry/management/commands/get_unmonitored_urls_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}


def get_config(base_url: str) -> dict:
def get_config(base_url: str, base_url_xyz: str) -> dict:
return {
# Public API
"registry": {
Expand Down Expand Up @@ -100,38 +100,38 @@ def get_config(base_url: str) -> dict:
"urls": {
# No auth required
("GET", "/ceramic-cache/stamp"): {
"url": f"{base_url}ceramic-cache/stamp?address={CERAMIC_CACHE_ADDRESS}",
"url": f"{base_url_xyz}ceramic-cache/stamp?address={CERAMIC_CACHE_ADDRESS}",
},
("GET", "/ceramic-cache/weights"): {
"url": f"{base_url}ceramic-cache/weights",
"url": f"{base_url_xyz}ceramic-cache/weights",
},
# Auth required
("GET", "/ceramic-cache/stake/gtc"): {
"url": f"{base_url}ceramic-cache/stake/gtc",
"url": f"{base_url_xyz}ceramic-cache/stake/gtc",
"http_headers": {
"Authorization": f"Bearer {CERAMIC_CACHE_JWT_TOKEN}"
},
},
("GET", "/ceramic-cache/score/{address}"): {
"url": f"{base_url}ceramic-cache/score/{CERAMIC_CACHE_ADDRESS}",
"url": f"{base_url_xyz}ceramic-cache/score/{CERAMIC_CACHE_ADDRESS}",
"http_headers": {
"Authorization": f"Bearer {CERAMIC_CACHE_JWT_TOKEN}"
},
},
("GET", "/ceramic-cache/tos/accepted/{tos_type}/{address}"): {
"url": f"{base_url}ceramic-cache/tos/accepted/ISI/{CERAMIC_CACHE_ADDRESS}",
"url": f"{base_url_xyz}ceramic-cache/tos/accepted/ISI/{CERAMIC_CACHE_ADDRESS}",
"http_headers": {
"Authorization": f"Bearer {CERAMIC_CACHE_JWT_TOKEN}"
},
},
("GET", "/ceramic-cache/tos/message-to-sign/{tos_type}/{address}"): {
"url": f"{base_url}ceramic-cache/tos/message-to-sign/IST/{CERAMIC_CACHE_ADDRESS}",
"url": f"{base_url_xyz}ceramic-cache/tos/message-to-sign/IST/{CERAMIC_CACHE_ADDRESS}",
"http_headers": {
"Authorization": f"Bearer {CERAMIC_CACHE_JWT_TOKEN}"
},
},
("PATCH", "/ceramic-cache/stamps/bulk/meta/compose-db"): {
"url": f"{base_url}ceramic-cache/stamps/bulk/meta/compose-db",
"url": f"{base_url_xyz}ceramic-cache/stamps/bulk/meta/compose-db",
"http_headers": {
"Authorization": f"Bearer {CERAMIC_CACHE_JWT_TOKEN}"
},
Expand All @@ -143,15 +143,15 @@ def get_config(base_url: str) -> dict:
("POST", "/ceramic-cache/score/{address}"): {
# TODO: do we still use this POST API ???
"skip": True, # Skipping because uptime robot api rejects creating multiple monitors on same endpoint
"url": f"{base_url}ceramic-cache/score/{CERAMIC_CACHE_ADDRESS}",
"url": f"{base_url_xyz}ceramic-cache/score/{CERAMIC_CACHE_ADDRESS}",
"http_headers": {
"Authorization": f"Bearer {CERAMIC_CACHE_JWT_TOKEN}"
},
"payload": {"alternate_scorer_id": REGISTRY_SCORER_ID},
},
("POST", "/ceramic-cache/stamps/bulk"): {
"skip": True, # Skipping because uptime robot api rejects creating multiple monitors on same endpoint
# "url": f"{base_url}ceramic-cache/stamps/bulk",
# "url": f"{base_url_xyz}ceramic-cache/stamps/bulk",
# "http_headers": {
# "Authorization": f"Bearer {CERAMIC_CACHE_JWT_TOKEN}"
# },
Expand All @@ -178,7 +178,27 @@ def get_config(base_url: str) -> dict:
"v2": {
"urls": {
("GET", "/v2/stamps/{scorer_id}/score/{address}"): {
"url": f"{base_url}v2/stamps/{REGISTRY_SCORER_ID}/score/{REGISTRY_ADDRESS}",
"url": f"{base_url_xyz}v2/stamps/{REGISTRY_SCORER_ID}/score/{REGISTRY_ADDRESS}",
"http_headers": {"X-API-Key": REGISTRY_API_KEY},
"success_http_statues": [200],
},
("GET", "/v2/stamps/{scorer_id}/score/{address}/history"): {
"url": f"{base_url_xyz}v2/stamps/{REGISTRY_SCORER_ID}/score/{REGISTRY_ADDRESS}/history",
"http_headers": {"X-API-Key": REGISTRY_API_KEY},
"success_http_statues": [200],
},
("GET", "/v2/stamps/{address}"): {
"url": f"{base_url_xyz}v2/stamps/{REGISTRY_ADDRESS}",
"http_headers": {"X-API-Key": REGISTRY_API_KEY},
"success_http_statues": [200],
},
("GET", "/v2/stamps/metadata"): {
"url": f"{base_url_xyz}v2/stamps/metadata",
"http_headers": {"X-API-Key": REGISTRY_API_KEY},
"success_http_statues": [200],
},
("GET", "/v2/models/score/{address}"): {
"url": f"{base_url_xyz}v2/models/score/{REGISTRY_ADDRESS}",
"http_headers": {"X-API-Key": REGISTRY_API_KEY},
"success_http_statues": [200],
},
Expand Down
11 changes: 9 additions & 2 deletions api/scorer/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from typing import List, Optional

from django.conf import settings
from django_ratelimit.exceptions import Ratelimited
from ninja import NinjaAPI
from ninja.openapi.schema import OpenAPISchema
Expand All @@ -22,6 +23,7 @@
from registry.api.utils import get_passport_api_rate_limited_msg
from registry.api.v1 import feature_flag_router
from registry.api.v1 import router as registry_router_v1
from v2.api import api as registry_api_v2


###############################################################################
Expand Down Expand Up @@ -92,14 +94,19 @@ def service_unavailable(request, _):


ceramic_cache_api_v1 = NinjaAPI(urls_namespace="ceramic-cache", docs_url=None)
ceramic_cache_api_v1.add_router("", ceramic_cache_router_v1)
ceramic_cache_api_v1.add_router("/ceramic-cache", ceramic_cache_router_v1)


passport_admin_api = NinjaAPI(urls_namespace="passport-admin", docs_url=None)
passport_admin_api.add_router("", passport_admin_router)
passport_admin_api.add_router("/passport-admin", passport_admin_router)


apis = [
registry_api_v1,
ceramic_cache_api_v1,
passport_admin_api,
]


if settings.FF_V2_API == "on":
apis.append(registry_api_v2)
13 changes: 2 additions & 11 deletions api/scorer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@
"""

# from rest_framework.schemas import get_schema_view
from django.conf import settings
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import include, path

from account.api import health
from scorer.api import apis as api_list

from .api import (
ceramic_cache_api_v1,
feature_flag_api,
passport_admin_api,
registry_api_v1,
)

urlpatterns = [
path("", registry_api_v1.urls),
path("registry/feature/", feature_flag_api.urls),
path("ceramic-cache/", ceramic_cache_api_v1.urls),
# path("ceramic-cache/v2/", ceramic_cache_api_v2.urls),
path("cgrants/", include("cgrants.urls")),
path("health/", health, {}, "health-check"),
path(
Expand All @@ -44,13 +38,10 @@
path("admin/", admin.site.urls),
path("account/", include("account.urls")),
path("social/", include("social_django.urls", namespace="social")),
path("passport-admin/", passport_admin_api.urls),
# path("__debug__/", include("debug_toolbar.urls")),
path("trusta_labs/", include("trusta_labs.urls")),
path("stake/", include("stake.urls")),
path("passport/", include("passport.urls")),
path("internal/", include("internal.urls")),
]

if settings.FF_V2_API == "on":
urlpatterns.append(path("v2/", include("v2.urls")))
urlpatterns += [path("", api.urls) for api in api_list]
20 changes: 3 additions & 17 deletions api/v2/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
from django_ratelimit.exceptions import Ratelimited
from ninja_extra import NinjaExtraAPI

from account.models import (
Nonce,
)
from registry.api.schema import (
ErrorMessageResponse,
SigningMessageResponse,
)
from registry.api.utils import (
ApiKey,
check_rate_limit,
track_apikey_usage,
)
from registry.utils import (
get_signing_message,
)

from .api_models import *
from .api_stamps import *
from .router import api_router
Expand All @@ -27,10 +11,12 @@
title="Passport Developer Platform",
description="The Passport Developer Platform's endpoints enable you to retrieve Passport scores, Stamps, analysis, and metadata.",
version="2.0.0",
docs_url="/v2/docs",
openapi_url="/v2/openapi.json",
)


api.add_router("", api_router)
api.add_router("/v2", api_router)


@api.exception_handler(Ratelimited)
Expand Down

0 comments on commit f014a95

Please sign in to comment.