<jupyter_start><jupyter_text>TSG029 - Find dumps in the cluster DescriptionLook for coredumps and minidumps from processes like SQL Server orcontroller in a big data cluster. Steps Instantiate Kubernetes client<jupyter_code># Instantiate the Python Kubernetes client into 'api' variable

import os
from IPython.display import Markdown

try:
    from kubernetes import client, config
    from kubernetes.stream import stream
except ImportError: 

    # Install the Kubernetes module
    import sys
    !{sys.executable} -m pip install kubernetes    
    
    try:
        from kubernetes import client, config
        from kubernetes.stream import stream
    except ImportError:
        display(Markdown(f'HINT: Use [SOP059 - Install Kubernetes Python module](../install/sop059-install-kubernetes-module.ipynb) to resolve this issue.'))
        raise

if "KUBERNETES_SERVICE_PORT" in os.environ and "KUBERNETES_SERVICE_HOST" in os.environ:
    config.load_incluster_config()
else:
    try:
        config.load_kube_config()
    except:
        display(Markdown(f'HINT: Use [TSG118 - Configure Kubernetes config](../repair/tsg118-configure-kube-config.ipynb) to resolve this issue.'))
        raise

api = client.CoreV1Api()

print('Kubernetes client instantiated')<jupyter_output><empty_output><jupyter_text>Get the namespace for the big data clusterGet the namespace of the Big Data Cluster from the Kuberenetes API.**NOTE:**If there is more than one Big Data Cluster in the target Kubernetescluster, then either:-   set \[0\] to the correct value for the big data cluster.-   set the environment variable AZDATA_NAMESPACE, before starting Azure    Data Studio.<jupyter_code># Place Kubernetes namespace name for BDC into 'namespace' variable

if "AZDATA_NAMESPACE" in os.environ:
    namespace = os.environ["AZDATA_NAMESPACE"]
else:
    try:
        namespace = api.list_namespace(label_selector='MSSQL_CLUSTER').items[0].metadata.name
    except IndexError:
        from IPython.display import Markdown
        display(Markdown(f'HINT: Use [TSG081 - Get namespaces (Kubernetes)](../monitor-k8s/tsg081-get-kubernetes-namespaces.ipynb) to resolve this issue.'))
        display(Markdown(f'HINT: Use [TSG010 - Get configuration contexts](../monitor-k8s/tsg010-get-kubernetes-contexts.ipynb) to resolve this issue.'))
        display(Markdown(f'HINT: Use [SOP011 - Set kubernetes configuration context](../common/sop011-set-kubernetes-context.ipynb) to resolve this issue.'))
        raise

print('The kubernetes namespace for your big data cluster is: ' + namespace)<jupyter_output><empty_output><jupyter_text>Get all relevant pods<jupyter_code>pod_list = api.list_namespaced_pod(namespace, label_selector='app in (compute-0, data-0, storage-0, master, controller, controldb)', field_selector='status.phase==Running')
pod_names = [pod.metadata.name for pod in pod_list.items]
print('Scanning pods: ' + ', '.join(pod_names))

command = 'find /var/opt /var/log -path /var/opt/mssql-extensibility/data -prune -o -print | grep -E "core\\.sqlservr|core\\.controller|SQLD|\\.mdmp$|\\.dmp$|\\.gdmp$"'
all_dumps = ''

for name in pod_names:
    print('Searching pod: ' + name)
    container = 'mssql-server'
    if 'control-' in name:
        container = 'controller'

    try:
        dumps=stream(api.connect_get_namespaced_pod_exec, name, namespace, command=['/bin/sh', '-c', command], container=container, stderr=True, stdout=True)
    except Exception as e:
        print(f'Unable to connect to pod: {name} due to {str(e.__class__)}. Skipping dump check for this pod...')
    else:
        if dumps:
            all_dumps += '*Pod: ' + name + '*\n'
            all_dumps += dumps + '\n'<jupyter_output><empty_output><jupyter_text>ValidateValidate no dump files were found.<jupyter_code>if len(all_dumps) > 0:
    raise SystemExit('FAIL - dump files found:\n' + all_dumps)

print('SUCCESS - no dump files were found.')
print("Notebook execution is complete.")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1086847389558233, 'fraction_numerical': 0.010542168674698794, 'mean_word_length': 4.063532401524777, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '51776', 'license': 'MIT', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1226, 'n_words': 348, 'path': 'Big-Data-Clusters/CU9/public/content/diagnose/tsg029-find-dumps-in-the-cluster.ipynb', 'repo_name': 'WilliamAntonRohm/tigertoolbox', 'size': '3984'}