airbyte icon indicating copy to clipboard operation
airbyte copied to clipboard

🐛 [source-linkedin-ads] fix re-adding sponsored content stream

Open FVidalCarneiro opened this issue 1 year ago • 9 comments

What

This pull request recovers the removed Ad Sponsored Content stream, and therefore solve the issue described here. To summarize the issue, this stream was removed without explanation and ingested data from an important and still usable Linkedin endpoint (doc here).

Fixes (https://github.com/airbytehq/airbyte/issues/35635)

How

To add this stream, the removed code was recovered and adapted to be compatible with the current version of the code.

Recommended reading order

  1. streams.py
  2. source.py
  3. test_source.py
  4. ad_direct_sponsored_contents.json

🚨 User Impact 🚨

No breaking changes, other streams were not effected, only one was added.

This change should therefore be a patch (if seen as a bug fix) or a minor change, if seen as a new feature added.

Pre-merge Actions

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Unit & integration tests added

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.

  • To see the specific tasks where the Asana app for GitHub is being used, see below:
    • https://app.asana.com/0/0/1206685813413289

FVidalCarneiro avatar Feb 27 '24 09:02 FVidalCarneiro

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
airbyte-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2024 10:50am

vercel[bot] avatar Feb 27 '24 09:02 vercel[bot]

The endpoint was removed in https://github.com/airbytehq/airbyte/pull/26372 @artem1205 can you take a look as you made the pull request? Can you confirm this endpoint is not deprecated?

marcosmarxm avatar Mar 20 '24 15:03 marcosmarxm

@marcosmarxm ,

Can you confirm this endpoint is not deprecated?

I can confirm that mentioned stream (endpoint) is no longer supported in Linkedin Ads. I don't see any proofs from the provided docs.

@FVidalCarneiro, Could you please provide some test results to confirm that this endpoint is still functional?

artem1205 avatar Mar 20 '24 16:03 artem1205

Hi @artem1205 , thank you for your time to take a look at our PR. The documentation is not at all clear regarding this endpoint, I have updated the documentation links with a more useful link, you can verify the existence of this endpoint as well through this link.

I confirm what the documentation states and therefore that the endpoint does exist and is working today. Please find below a screenshot of an example API call to the given endpoint using postman:

proof_endpoint_exists

I have likewise tested the code with a local run on our data and the data is collected as expected, we collect multiple elements and each element has the a schema of the following example record:

{
        "duration": 15000,
        "aspectRatioWidth": 9.0,
        "owner": "urn:li:organization:111111",
        "thumbnail": "https://link.com/path",
        "downloadUrlExpiresAt": 1711627200000,
        "downloadUrl": "https://link-2.com/path",
        "aspectRatioHeight": 16.0,
        "id": "urn:li:video:5555555",
        "mediaLibraryMetadata": {
            "associatedAccount": "urn:li:sponsoredAccount:222222",
            "mediaLibraryStatus": "ACTIVE",
            "assetName": "asset-name-example.mp4"
}

FVidalCarneiro avatar Mar 21 '24 11:03 FVidalCarneiro

@artem1205 , did you have time to verify that the endpoint exists by taking a look at my comment above ? @marcosmarxm , are there any other blockers for this PR to be merged ?

FVidalCarneiro avatar Apr 10 '24 15:04 FVidalCarneiro

Hello @natikgadzhi , as promised, here is a description of why we need this endpoint.

Essentially, Linkedin adverts are obtained through the endpoint Linkedin Creatives. Creatives, reference some sort of content, like videos through a field called reference (more information on this on the creatives endpoint documentation). This is the field we use to make a join with the adSponsoredContent object, field content_reference. We need to make this join in order to obtain the name of the video that is associated to the Linkedin Creative we are analyzing. The adSponsoredContent is currently the only endpoint we could find that can give us the information necessary to make this join / connection.

The documentation of this adSponsoredContent object is available here.

FVidalCarneiro avatar Apr 24 '24 13:04 FVidalCarneiro

Essentially, Linkedin adverts are obtained through the endpoint Linkedin Creatives. Creatives, reference some sort of content, like videos through a field called reference (more information on this on the creatives endpoint documentation). This is the field we use to make a join with the adSponsoredContent object, field content_reference. We need to make this join in order to obtain the name of the video that is associated to the Linkedin Creative we are analyzing. The adSponsoredContent is currently the only endpoint we could find that can give us the information necessary to make this join / connection.

The documentation of this adSponsoredContent object is available here.

Can you add this to the readme + docs for this connector? I think this will be useful for others, plus we're migrating the connector to low-code and I would love to not miss this.

Additionally, @FVidalCarneiro when we will migrate this to low code, would you like to be a reviewer on our PR? /cc @lazebnyi

natikgadzhi avatar Apr 24 '24 16:04 natikgadzhi

@natikgadzhi , as requested, I have added documentation regarding the ad sponsored contents stream. Let me know if you want us to add more details

FVidalCarneiro avatar May 02 '24 19:05 FVidalCarneiro

@FVidalCarneiro, I've kicked off the CI run on this! Thank you for continuing to work on it.

I see that formatters errored out on source_linkedin_ads/source.py - run airbyte-ci format fix all locally, or run poetry run black just for this file from the repo root.

natikgadzhi avatar May 05 '24 14:05 natikgadzhi

/format-fix pr=35655

Format-fix job started... Check job output.

natikgadzhi avatar May 28 '24 22:05 natikgadzhi

Kicking off the CI, let's see what's going on here.

natikgadzhi avatar May 28 '24 22:05 natikgadzhi

Hi @natikgadzhi , thanks, just pushed another commit to fix formatting errors (apologies for not having done it earlier). Tests seem to pass now !

FVidalCarneiro avatar May 29 '24 08:05 FVidalCarneiro

@natikgadzhi , just solved the merge conflicts

FVidalCarneiro avatar Jun 18 '24 16:06 FVidalCarneiro

/format-fix

Format-fix job started... Check job output.

❌ Job failed.

marcosmarxm avatar Jun 18 '24 20:06 marcosmarxm

I'll review the rest, but you'd need to airbyte-ci format fix all in your fork, our format-fix can't commit back to your fork ;)

natikgadzhi avatar Jun 18 '24 21:06 natikgadzhi

@natikgadzhi , ran the formatting again, must of introduced an issue when solving merge conflicts, thanks for the heads up

FVidalCarneiro avatar Jun 19 '24 09:06 FVidalCarneiro

Running CI @FVidalCarneiro let's wait for results.

marcosmarxm avatar Jun 26 '24 15:06 marcosmarxm

process "python /airbyte/integration_code/main.py spec" did not complete successfully: exit code: 1
Stdout:
{"type": "LOG", "log": {"level": "FATAL", "message": "Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\nTraceback (most recent call last):\n  File \"/airbyte/integration_code/main.py\", line 8, in <module>\n    run()\n  File \"/airbyte/integration_code/source_linkedin_ads/run.py\", line 14, in run\n    launch(source, sys.argv[1:])\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 235, in launch\n    for message in source_entrypoint.run(parsed_args):\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 97, in run\n    source_spec: ConnectorSpecification = self.source.spec(self.logger)\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/connector.py\", line 86, in spec\n    raise RuntimeError(\"Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\")\nRuntimeError: Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided."}}
{"type": "TRACE", "trace": {"type": "ERROR", "emitted_at": 1719414714121.64, "error": {"message": "Something went wrong in the connector. See the logs for more details.", "internal_message": "Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.", "stack_trace": "Traceback (most recent call last):\n  File \"/airbyte/integration_code/main.py\", line 8, in <module>\n    run()\n  File \"/airbyte/integration_code/source_linkedin_ads/run.py\", line 14, in run\n    launch(source, sys.argv[1:])\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 235, in launch\n    for message in source_entrypoint.run(parsed_args):\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 97, in run\n    source_spec: ConnectorSpecification = self.source.spec(self.logger)\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/connector.py\", line 86, in spec\n    raise RuntimeError(\"Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\")\nRuntimeError: Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\n", "failure_type": "system_error", "stream_descriptor": null}}}

I see you've added spec.json — probably change things in spec.yaml instead.

natikgadzhi avatar Jun 26 '24 15:06 natikgadzhi

@FVidalCarneiro here you can access the report

marcosmarxm avatar Jun 26 '24 15:06 marcosmarxm

process "python /airbyte/integration_code/main.py spec" did not complete successfully: exit code: 1
Stdout:
{"type": "LOG", "log": {"level": "FATAL", "message": "Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\nTraceback (most recent call last):\n  File \"/airbyte/integration_code/main.py\", line 8, in <module>\n    run()\n  File \"/airbyte/integration_code/source_linkedin_ads/run.py\", line 14, in run\n    launch(source, sys.argv[1:])\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 235, in launch\n    for message in source_entrypoint.run(parsed_args):\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 97, in run\n    source_spec: ConnectorSpecification = self.source.spec(self.logger)\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/connector.py\", line 86, in spec\n    raise RuntimeError(\"Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\")\nRuntimeError: Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided."}}
{"type": "TRACE", "trace": {"type": "ERROR", "emitted_at": 1719414714121.64, "error": {"message": "Something went wrong in the connector. See the logs for more details.", "internal_message": "Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.", "stack_trace": "Traceback (most recent call last):\n  File \"/airbyte/integration_code/main.py\", line 8, in <module>\n    run()\n  File \"/airbyte/integration_code/source_linkedin_ads/run.py\", line 14, in run\n    launch(source, sys.argv[1:])\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 235, in launch\n    for message in source_entrypoint.run(parsed_args):\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/entrypoint.py\", line 97, in run\n    source_spec: ConnectorSpecification = self.source.spec(self.logger)\n  File \"/usr/local/lib/python3.9/site-packages/airbyte_cdk/connector.py\", line 86, in spec\n    raise RuntimeError(\"Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\")\nRuntimeError: Found multiple spec files in the package. Only one of spec.yaml or spec.json should be provided.\n", "failure_type": "system_error", "stream_descriptor": null}}}

I see you've added spec.json — probably change things in spec.yaml instead.

Thanks @natikgadzhi , my bad, removed the spec.json file keeping the yaml file. You can go ahead and relaunch the CI

FVidalCarneiro avatar Jun 27 '24 12:06 FVidalCarneiro

@FVidalCarneiro here you can access the report

@marcosmarxm , link expired 🤔

FVidalCarneiro avatar Jun 27 '24 12:06 FVidalCarneiro

@marcosmarxm , as described by @natikgadzhi, I believe the last test is on your end to solve (regarding the sandbox account and acceptance-test-config). Could you please confirm this ? Also, I see that this PR still has your request for changes that I think we responded to, can you confirm this ?

FVidalCarneiro avatar Jul 04 '24 13:07 FVidalCarneiro

The error is:

E Failed: High strictness level error: posts streams are declared in the catalog but do not have expected records. Please add expected records to integration_tests/expected_records.jsonl or declare these streams in empty_streams.

We need to add the expected records this stream is reading from sandbox account.

marcosmarxm avatar Jul 04 '24 13:07 marcosmarxm

The error is:

E Failed: High strictness level error: posts streams are declared in the catalog but do not have expected records. Please add expected records to integration_tests/expected_records.jsonl or declare these streams in empty_streams.

We need to add the expected records this stream is reading from sandbox account.

@marcosmarxm , ok so do you want us to add some fictive records or will you add some from your sandbox account ?

FVidalCarneiro avatar Jul 04 '24 13:07 FVidalCarneiro

@FVidalCarneiro I think now is up to us fix some tests requires access to Airbyte sandbox.

{"type": "RECORD", "record": {"stream": "posts", "data": {"lifecycleState": "PUBLISHED", "lastModifiedAt": 1629888842072, "visibility": "PUBLIC", "publishedAt": 1629888842026, ..., "emitted_at": 1720101201826}} {"type": "RECORD", "record": {"stream": "posts", "data": {"lifecycleState": "PUBLISHED", "lastModifiedAt": 1629665367207, "visibility": "PUBLIC", "publishedAt": 1629665367207, "author":...}, "emitted_at": 1720101202178}} {"type": "LOG", "log": {"level": "ERROR", "message": "{"code":"FORBIDDEN","message":"Accessing the resource is forbidden. Please check your permissions for this resource","status":403}"}}

@natikgadzhi, I ran these changes locally and was able to retrieve two records using OAuth. However, it fails afterward. I'm not sure if we need to update the permissions in the OAuth scope or introduce error handling in the connector code itself. Can you assist me with this? I tried to use the Token and couldn't read any records with that credential.

I found this Stack Overflow discussion about the same problem.

marcosmarxm avatar Jul 04 '24 13:07 marcosmarxm

@marcosmarxm , just solved merge conflicts, you can re-run the CI please once the sandbox issue has been solved on your end, thanks 🙏

FVidalCarneiro avatar Jul 08 '24 07:07 FVidalCarneiro

[!IMPORTANT]

Review skipped

Auto reviews are limited to specific labels.

Labels to auto review (1)
  • coderabbit-ai-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jul 10 '24 08:07 coderabbitai[bot]

@FVidalCarneiro, probably need for adapting this stream to the new low-code linkedin-ads ?

kev-datams avatar Aug 05 '24 21:08 kev-datams