Skip to content

feat(connector-insights): track manifest usage of $parameters and custom component classes #43036

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion airbyte-ci/connectors/connectors_insights/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ connectors-insights generate --output-directory <path-to-local-output-dir> --gcs
### CLI Options

- `generate`: The command to generate the artifacts.

- `-o, --output-dir`: Specifies the local directory where the generated artifacts will be saved. In this example, artifacts are saved to `/Users/augustin/Desktop/insights`.

- `-g, --gcs-uri`: The Google Cloud Storage (GCS) URI prefix where the artifacts will be uploaded. In the form: `gs://<bucket>/<key-prefix>`.
Expand Down Expand Up @@ -56,6 +56,9 @@ This CLI is currently running nightly in GitHub Actions. The workflow can be fou

## Changelog

### 0.3.0
Adding `manifest_uses_parameters`, `manifest_uses_custom_components`, and `manifest_custom_components_classes` insights.

### 0.2.4
Do not generate insights for `*-scaffold-*` and `*-strict-encrypt` connectors.

Expand Down
461 changes: 252 additions & 209 deletions airbyte-ci/connectors/connectors_insights/poetry.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion airbyte-ci/connectors/connectors_insights/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "connectors-insights"
version = "0.2.4"
version = "0.3.0"
description = ""
authors = ["Airbyte <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -31,6 +31,9 @@ mypy = "^1.8.0"
types-requests = "^2.32.0.20240602"
types-beautifulsoup4 = "^4.12.0.20240511"

[tool.ruff]
line-length = 140

[tool.ruff.lint]
select = ["F"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ async def generate(
concurrency: int,
rewrite: bool,
) -> None:

logger = logging.getLogger(__name__)
result_backends: List[ResultBackend] = []
if output_directory:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.

from __future__ import annotations

import datetime
Expand All @@ -14,6 +13,7 @@
from connectors_insights.pylint import get_pylint_output
from connectors_insights.result_backends import FileToPersist, ResultBackend
from connectors_insights.sbom import get_json_sbom
from typing_extensions import Mapping

if TYPE_CHECKING:
from typing import Dict, List, Tuple
Expand All @@ -23,6 +23,19 @@
from connector_ops.utils import Connector # type: ignore


def get_manifest_inferred_insights(connector: Connector) -> dict:
manifest = connector.manifest_path.read_text()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natikgadzhi this raises a FileNotFounderror on connectors without manifests.


schemas_directory = connector.code_path / connector.technical_name.replace("-", "_") / "schemas"

return {
"manifest_uses_parameters": manifest.find("$parameters") != -1,
"manifest_uses_custom_components": manifest.find("class_name:") != -1,
"manifest_custom_component_classes": re.findall(r"class_name: (.+)", manifest),
"has_json_schemas": schemas_directory.is_dir() and any(schemas_directory.iterdir()),
}


def get_metadata_inferred_insights(connector: Connector) -> Dict:
return {
"connector_technical_name": connector.technical_name,
Expand Down Expand Up @@ -155,6 +168,7 @@ def generate_insights(connector: Connector, sbom: str | None, pylint_output: str
return ConnectorInsights(
**{
**get_metadata_inferred_insights(connector),
**get_manifest_inferred_insights(connector),
**get_pylint_inferred_insights(pylint_output),
**get_sbom_inferred_insights(sbom, connector),
"ci_on_master_report": ci_on_master_report,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class ConnectorInsights(BaseModel):
deprecated_classes_in_use: list[str] | None
deprecated_modules_in_use: list[str] | None
forbidden_method_names_in_use: list[str] | None
manifest_uses_parameters: StrictBool
manifest_uses_custom_components: StrictBool
manifest_custom_component_classes: list[str] | None
has_json_schemas: StrictBool

class Config:
json_encoders = {dict: lambda v: json.dumps(v, default=pydantic_encoder)}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from connectors_insights.utils import never_fail_exec

if TYPE_CHECKING:

import dagger
from connector_ops.utils import Connector # type: ignore

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.

from __future__ import annotations

import logging
Expand Down Expand Up @@ -65,7 +64,6 @@ def artifact_already_exists(self, connector: Connector, file_to_persist: FileToP


class GCSBucket(ResultBackend):

DEFAULT_GCP_PROJECT = "prod-ab-cloud-proj"

def __init__(self, bucket_name: str, key_prefix: str, gcp_project: str = DEFAULT_GCP_PROJECT):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:

import dagger
from connector_ops.utils import Connector # type: ignore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Set, Tuple, List, Callable
from typing import Callable, List, Set, Tuple

from dagger import Container

from connector_ops.utils import METADATA_FILE_NAME, Connector # type: ignore
Expand Down
Loading