OpenMetadata/ingestion/tests/integration/ometa/test_ometa_server_api.py
Teddy 449a5f2de3
FIX #11951 - ingestion logic for global profiler config (#15948)
* feat: add global metric configuration for the profiler

* style: ran java linting

* fix: renamed disable to disabled

* style: ran java linting

* feat: ometa sdk for profiler setting

* test: ingestion profiler global config tests

* fix: update metric name to use MetricType Enum

* fix: allow bot to retrieve settings

* fix: exclude GX artifacts

* feat: implement global profiler setting logic for ingestion side

* fix: exclude metrics if Metric is empty

* style: ran python linting

* style: ran python linting

* fix: skip empty metrics

* style: ran python linting

* fix: moved GET profiler config to seperate endpoint in system resource

* fix: moved compute metric filter to MetricFilter + renamed container

* fix: test failures

* fix: profiler test case
2024-04-22 22:35:37 +02:00

99 lines
4.0 KiB
Python

# Copyright 2021 Schlameel
# 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.
"""
OpenMetadata high-level API Server test
"""
from unittest import TestCase
from metadata.generated.schema.configuration.profilerConfiguration import (
MetricConfigurationDefinition,
MetricType,
ProfilerConfiguration,
)
from metadata.generated.schema.entity.data.table import DataType
from metadata.generated.schema.entity.services.connections.metadata.openMetadataConnection import (
OpenMetadataConnection,
)
from metadata.generated.schema.security.client.openMetadataJWTClientConfig import (
OpenMetadataJWTClientConfig,
)
from metadata.generated.schema.settings.settings import Settings, SettingType
from metadata.ingestion.ometa.ometa_api import OpenMetadata
TEST_TOKEN = "eyJraWQiOiJHYjM4OWEtOWY3Ni1nZGpzLWE5MmotMDI0MmJrOTQzNTYiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlzQm90IjpmYWxzZSwiaXNzIjoib3Blbi1tZXRhZGF0YS5vcmciLCJpYXQiOjE2NjM5Mzg0NjIsImVtYWlsIjoiYWRtaW5Ab3Blbm1ldGFkYXRhLm9yZyJ9.tS8um_5DKu7HgzGBzS1VTA5uUjKWOCU0B_j08WXBiEC0mr0zNREkqVfwFDD-d24HlNEbrqioLsBuFRiwIWKc1m_ZlVQbG7P36RUxhuv2vbSp80FKyNM-Tj93FDzq91jsyNmsQhyNv_fNr3TXfzzSPjHt8Go0FMMP66weoKMgW2PbXlhVKwEuXUHyakLLzewm9UMeQaEiRzhiTMU3UkLXcKbYEJJvfNFcLwSl9W8JCO_l0Yj3ud-qt_nQYEZwqW6u5nfdQllN133iikV4fM5QZsMCnm8Rq1mvLR0y9bmJiD7fwM1tmJ791TUWqmKaTnP49U493VanKpUAfzIiOiIbhg"
class OMetaGlossaryTest(TestCase):
"""
Run this integration test with the local API available
Install the ingestion package before running the tests
"""
server_config = OpenMetadataConnection(
hostPort="http://localhost:8585/api",
authProvider="openmetadata",
securityConfig=OpenMetadataJWTClientConfig(
jwtToken=TEST_TOKEN, # type: ignore
),
)
metadata = OpenMetadata(server_config)
assert metadata.health_check()
@classmethod
def tearDownClass(cls):
"""Clean up after the test"""
cls._clean_up_settings()
@classmethod
def _clean_up_settings(cls):
"""Reset profiler settings"""
profiler_configuration = ProfilerConfiguration(metricConfiguration=[])
settings = Settings(
config_type=SettingType.profilerConfiguration,
config_value=profiler_configuration,
)
cls.metadata.create_or_update_settings(settings)
def test_profiler_configuration(self):
"""
Test get_profiler_configuration
"""
profiler_configuration = ProfilerConfiguration(
metricConfiguration=[
MetricConfigurationDefinition(
dataType=DataType.INT,
disabled=False,
metrics=[MetricType.valuesCount, MetricType.distinctCount],
),
MetricConfigurationDefinition(
dataType=DataType.DATETIME, disabled=True, metrics=None
),
]
)
settings = Settings(
config_type=SettingType.profilerConfiguration,
config_value=profiler_configuration,
)
created_profiler_settings = self.metadata.create_or_update_settings(settings)
self.assertEqual(settings.json(), created_profiler_settings.json())
profiler_configuration.metricConfiguration.append(
MetricConfigurationDefinition(
dataType=DataType.STRING, disabled=False, metrics=[MetricType.histogram]
)
)
updated_profiler_settings = self.metadata.create_or_update_settings(settings)
self.assertEqual(settings.json(), updated_profiler_settings.json())