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-BRANCH] feat: add Webhooks #5467

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

jfcalvo
Copy link
Member

@jfcalvo jfcalvo commented Sep 9, 2024

Description

This is the feature branch for Webhooks implementation.

Closes #1836

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested

  • Manually tested locally and in HF spaces.

Checklist

  • I added relevant documentation
  • I followed the style guidelines of this project
  • I did a self-review of my code
  • I made corresponding changes to the documentation
  • I confirm My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)

# Description

This PR adds the base implementation for Webhooks with the following
changes:
* Adding a new API to create/update/delete Webhooks.
* Add a new endpoint to execute a testing a ping event for a specific
Webhook.
* No background jobs integration. This is gonna be done in a different
PR.

**Type of change**

- New feature (non-breaking change which adds functionality)

**How Has This Been Tested**

- [x] Manually tested locally and in HF spaces.

**Checklist**

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: Paco Aranda <[email protected]>
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 97.33656% with 11 lines in your changes missing coverage. Please review.

Project coverage is 91.52%. Comparing base (1d9dbad) to head (a65eb96).

Files with missing lines Patch % Lines
...lla-server/src/argilla_server/jobs/webhook_jobs.py 63.33% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5467      +/-   ##
===========================================
+ Coverage    91.10%   91.52%   +0.41%     
===========================================
  Files          145      158      +13     
  Lines         5939     6345     +406     
