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

[FEATURE] Add Webhooks #5467

Merged
merged 41 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ff01b1c
feat: add Webhooks base feature (#5453)
jfcalvo Sep 9, 2024
70a9b2e
feat: add Webhooks notify events using background jobs (#5468)
jfcalvo Sep 11, 2024
a55e884
feat: add Webhook expanded events (#5480)
jfcalvo Sep 16, 2024
935a299
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Sep 16, 2024
bea6eb0
[ENHANCEMENT] add record related webhook events (#5489)
frascuchon Sep 16, 2024
48a0dfe
[ENHANCEMENT] `argilla`: expose webhooks API (#5490)
frascuchon Sep 16, 2024
3fb3d66
chore: move webhooks folder outside api folder (#5493)
jfcalvo Sep 16, 2024
cbf28c7
feat: remove `response.upserted` webhook event (#5494)
jfcalvo Sep 16, 2024
97802e2
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Sep 18, 2024
38642ea
Merge branch 'develop' into feat/add-webhooks-feature-branch
jfcalvo Sep 19, 2024
a26f008
tests: Add tests using IP address when creating or updating webhooks …
frascuchon Sep 19, 2024
a65eb96
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Sep 19, 2024
b0931ed
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Sep 20, 2024
6cd08fe
[IMPROVEMENT] Add Webhooks delete events with expanded schemas (#5519)
jfcalvo Sep 20, 2024
208f920
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Sep 23, 2024
d2cfbed
[FIX] `webhook-timestamp` header to use current seconds since epoch v…
jfcalvo Sep 23, 2024
1afad17
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Sep 24, 2024
d8d2986
feat: add missing tests for webhooks feature (#5537)
jfcalvo Sep 25, 2024
78193c7
chore: update CHANGELOG.md
jfcalvo Sep 25, 2024
e3a443e
Merge branch 'develop' into feat/add-webhooks-feature-branch
jfcalvo Sep 25, 2024
922c59c
feat: increase webhook requests timeout from 5 to 20 seconds (#5544)
jfcalvo Sep 26, 2024
7540186
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Oct 2, 2024
3bef0e0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2024
dc52185
Apply suggestions from code review
frascuchon Oct 2, 2024
8a90dcc
tests: Fixing tests after merge
frascuchon Oct 2, 2024
22dfb92
[FEAUTURE] `argilla`: working with webhooks (#5502)
frascuchon Oct 8, 2024
f6ab425
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Oct 8, 2024
9684561
Merge branch 'develop' into feat/add-webhooks-feature-branch
jfcalvo Oct 31, 2024
ef45673
Merge branch 'develop' into feat/add-webhooks-feature-branch
jfcalvo Oct 31, 2024
39dcfc2
chore: small improvements after reviewing PR
jfcalvo Oct 31, 2024
8b69c3d
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Nov 4, 2024
622f6c3
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Nov 5, 2024
80b0a80
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Nov 8, 2024
6b82873
Merge branch 'develop' into feat/add-webhooks-feature-branch
frascuchon Nov 11, 2024
9bbdd62
chore: update CHANGELOG
frascuchon Nov 11, 2024
cb73cf6
Merge branch 'develop' into feat/add-webhooks-feature-branch
jfcalvo Nov 19, 2024
32b890e
improve: use StrEnum for Webhooks Enums
jfcalvo Nov 19, 2024
462b880
improve: define a StrEnum custom class at utils package
jfcalvo Nov 19, 2024
f1b93e3
chore: fix problem with pdm dependencies
jfcalvo Nov 19, 2024
7740799
change: use default queue instead of low queue for jobs
jfcalvo Nov 19, 2024
fe69e55
chore: Remove env/hosts section
frascuchon Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions argilla-server/.env.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES # Needed by RQ to work with forked processes on MacOS
ALEMBIC_CONFIG=src/argilla_server/alembic.ini
ARGILLA_AUTH_SECRET_KEY=8VO7na5N/jQx+yP/N+HlE8q51vPdrxqlh6OzoebIyko= # With this we avoid using a different key every time the server is reloaded
ARGILLA_DATABASE_URL=sqlite+aiosqlite:///${HOME}/.argilla/argilla.db?check_same_thread=False
1 change: 1 addition & 0 deletions argilla-server/.env.test
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ARGILLA_DATABASE_URL=sqlite+aiosqlite:///${HOME}/.argilla/argilla-test.db?check_same_thread=False
ARGILLA_REDIS_URL=redis://localhost:6379/1 # Using a different Redis database for testing
8 changes: 8 additions & 0 deletions argilla-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ These are the section headers that we use:

## [Unreleased]()

### Added

- Added new endpoints to create, update, ping and delete webhooks. ([#5453](https://github.com/argilla-io/argilla/pull/5453))
- Added new webhook events when responses are created, updated, deleted. ([#5468](https://github.com/argilla-io/argilla/pull/5468))
- Added new webhook events when datasets are created, updated, deleted or published. ([#5468](https://github.com/argilla-io/argilla/pull/5468))
- Added new webhook events when records are created, updated, deleted or completed. ([#5489](https://github.com/argilla-io/argilla/pull/5489))
- Added new `high` RQ queue to process high priority background jobs. ([#5467](https://github.com/argilla-io/argilla/pull/5467))

### Changed

- Changed default python version to 3.13. ([#5649](https://github.com/argilla-io/argilla/pull/5649))
Expand Down
1 change: 0 additions & 1 deletion argilla-server/docker/argilla-hf-spaces/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ ENV ELASTIC_CONTAINER=true
ENV ES_JAVA_OPTS="-Xms1g -Xmx1g"

ENV ARGILLA_HOME_PATH=/data/argilla
ENV BACKGROUND_NUM_WORKERS=2
ENV REINDEX_DATASETS=1

CMD ["/bin/bash", "start.sh"]
3 changes: 2 additions & 1 deletion argilla-server/docker/argilla-hf-spaces/Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
elastic: /usr/share/elasticsearch/bin/elasticsearch
redis: /usr/bin/redis-server
worker: sleep 30; rq worker-pool --num-workers ${BACKGROUND_NUM_WORKERS}
worker_high: sleep 30; rq worker-pool --num-workers 2 high
worker_default: sleep 30; rq worker-pool --num-workers 1 default
argilla: sleep 30; /bin/bash start_argilla_server.sh
111 changes: 110 additions & 1 deletion argilla-server/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion argilla-server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[project]
# Remove me
name = "argilla-server"
dynamic = ["version"]
description = "Open-source tool for exploring, labeling, and monitoring data for NLP projects."
Expand Down Expand Up @@ -55,6 +54,8 @@ dependencies = [
# For CLI
"typer >= 0.6.0, < 0.10.0", # spaCy only supports typer<0.10.0
"packaging>=23.2",
# For Webhooks
"standardwebhooks>=1.0.0",
# For HF dataset import
"datasets >= 3.0.1",
"pillow >= 10.4.0",
Expand Down Expand Up @@ -99,6 +100,8 @@ test = [
"factory-boy~=3.2.1",
"httpx>=0.26.0",
"pytest-randomly>=3.15.0",
# For mocking httpx requests and responses
"respx>=0.21.1",
# pytest-randomly requires numpy < 2.0.0
"numpy<2.0.0",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2021-present, the Recognai S.L. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""create webhooks table

Revision ID: 6ed1b8bf8e08
Revises: 660d6c6b3360
Create Date: 2024-09-02 11:41:57.561655

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "6ed1b8bf8e08"
down_revision = "660d6c6b3360"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.create_table(
"webhooks",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("url", sa.Text(), nullable=False),
sa.Column("secret", sa.Text(), nullable=False),
sa.Column("events", sa.JSON(), nullable=False),
sa.Column("enabled", sa.Boolean(), nullable=False, server_default=sa.text("true")),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("inserted_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)


def downgrade() -> None:
op.drop_table("webhooks")
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from argilla_server.models import Dataset, User
from argilla_server.search_engine import SearchEngine, get_search_engine
from argilla_server.security import auth
from argilla_server.telemetry import TelemetryClient, get_telemetry_client

router = APIRouter()

Expand All @@ -43,7 +42,6 @@ async def create_dataset_records_bulk(
db: AsyncSession = Depends(get_async_db),
search_engine: SearchEngine = Depends(get_search_engine),
current_user: User = Security(auth.get_current_user),
telemetry_client: TelemetryClient = Depends(get_telemetry_client),
):
dataset = await Dataset.get_or_raise(
db,
Expand All @@ -58,9 +56,7 @@ async def create_dataset_records_bulk(

await authorize(current_user, DatasetPolicy.create_records(dataset))

records_bulk = await CreateRecordsBulk(db, search_engine).create_records_bulk(dataset, records_bulk_create)

return records_bulk
return await CreateRecordsBulk(db, search_engine).create_records_bulk(dataset, records_bulk_create)


@router.put("/datasets/{dataset_id}/records/bulk", response_model=RecordsBulk)
Expand All @@ -71,7 +67,6 @@ async def upsert_dataset_records_bulk(
db: AsyncSession = Depends(get_async_db),
search_engine: SearchEngine = Depends(get_search_engine),
current_user: User = Security(auth.get_current_user),
telemetry_client: TelemetryClient = Depends(get_telemetry_client),
):
dataset = await Dataset.get_or_raise(
db,
Expand All @@ -86,9 +81,4 @@ async def upsert_dataset_records_bulk(

await authorize(current_user, DatasetPolicy.upsert_records(dataset))

records_bulk = await UpsertRecordsBulk(db, search_engine).upsert_records_bulk(dataset, records_bulk_upsert)

updated = len(records_bulk.updated_item_ids)
created = len(records_bulk.items) - updated

return records_bulk
return await UpsertRecordsBulk(db, search_engine).upsert_records_bulk(dataset, records_bulk_upsert)
Loading
Loading