def test_check_with_errored_handled_metadata_section(): # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.ERROR, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=NodeMetadataFactory.batch(1), ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=False, duplicate_container_collector=False, unknown_collector=False, ), ) # Act check_result = list( kube_collector_info.check( collector_metadata, None, collector_daemons, )) # Assert assert len(check_result) == 3 assert isinstance(check_result[0], Result) and check_result[0].state == State.CRIT
def test_check_with_no_collector_components_section(): # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.OK, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=NodeMetadataFactory.batch(1), ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=False, duplicate_container_collector=False, unknown_collector=False, )) # Act check_result = list( kube_collector_info.check( collector_metadata, None, collector_daemons, )) # Assert assert all(isinstance(result, Result) for result in check_result) assert isinstance(check_result[0], Result) and check_result[0].summary.startswith( "Cluster collector version:") assert len(check_result) == 4
def collectors_metadata( metadata_collection_log: CollectorHandlerLog, collector_metadata_handling_state: CollectorState, ) -> CollectorComponentsMetadata: return CollectorComponentsMetadata( processing_log=metadata_collection_log, cluster_collector=ClusterCollectorMetadataFactory.build(), node_collectors=[NodeMetadataFactory.build()], )
def test_check_api_daemonsets_multiple_with_same_label() -> None: # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.OK, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=None, ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=True, duplicate_container_collector=True, unknown_collector=False, ), ) collector_processing_logs = None # Act check_result = list( kube_collector_info.check( collector_metadata, collector_processing_logs, collector_daemons, )) # Assert assert len(check_result) == 4 container_result = check_result[1] machine_result = check_result[2] additional_info_result = check_result[3] assert isinstance(container_result, Result) and container_result.state == State.OK assert (container_result.summary == "Multiple DaemonSets with label node-collector=container-metrics") assert isinstance(machine_result, Result) and machine_result.state == State.OK assert (machine_result.summary == "Multiple DaemonSets with label node-collector=machine-sections") assert isinstance(additional_info_result, Result) and additional_info_result.state == State.OK assert ( additional_info_result.details == "Cannot identify node collector, if label is found on multiple DaemonSets" )
def test_check_all_ok_sections(): # Arrange collector_metadata = CollectorComponentsMetadata( processing_log=CollectorHandlerLog( status=CollectorState.OK, title="title", detail="detail", ), cluster_collector=ClusterCollectorMetadataFactory.build(), nodes=NodeMetadataFactory.batch(1), ) collector_processing_logs = CollectorProcessingLogs( container=CollectorHandlerLog(status=CollectorState.OK, title="title", detail="OK"), machine=CollectorHandlerLog(status=CollectorState.OK, title="title", detail="OK"), ) collector_daemons = CollectorDaemonsFactory.build( errors=IdentificationError( duplicate_machine_collector=False, duplicate_container_collector=False, unknown_collector=False, )) # Act check_result = list( kube_collector_info.check( collector_metadata, collector_processing_logs, collector_daemons, )) # Assert assert len(check_result) == 6 assert all(isinstance(result, Result) for result in check_result) assert all(result.state == State.OK for result in check_result if isinstance(result, Result))
def parse_collector_metadata(string_table: StringTable) -> CollectorComponentsMetadata: return CollectorComponentsMetadata(**json.loads(string_table[0][0]))
def test_parse_collector_metadata(): string_table_element = json.dumps({ "processing_log": { "status": "ok", "title": "title", "detail": "detail" }, "cluster_collector": { "node": "node", "host_name": "host", "container_platform": { "os_name": "os", "os_version": "version", "python_version": "pversion", "python_compiler": "compiler", }, "checkmk_kube_agent": { "project_version": "package" }, }, "node_collectors": [{ "name": "minikube", "components": { "checkmk_agent_version": { "collector_type": "Machine Sections", "checkmk_kube_agent": { "project_version": "0.1.0" }, "name": "checkmk_agent_version", "version": "version", }, }, }], }) assert kube_collector_info.parse_collector_metadata( [[string_table_element]]) == CollectorComponentsMetadata( processing_log=CollectorHandlerLog(status=CollectorState.OK, title="title", detail="detail"), cluster_collector=ClusterCollectorMetadata( node="node", host_name="host", container_platform=PlatformMetadata( os_name="os", os_version="version", python_version="pversion", python_compiler="compiler", ), checkmk_kube_agent=CheckmkKubeAgentMetadata( project_version="package"), ), node_collectors=[ NodeMetadata( name="node", components={ "checkmk_agent_version": NodeComponent( collector_type=CollectorType.MACHINE_SECTIONS, checkmk_kube_agent=CheckmkKubeAgentMetadata( project_version="package"), name="checkmk_agent_version", version="version", ), }, ) ], )