===========================================
+ Hits          5411     5807     +396     
- Misses         528      538      +10     
Flag Coverage Δ
argilla-server 91.52% <97.33%> (+0.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

jfcalvo and others added 7 commits September 11, 2024 13:45
# Description

This PR adds the following changes:
* Add first real Webhooks notifications for responses using some
background jobs for them.
* Add a new RQ `high` queue where we will enqueue the Webhooks
notification jobs.
* Add webhook events:
  * `response.created`
  * `response.updated`
  * `response.deleted`
  * `response.upserted`
  * `dataset.created`
  * `dataset.updated`
  * `dataset.deleted`
  * `dataset.published`

**Type of change**

- New feature (non-breaking change which adds functionality)

**How Has This Been Tested**

- [x] Manually tested locally and in HF spaces.

**Checklist**

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: Damián Pumar <[email protected]>
Co-authored-by: Paco Aranda <[email protected]>
# Description

This is a PR exploring the possibility of expanding associated resources
on webhook event messages.

The following changes has been added:
* Add webhook event schemas for the following resources:
  * `Response`
  * `Record`
  * `Dataset`
  * `Workspace`
  * `User`
* Webhook events associated to deletion of resources are sending now a
simple `{"id": "id-of-the-deleted-resource"}` to avoid problems with
missing resources deleted on cascade.
* The model associations are loaded using `awaitable_attrs` to avoid
replacing the original resource instance (and avoid a database refresh
that could cause losing the state of the resource).

This is an example of a `response.created` event with the changes:

```json
{
  "type": "response.created",
  "version": 1,
  "timestamp": "2024-09-12T11:52:15.083612Z",
  "data": {
    "id": "053a845a-02fd-4951-9884-2317a4a2be19",
    "values": {
      "int_score": {
        "value": 3
      }
    },
    "status": "submitted",
    "record": {
      "id": "60eadd2c-76ed-4216-870e-9d361ac0a894",
      "status": "pending",
      "fields": {
        "text": "a combination of one or more elementary reaction steps which start with the appropriate reactants and end with the appropriate product(s)\na description of the path, or sequence of steps, by which a reaction occurs\na description of the path that a reaction takes\na detailed description of how a chemical reaction occurs\na detailed description of the way a reaction occurs and is based on the known experimental data about the reaction\na detailed (theoretical) description of how we think the chemical reaction proceeds\na series of elementary reactions or elementary steps that lead from reactants to products\na set of steps at the molecular level\na step by step description of the separate steps that occur during a chemical reaction\na stepwise description of the reaction path\nmechanism. A list of all elementary reactions that occur in the course of an overall chemical reaction.\nIn chemistry, a reaction mechanism is the step by step sequence of elementary reactions by which overall chemical change occurs."
      },
      "metadata": {
        "dump": "CC-MAIN-2013-20",
        "url": "http://www.metaglossary.com/meanings/3337605/",
        "language": "en",
        "language_score": 0.9414262175559998,
        "token_count": 195,
        "score": 3.671875
      },
      "external_id": "<urn:uuid:7ae3a60b-341f-4a49-8f9d-b5b4588f2f8d>",
      "dataset": {
        "id": "408239b6-d100-4eff-b5d9-afcc8e99b9f1",
        "name": "fineweb-edu-min-submitted-big",
        "guidelines": null,
        "allow_extra_metadata": false,
        "status": "ready",
        "distribution": {
          "strategy": "overlap",
          "min_submitted": 1
        },
        "workspace": {
          "id": "350bc020-2cd2-4a67-8b23-37a15c4d8139",
          "name": "argilla",
          "inserted_at": "2024-09-05T11:39:20.377192",
          "updated_at": "2024-09-05T11:39:20.377192"
        },
        "questions": [
          {
            "id": "f6453e3a-5ed2-4853-a8c4-913d03bc1dfb",
            "name": "int_score",
            "title": "Rate the quality of the text",
            "description": null,
            "required": true,
            "settings": {
              "type": "rating",
              "options": [
                {
                  "value": 0
                },
                {
                  "value": 1
                },
                {
                  "value": 2
                },
                {
                  "value": 3
                },
                {
                  "value": 4
                },
                {
                  "value": 5
                }
              ]
            },
            "inserted_at": "2024-09-06T10:21:25.482006",
            "updated_at": "2024-09-06T10:21:25.482006"
          },
          {
            "id": "4d0b53e6-9b96-42da-a863-2c17d483be01",
            "name": "comments",
            "title": "Comments:",
            "description": null,
            "required": false,
            "settings": {
              "type": "text",
              "use_markdown": false
            },
            "inserted_at": "2024-09-06T10:21:25.493565",
            "updated_at": "2024-09-06T10:21:25.493565"
          }
        ],
        "fields": [
          {
            "id": "02ef122a-d989-4422-89ad-e29096a1acfd",
            "name": "text",
            "title": "text",
            "required": true,
            "settings": {
              "type": "text",
              "use_markdown": false
            },
            "inserted_at": "2024-09-06T10:21:25.468310",
            "updated_at": "2024-09-06T10:21:25.468310"
          }
        ],
        "metadata_properties": [
          {
            "id": "c79d1808-7551-4fb8-b673-b5bb0bec0532",
            "name": "dump",
            "title": "dump",
            "settings": {
              "type": "terms",
              "values": null
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.506303",
            "updated_at": "2024-09-06T10:21:25.506303"
          },
          {
            "id": "1195fc9b-0974-498f-8cff-6feddfd6e9a1",
            "name": "url",
            "title": "url",
            "settings": {
              "type": "terms",
              "values": null
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.516085",
            "updated_at": "2024-09-06T10:21:25.516085"
          },
          {
            "id": "28cc925c-fed6-48bf-a1df-ef43e884b33b",
            "name": "language",
            "title": "language",
            "settings": {
              "type": "terms",
              "values": null
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.523871",
            "updated_at": "2024-09-06T10:21:25.523871"
          },
          {
            "id": "9333a2c9-efaf-4b0e-88e7-b1ed24dfcbfa",
            "name": "language_score",
            "title": "language_score",
            "settings": {
              "min": null,
              "max": null,
              "type": "float"
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.532447",
            "updated_at": "2024-09-06T10:21:25.532447"
          },
          {
            "id": "9d56b399-3c53-4e98-9d4a-ebfb360ec293",
            "name": "token_count",
            "title": "token_count",
            "settings": {
              "min": null,
              "max": null,
              "type": "integer"
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.539531",
            "updated_at": "2024-09-06T10:21:25.539531"
          },
          {
            "id": "6c701f7b-de47-4224-b9b0-3629133282ed",
            "name": "score",
            "title": "score",
            "settings": {
              "min": null,
              "max": null,
              "type": "float"
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.546505",
            "updated_at": "2024-09-06T10:21:25.546505"
          }
        ],
        "vectors_settings": [],
        "last_activity_at": "2024-09-12T11:52:15.030317",
        "inserted_at": "2024-09-06T10:21:25.443578",
        "updated_at": "2024-09-12T11:52:04.923388"
      },
      "inserted_at": "2024-09-06T10:21:27.790000",
      "updated_at": "2024-09-06T10:21:27.790000"
    },
    "user": {
      "id": "df114042-958d-42c6-9f03-ab49bd451c6c",
      "first_name": "",
      "last_name": null,
      "username": "argilla",
      "role": "owner",
      "inserted_at": "2024-09-05T11:39:20.376463",
      "updated_at": "2024-09-05T11:39:20.376463"
    },
    "inserted_at": "2024-09-12T11:52:15.029023",
    "updated_at": "2024-09-12T11:52:15.029023"
  }
}
```

There are still missing changes and solutions to explore:
- [ ] Review some associations that we can still add to the events.
- [ ] Review if some missing endpoints are necessary.
- [ ] Should we truncate record field values that are too large?
- [ ] For example truncate image field values. Something like
`afdsmk432mkfseiwer...(truncated)`
- [ ] Update CHANGELOG if necessary.

**Type of change**

- New feature (non-breaking change which adds functionality)

**How Has This Been Tested**

- [ ] Manually test the new events on HF spaces.

**Checklist**

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

This PR adds record-related webhook events: `created`, `updated`,
`deleted` and `completed`

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->

- Improvement (change adding some improvement to an existing
functionality)

**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: José Francisco Calvo <[email protected]>
# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

This PR exposes the new webhooks API through the low-level `client.api`
component. Once the backend API and SDK flows are validated, we can work
on exposing webhooks as client resource level

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Refactor (change restructuring the codebase without changing
functionality)
- Improvement (change adding some improvement to an existing
functionality)
- Documentation update

**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
# Description

As discussed this PR is moving `webhooks` folder outside `api` folder.
Now that we have specific schemas for webhooks it does not have much
sense to have this code inside the `api` folder.

Refs #1836 

**Type of change**

- Refactor (change restructuring the codebase without changing
functionality)

**How Has This Been Tested**

- [x] Running test suite.

**Checklist**

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
# Description

As discussed we want to stop using `response.upserted` webhook event and
instead use `response.created` or `response.updated` when a response is
upserted.

Refs #1836 

**Type of change**

- New feature (non-breaking change which adds functionality)

**How Has This Been Tested**

- [x] Running test suite.

**Checklist**

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
@jfcalvo jfcalvo added this to the v2.3.0 milestone Sep 17, 2024
frascuchon and others added 4 commits September 18, 2024 11:00
…5511)

# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

Since URLs including IP addresses are allowed values when
creating/updating webhooks, this PR only adds tests checking these
scenarios.

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->


**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: José Francisco Calvo <[email protected]>
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.

Webhooks
2 participants