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

Scope crawled jobs in JobsCrawler with include_job_ids #3658

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion src/databricks/labs/ucx/assessment/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ def _job_clusters(job: BaseJob) -> Iterable[tuple[BaseJob, ClusterSpec]]:


class JobsCrawler(CrawlerBase[JobInfo], JobsMixin, CheckClusterMixin):
def __init__(self, ws: WorkspaceClient, sql_backend: SqlBackend, schema):
def __init__(self, ws: WorkspaceClient, sql_backend: SqlBackend, schema, include_job_ids: list[int] | None = None):
pritishpai marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(sql_backend, "hive_metastore", schema, "jobs", JobInfo)
self._ws = ws
self._include_job_ids = include_job_ids

def _crawl(self) -> Iterable[JobInfo]:
all_jobs = list(self._ws.jobs.list(expand_tasks=True))
Expand All @@ -109,6 +110,9 @@ def _assess_jobs(self, all_jobs: list[BaseJob], all_clusters_by_id) -> Iterable[
job_id = job.job_id
if not job_id:
continue
if self._include_job_ids is not None and job_id not in self._include_job_ids:
logger.info(f"Skipping job_id={job_id}")
continue
cluster_details = ClusterDetails.from_dict(cluster_config.as_dict())
cluster_failures = self._check_cluster_failures(cluster_details, "Job cluster")
cluster_failures.extend(self._check_jar_task(job.settings.tasks))
Expand Down
4 changes: 3 additions & 1 deletion src/databricks/labs/ucx/contexts/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def tables_crawler(self) -> TablesCrawler:

@cached_property
def jobs_crawler(self) -> JobsCrawler:
return JobsCrawler(self.workspace_client, self.sql_backend, self.inventory_database)
return JobsCrawler(
self.workspace_client, self.sql_backend, self.inventory_database, self.config.include_job_ids
)

@cached_property
def table_ownership(self) -> TableOwnership:
Expand Down
4 changes: 3 additions & 1 deletion src/databricks/labs/ucx/contexts/workflow_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def installation(self) -> Installation:

@cached_property
def jobs_crawler(self) -> JobsCrawler:
return JobsCrawler(self.workspace_client, self.sql_backend, self.inventory_database)
return JobsCrawler(
self.workspace_client, self.sql_backend, self.inventory_database, self.config.include_job_ids
)

@cached_property
def job_ownership(self) -> JobOwnership:
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/assessment/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
@retried(on=[NotFound], timeout=timedelta(minutes=5))
def test_job_crawler(ws, make_job, inventory_schema, sql_backend):
new_job = make_job(spark_conf=_SPARK_CONF)
job_crawler = JobsCrawler(ws=ws, sql_backend=sql_backend, schema=inventory_schema)
skip_job = make_job(spark_conf=_SPARK_CONF)

ws.config.include_job_ids = [new_job.job_id]
pritishpai marked this conversation as resolved.
Show resolved Hide resolved
job_crawler = JobsCrawler(ws=ws, sql_backend=sql_backend, schema=inventory_schema, include_job_ids=[new_job.job_id])
jobs = job_crawler.snapshot()
results = []
for job in jobs:
if job.success != 0:
continue
if int(job.job_id) == new_job.job_id:
results.append(job)
if int(job.job_id) == skip_job.job_id:
assert False, "Job should have been skipped"

assert len(results) >= 1
assert int(results[0].job_id) == new_job.job_id
Expand Down