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

test httpjson log handler #127

Open
smoors opened this issue Mar 17, 2024 · 1 comment
Open

test httpjson log handler #127

smoors opened this issue Mar 17, 2024 · 1 comment

Comments

@smoors
Copy link
Collaborator

smoors commented Mar 17, 2024

can be useful for visualization on a remote host

see https://reframe-hpc.readthedocs.io/en/stable/config_reference.html#the-httpjson-log-handler

@smoors
Copy link
Collaborator Author

smoors commented Mar 17, 2024

i tested this with a local http server that handles json data:

from http.server import BaseHTTPRequestHandler, HTTPServer
import json

class JSONRequestHandler(BaseHTTPRequestHandler):
    def _set_response(self, status_code=200):
        self.send_response(status_code)
        self.send_header('Content-type', 'application/json')
        self.end_headers()

    def do_POST(self):

        content_length = int(self.headers['Content-Length'])
        post_data = self.rfile.read(content_length)

        try:
            # Parse JSON data
            json_data = json.loads(post_data.decode('utf-8'))
            print("Received JSON data:", json_data)

            # Here you can handle the JSON data as needed

            # Send a response back
            self._set_response(200)

            # send the data back to the client, just to show that we can do this
            response_data = {'message': 'JSON data received successfully', 'data': json_data}
            self.wfile.write(json.dumps(response_data).encode('utf-8'))

        except json.JSONDecodeError as e:
            self._set_response(400)
            self.wfile.write(json.dumps({'error': 'Invalid JSON data'}).encode('utf-8'))


def run(server_class=HTTPServer, handler_class=JSONRequestHandler, port=8000):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    print(f"Starting server on port {port}...")
    httpd.serve_forever()


if __name__ == '__main__':
    run()

i also added the following to the handlers_perflog section of the config file:

            { 
                'type': 'httpjson',
                'url': 'http://127.0.0.1:8000/rfm',
                'level': 'info',
                # 'extra_headers': {'Authorization': 'Token YOUR_API_TOKEN'},
                'extras': { 
                    'facility': 'reframe',
                    'data-version': '1.0'
                },
                'ignore_keys': ['check_perfvalues']
            },

seems to work nicely, this is the output of the server:

Starting server on port 8000...
Received JSON data: {'check_name': 'EESSI_GROMACS %benchmark_info=HECBioSim/Crambin %nb_impl=cpu %scale=1_2_node %module_name=GROMACS/2023.1-foss-2022a', 'check_jobid': '9079169', 'check_job_completion_time': '2024-03-17T11:22:58+01:00', 'check_job_completion_time_unix': 1710670978.0, 'check_info': 'EESSI_GROMACS %benchmark_info=HECBioSim/Crambin %nb_impl=cpu %scale=1_2_node %module_name=GROMACS/2023.1-foss-2022a /662f9d8a @hydra:skylake+default', 'check_system': 'hydra', 'check_partition': 'skylake', 'check_environ': 'default', 'check_perf_var': None, 'check_perf_value': None, 'check_perf_ref': None, 'check_perf_lower_thres': None, 'check_perf_upper_thres': None, 'check_perf_unit': None, 'check_result': 'pass', 'osuser': 'vsc10009', 'osgroup': 'vsc10009', 'version': '4.3.2', 'check_job_exitcode': 0, 'check_job_nodelist': ['node302'], 'check_bench_name': 'HECBioSim/Crambin', 'check_benchmark_info': 'HECBioSim/Crambin', 'check_benchmark_version': '1.0.0', 'check_build_locally': True, 'check_build_time_limit': None, 'check_descr': 'GROMACS HECBioSim/Crambin benchmark (NB: cpu)', 'check_display_name': 'EESSI_GROMACS %benchmark_info=HECBioSim/Crambin %nb_impl=cpu %scale=1_2_node %module_name=GROMACS/2023.1-foss-2022a', 'check_env_vars': {'OMP_NUM_THREADS': 1}, 'check_exclusive_access': False, 'check_executable': 'gmx_mpi mdrun', 'check_executable_opts': ['-nb', 'cpu', '-s', 'benchmark.tpr', '-dlb', 'yes', '-npme', '-1', '-ntomp', '1'], 'check_extra_resources': {}, 'check_hashcode': '662f9d8a', 'check_keep_files': ['md.log'], 'check_local': False, 'check_maintainers': [], 'check_max_pending_time': None, 'check_modules': ['GROMACS/2023.1-foss-2022a'], 'check_nb_impl': 'cpu', 'check_num_cpus_per_task': 1, 'check_num_gpus_per_node': None, 'check_num_tasks': 20, 'check_num_tasks_per_core': None, 'check_num_tasks_per_node': 20, 'check_num_tasks_per_socket': None, 'check_outputdir': '/data/brussel/100/vsc10009/reframe/eessitestsuite/newtest/prefix/output/hydra/skylake/default/EESSI_GROMACS_662f9d8a', 'check_postbuild_cmds': [], 'check_postrun_cmds': [], 'check_prebuild_cmds': [], 'check_prefix': '/vscmnt/brussel_pixiu_data/_data_brussel/100/vsc10009/reframe/eessitestsuite/test-suite/eessi/testsuite/tests/apps', 'check_prerun_cmds': ['curl -LJO https://github.com/victorusu/GROMACS_Benchmark_Suite/raw/1.0.0/HECBioSim/Crambin/benchmark.tpr'], 'check_readonly_files': [], 'check_short_name': 'EESSI_GROMACS_662f9d8a', 'check_sourcepath': '', 'check_sourcesdir': None, 'check_stagedir': '/data/brussel/100/vsc10009/reframe/eessitestsuite/newtest/prefix/stage/hydra/skylake/default/EESSI_GROMACS_662f9d8a', 'check_strict_check': True, 'check_tags': ['CI', 'chemistry', 'sciapp', '1_2_node'], 'check_time_limit': 1800.0, 'check_unique_name': 'EESSI_GROMACS_022', 'check_use_multithreading': None, 'check_valid_prog_environs': ['default'], 'check_valid_systems': ['+1_2_node +cpu'], 'check_variables': {'OMP_NUM_THREADS': 1}, 'facility': 'reframe', 'data-version': '1.0'}
127.0.0.1 - - [17/Mar/2024 11:23:02] "POST /rfm HTTP/1.1" 200 -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant