2022-02-20 17:55:12 +01:00
|
|
|
# Copyright 2021 Collate
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
"""
|
2022-03-30 08:54:27 +02:00
|
|
|
Models to map profiler definitions
|
2022-02-20 17:55:12 +01:00
|
|
|
JSON workflows to the profiler
|
|
|
|
|
"""
|
2022-03-30 08:54:27 +02:00
|
|
|
from typing import List, Optional
|
2022-02-20 17:55:12 +01:00
|
|
|
|
2024-09-20 16:05:29 +02:00
|
|
|
from pydantic import BaseModel, BeforeValidator
|
|
|
|
|
from typing_extensions import Annotated
|
2022-02-20 17:55:12 +01:00
|
|
|
|
2023-03-01 08:20:38 +01:00
|
|
|
from metadata.profiler.metrics.registry import Metrics
|
2022-02-20 17:55:12 +01:00
|
|
|
|
|
|
|
|
|
2024-09-20 16:05:29 +02:00
|
|
|
def valid_metric(value: str):
|
|
|
|
|
"""
|
|
|
|
|
Validate that the input metrics are correctly named
|
|
|
|
|
and can be found in the Registry
|
|
|
|
|
"""
|
|
|
|
|
if not Metrics.get(value.upper()):
|
|
|
|
|
raise ValueError(
|
|
|
|
|
f"Metric name {value} is not a proper metric name from the Registry"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return value.upper()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ValidMetric = Annotated[str, BeforeValidator(valid_metric)]
|
|
|
|
|
|
|
|
|
|
|
2022-02-20 17:55:12 +01:00
|
|
|
class ProfilerDef(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
Incoming profiler definition from the
|
|
|
|
|
JSON workflow
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
name: str # Profiler name
|
2022-03-30 08:54:27 +02:00
|
|
|
timeout_seconds: Optional[
|
|
|
|
|
int
|
|
|
|
|
] = None # Stop running a query after X seconds and continue
|
2024-09-20 16:05:29 +02:00
|
|
|
metrics: Optional[List[ValidMetric]] = None
|