|
| 1 | +# BSD 3-Clause License |
| 2 | +# |
| 3 | +# Copyright (c) 2021., Redis Labs Modules |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +import logging |
| 7 | + |
| 8 | +import pytablewriter |
| 9 | +from pytablewriter import MarkdownTableWriter |
| 10 | + |
| 11 | + |
| 12 | +def generate_artifacts_table_grafana_redis( |
| 13 | + args, |
| 14 | + grafana_profile_dashboard, |
| 15 | + profile_artifacts, |
| 16 | + rts, |
| 17 | + setup_name, |
| 18 | + start_time_ms, |
| 19 | + start_time_str, |
| 20 | + test_name, |
| 21 | + tf_github_org, |
| 22 | + tf_github_repo, |
| 23 | + tf_github_sha, |
| 24 | + tf_github_branch, |
| 25 | +): |
| 26 | + logging.info("Printing profiler generated artifacts") |
| 27 | + table_name = "Profiler artifacts for test case {}".format(test_name) |
| 28 | + headers = ["artifact_name", "s3_link"] |
| 29 | + profilers_final_matrix = [] |
| 30 | + profilers_final_matrix_html = [] |
| 31 | + for artifact in profile_artifacts: |
| 32 | + profilers_final_matrix.append( |
| 33 | + [ |
| 34 | + artifact["artifact_name"], |
| 35 | + artifact["s3_link"], |
| 36 | + ] |
| 37 | + ) |
| 38 | + profilers_final_matrix_html.append( |
| 39 | + [ |
| 40 | + artifact["artifact_name"], |
| 41 | + ' <a href="{}">{}</a>'.format( |
| 42 | + artifact["s3_link"], |
| 43 | + artifact["s3_link"], |
| 44 | + ), |
| 45 | + ] |
| 46 | + ) |
| 47 | + writer = MarkdownTableWriter( |
| 48 | + table_name=table_name, |
| 49 | + headers=headers, |
| 50 | + value_matrix=profilers_final_matrix, |
| 51 | + ) |
| 52 | + writer.write_table() |
| 53 | + htmlwriter = pytablewriter.HtmlTableWriter( |
| 54 | + table_name=table_name, |
| 55 | + headers=headers, |
| 56 | + value_matrix=profilers_final_matrix_html, |
| 57 | + ) |
| 58 | + profile_markdown_str = htmlwriter.dumps() |
| 59 | + profile_markdown_str = profile_markdown_str.replace("\n", "") |
| 60 | + profile_id = "{}_{}_hash_{}".format(start_time_str, setup_name, tf_github_sha) |
| 61 | + profile_string_testcase_markdown_key = "profile:{}:{}".format(profile_id, test_name) |
| 62 | + zset_profiles = "profiles:{}_{}_{}".format( |
| 63 | + tf_github_org, tf_github_repo, setup_name |
| 64 | + ) |
| 65 | + zset_profiles_setup = "profiles:setups:{}_{}".format( |
| 66 | + tf_github_org, |
| 67 | + tf_github_repo, |
| 68 | + ) |
| 69 | + profile_set_redis_key = "profile:{}:testcases".format(profile_id) |
| 70 | + zset_profiles_setups_testcases = "profiles:testcases:{}_{}_{}".format( |
| 71 | + tf_github_org, |
| 72 | + tf_github_repo, |
| 73 | + setup_name, |
| 74 | + ) |
| 75 | + zset_profiles_setups_testcases_profileid = "profiles:ids:{}_{}_{}_{}_{}".format( |
| 76 | + tf_github_org, |
| 77 | + tf_github_repo, |
| 78 | + setup_name, |
| 79 | + test_name, |
| 80 | + tf_github_branch, |
| 81 | + ) |
| 82 | + zset_profiles_setups_testcases_branches = "profiles:branches:{}_{}_{}_{}".format( |
| 83 | + tf_github_org, tf_github_repo, setup_name, test_name |
| 84 | + ) |
| 85 | + zset_profiles_setups_testcases_branches_latest_link = ( |
| 86 | + "latest_profiles:by.branch:{}_{}_{}_{}".format( |
| 87 | + tf_github_org, tf_github_repo, setup_name, test_name |
| 88 | + ) |
| 89 | + ) |
| 90 | + https_link = "{}?var-org={}&var-repo={}&var-setup={}&var-branch={}".format( |
| 91 | + grafana_profile_dashboard, |
| 92 | + tf_github_org, |
| 93 | + tf_github_repo, |
| 94 | + setup_name, |
| 95 | + tf_github_branch, |
| 96 | + ) + "&var-test_case={}&var-profile_id={}".format( |
| 97 | + test_name, |
| 98 | + profile_id, |
| 99 | + ) |
| 100 | + if args.push_results_redistimeseries: |
| 101 | + rts.redis.zadd( |
| 102 | + zset_profiles_setups_testcases_branches, |
| 103 | + {tf_github_branch: start_time_ms}, |
| 104 | + ) |
| 105 | + rts.redis.zadd( |
| 106 | + zset_profiles_setups_testcases_branches_latest_link, |
| 107 | + {https_link: start_time_ms}, |
| 108 | + ) |
| 109 | + rts.redis.zadd( |
| 110 | + zset_profiles_setup, |
| 111 | + {setup_name: start_time_ms}, |
| 112 | + ) |
| 113 | + rts.redis.zadd( |
| 114 | + zset_profiles_setups_testcases, |
| 115 | + {test_name: start_time_ms}, |
| 116 | + ) |
| 117 | + rts.redis.zadd( |
| 118 | + zset_profiles_setups_testcases_profileid, |
| 119 | + {profile_id: start_time_ms}, |
| 120 | + ) |
| 121 | + rts.redis.zadd( |
| 122 | + zset_profiles, |
| 123 | + {profile_id: start_time_ms}, |
| 124 | + ) |
| 125 | + rts.redis.sadd(profile_set_redis_key, test_name) |
| 126 | + rts.redis.set( |
| 127 | + profile_string_testcase_markdown_key, |
| 128 | + profile_markdown_str, |
| 129 | + ) |
| 130 | + logging.info( |
| 131 | + "Store html table with artifacts in: {}".format( |
| 132 | + profile_string_testcase_markdown_key |
| 133 | + ) |
| 134 | + ) |
| 135 | + return https_link |
0 commit comments