diff --git a/cmd/jaeger/docs/migration/all-in-one-metrics.md b/cmd/jaeger/docs/migration/all-in-one-metrics.md new file mode 100644 index 00000000000..28f165b2be3 --- /dev/null +++ b/cmd/jaeger/docs/migration/all-in-one-metrics.md @@ -0,0 +1,86 @@ +# ALL-IN-ONE METRICS +### Combined Metrics + +| V1 Metric | V1 Labels | V2 Metric | V2 Labels | +|-----------|---------------|-----------|---------------| +| jaeger_query_latency | operation, result | jaeger_query_latency | operation, result | +| jaeger_query_responses | operation | jaeger_query_responses | operation | +| jaeger_query_requests_total | operation, result | jaeger_query_requests_total | operation, result | +| go_gc_duration_seconds | N/A | N/A | N/A | +| go_goroutines | N/A | N/A | N/A | +| go_info | version | N/A | N/A | +| go_memstats_alloc_bytes | N/A | N/A | N/A | +| go_memstats_alloc_bytes_total | N/A | N/A | N/A | +| go_memstats_buck_hash_sys_bytes | N/A | N/A | N/A | +| go_memstats_frees_total | N/A | N/A | N/A | +| go_memstats_gc_sys_bytes | N/A | N/A | N/A | +| go_memstats_heap_alloc_bytes | N/A | N/A | N/A | +| go_memstats_heap_idle_bytes | N/A | N/A | N/A | +| go_memstats_heap_inuse_bytes | N/A | N/A | N/A | +| go_memstats_heap_objects | N/A | N/A | N/A | +| go_memstats_heap_released_bytes | N/A | N/A | N/A | +| go_memstats_heap_sys_bytes | N/A | N/A | N/A | +| go_memstats_last_gc_time_seconds | N/A | N/A | N/A | +| go_memstats_lookups_total | N/A | N/A | N/A | +| go_memstats_mallocs_total | N/A | N/A | N/A | +| go_memstats_mcache_inuse_bytes | N/A | N/A | N/A | +| go_memstats_mcache_sys_bytes | N/A | N/A | N/A | +| go_memstats_mspan_inuse_bytes | N/A | N/A | N/A | +| go_memstats_mspan_sys_bytes | N/A | N/A | N/A | +| go_memstats_next_gc_bytes | N/A | N/A | N/A | +| go_memstats_other_sys_bytes | N/A | N/A | N/A | +| go_memstats_stack_inuse_bytes | N/A | N/A | N/A | +| go_memstats_stack_sys_bytes | N/A | N/A | N/A | +| go_memstats_sys_bytes | N/A | N/A | N/A | +| go_threads | N/A | N/A | N/A | +| jaeger_build_info | build_date, revision, version | N/A | N/A | +| jaeger_collector_batch_size | host | N/A | N/A | +| jaeger_collector_http_request_duration | method, path, status | N/A | N/A | +| jaeger_collector_http_server_errors_total | source, status | N/A | N/A | +| jaeger_collector_http_server_requests_total | type | N/A | N/A | +| jaeger_collector_in_queue_latency | host | N/A | N/A | +| jaeger_collector_queue_capacity | host | N/A | N/A | +| jaeger_collector_queue_length | host | N/A | N/A | +| jaeger_collector_save_latency | host | N/A | N/A | +| jaeger_collector_spans_bytes | host | N/A | N/A | +| jaeger_collector_spans_dropped_total | host | N/A | N/A | +| jaeger_collector_spans_received_total | debug, format, svc, transport | N/A | N/A | +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | N/A | N/A | +| jaeger_collector_spans_saved_by_svc_total | debug, result, svc | N/A | N/A | +| jaeger_collector_spans_serviceNames | host | N/A | N/A | +| jaeger_collector_traces_received_total | debug, format, sampler_type, svc, transport | N/A | N/A | +| jaeger_collector_traces_rejected_total | debug, format, sampler_type, svc, transport | N/A | N/A | +| jaeger_collector_traces_saved_by_svc_total | debug, result, sampler_type, svc | N/A | N/A | +| process_cpu_seconds_total | N/A | N/A | N/A | +| process_max_fds | N/A | N/A | N/A | +| process_open_fds | N/A | N/A | N/A | +| process_resident_memory_bytes | N/A | N/A | N/A | +| process_start_time_seconds | N/A | N/A | N/A | +| process_virtual_memory_bytes | N/A | N/A | N/A | +| process_virtual_memory_max_bytes | N/A | N/A | N/A | +| N/A | N/A | exporter_send_failed_spans | exporter, service_instance_id, service_name, service_version | +| N/A | N/A | exporter_sent_spans | exporter, service_instance_id, service_name, service_version | +| N/A | N/A | process_cpu_seconds | service_instance_id, service_name, service_version | +| N/A | N/A | process_memory_rss | service_instance_id, service_name, service_version | +| N/A | N/A | process_runtime_heap_alloc_bytes | service_instance_id, service_name, service_version | +| N/A | N/A | process_runtime_total_alloc_bytes | service_instance_id, service_name, service_version | +| N/A | N/A | process_runtime_total_sys_memory_bytes | service_instance_id, service_name, service_version | +| N/A | N/A | process_uptime | service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_batch_send_size | processor, service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_batch_send_size_bytes | processor, service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_metadata_cardinality | processor, service_instance_id, service_name, service_version | +| N/A | N/A | processor_batch_timeout_trigger_send | processor, service_instance_id, service_name, service_version | +| N/A | N/A | receiver_accepted_spans | receiver, service_instance_id, service_name, service_version, transport | +| N/A | N/A | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| N/A | N/A | rpc_server_duration | rpc_grpc_status_code, rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_request_size | rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_requests_per_rpc | rpc_grpc_status_code, rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_response_size | rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | rpc_server_responses_per_rpc | rpc_grpc_status_code, rpc_method, rpc_service, rpc_system, service_instance_id, service_name, service_version | +| N/A | N/A | target_info | service_instance_id, service_name, service_version | +### Equivalent Metrics + +| V1 Metric | V1 Labels | V2 Metric | V2 Labels | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/badger-metrics.md b/cmd/jaeger/docs/migration/badger-metrics.md new file mode 100644 index 00000000000..65656e44c6a --- /dev/null +++ b/cmd/jaeger/docs/migration/badger-metrics.md @@ -0,0 +1,33 @@ +# BADGER METRICS + +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +| ------------------------------------------ | ------------- | ---------------------------------------- | ------------- | +| jaeger_badger_compaction_current_num_lsm | N/A | jaeger_badger_compaction_current_num_lsm | N/A | +| jaeger_badger_get_num_memtable | N/A | jaeger_badger_get_num_memtable | N/A | +| jaeger_badger_get_num_user | N/A | jaeger_badger_get_num_user | N/A | +| jaeger_badger_get_with_result_num_user | N/A | jaeger_badger_get_with_result_num_user | N/A | +| jaeger_badger_iterator_num_user | N/A | jaeger_badger_iterator_num_user | N/A | +| jaeger_badger_put_num_user | N/A | jaeger_badger_put_num_user | N/A | +| jaeger_badger_read_bytes_lsm | N/A | jaeger_badger_read_bytes_lsm | N/A | +| jaeger_badger_read_bytes_vlog | N/A | jaeger_badger_read_bytes_vlog | N/A | +| jaeger_badger_read_num_vlog | N/A | jaeger_badger_read_num_vlog | N/A | +| jaeger_badger_size_bytes_lsm | N/A | jaeger_badger_size_bytes_lsm | N/A | +| jaeger_badger_size_bytes_vlog | N/A | jaeger_badger_size_bytes_vlog | N/A | +| jaeger_badger_write_bytes_l0 | N/A | jaeger_badger_write_bytes_l0 | N/A | +| jaeger_badger_write_bytes_user | N/A | jaeger_badger_write_bytes_user | N/A | +| jaeger_badger_write_bytes_vlog | N/A | jaeger_badger_write_bytes_vlog | N/A | +| jaeger_badger_write_num_vlog | N/A | jaeger_badger_write_num_vlog | N/A | +| jaeger_badger_write_pending_num_memtable | N/A | jaeger_badger_write_pending_num_memtable | N/A | +| jaeger_badger_key_log_bytes_available | N/A | N/A | N/A | +| jaeger_badger_storage_maintenance_last_run | N/A | N/A | N/A | +| jaeger_badger_storage_valueloggc_last_run | N/A | N/A | N/A | +| jaeger_badger_value_log_bytes_available | N/A | N/A | N/A | + +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +| ------------------------------------- | ------------------------------ | ---------------------- | ----------------------------------------------------------------------- | +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/cassandra-metrics.md b/cmd/jaeger/docs/migration/cassandra-metrics.md new file mode 100644 index 00000000000..95d453f7ca3 --- /dev/null +++ b/cmd/jaeger/docs/migration/cassandra-metrics.md @@ -0,0 +1,22 @@ +# CASSANDRA METRICS +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_cassandra_attempts_total | table | jaeger_cassandra_attempts_total | table | +| jaeger_cassandra_errors_total | table | jaeger_cassandra_errors_total | table | +| jaeger_cassandra_inserts_total | table | jaeger_cassandra_inserts_total | table | +| jaeger_cassandra_latency_err | table | jaeger_cassandra_latency_err | table | +| jaeger_cassandra_latency_ok | table | jaeger_cassandra_latency_ok | table | +| jaeger_cassandra_read_attempts_total | table | jaeger_cassandra_read_attempts_total | table | +| jaeger_cassandra_read_errors_total | table | jaeger_cassandra_read_errors_total | table | +| jaeger_cassandra_read_inserts_total | table | jaeger_cassandra_read_inserts_total | table | +| jaeger_cassandra_read_latency_err | table | jaeger_cassandra_read_latency_err | table | +| jaeger_cassandra_read_latency_ok | table | jaeger_cassandra_read_latency_ok | table | +| jaeger_cassandra_tag_index_skipped_total | N/A | jaeger_cassandra_tag_index_skipped_total | N/A | +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/elasticsearch-metrics.md b/cmd/jaeger/docs/migration/elasticsearch-metrics.md new file mode 100644 index 00000000000..9b5a0a0b608 --- /dev/null +++ b/cmd/jaeger/docs/migration/elasticsearch-metrics.md @@ -0,0 +1,21 @@ +# ELASTICSEARCH METRICS +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_bulk_index_attempts_total | N/A | jaeger_bulk_index_attempts_total | N/A | +| jaeger_bulk_index_errors_total | N/A | jaeger_bulk_index_errors_total | N/A | +| jaeger_bulk_index_inserts_total | N/A | jaeger_bulk_index_inserts_total | N/A | +| jaeger_bulk_index_latency_err | N/A | jaeger_bulk_index_latency_err | N/A | +| jaeger_bulk_index_latency_ok | N/A | jaeger_bulk_index_latency_ok | N/A | +| jaeger_index_create_attempts_total | N/A | jaeger_index_create_attempts_total | N/A | +| jaeger_index_create_errors_total | N/A | jaeger_index_create_errors_total | N/A | +| jaeger_index_create_inserts_total | N/A | jaeger_index_create_inserts_total | N/A | +| jaeger_index_create_latency_err | N/A | jaeger_index_create_latency_err | N/A | +| jaeger_index_create_latency_ok | N/A | jaeger_index_create_latency_ok | N/A | +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/cmd/jaeger/docs/migration/opensearch-metrics.md b/cmd/jaeger/docs/migration/opensearch-metrics.md new file mode 100644 index 00000000000..aa5052c270b --- /dev/null +++ b/cmd/jaeger/docs/migration/opensearch-metrics.md @@ -0,0 +1,21 @@ +# OPENSEARCH METRICS +### Combined Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_bulk_index_attempts_total | N/A | jaeger_bulk_index_attempts_total | N/A | +| jaeger_bulk_index_errors_total | N/A | jaeger_bulk_index_errors_total | N/A | +| jaeger_bulk_index_inserts_total | N/A | jaeger_bulk_index_inserts_total | N/A | +| jaeger_bulk_index_latency_err | N/A | jaeger_bulk_index_latency_err | N/A | +| jaeger_bulk_index_latency_ok | N/A | jaeger_bulk_index_latency_ok | N/A | +| jaeger_index_create_attempts_total | N/A | jaeger_index_create_attempts_total | N/A | +| jaeger_index_create_errors_total | N/A | jaeger_index_create_errors_total | N/A | +| jaeger_index_create_inserts_total | N/A | jaeger_index_create_inserts_total | N/A | +| jaeger_index_create_latency_err | N/A | jaeger_index_create_latency_err | N/A | +| jaeger_index_create_latency_ok | N/A | jaeger_index_create_latency_ok | N/A | +### Equivalent Metrics + +| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters | +|-----------|---------------|-----------|---------------| +| jaeger_collector_spans_rejected_total | debug, format, svc, transport | receiver_refused_spans | receiver, service_instance_id, service_name, service_version, transport | +| jaeger_build_info | build_date, revision, version | target_info | service_instance_id, service_name, service_version | diff --git a/scripts/compare_metrics.py b/scripts/compare_metrics.py deleted file mode 100755 index 36fe190d592..00000000000 --- a/scripts/compare_metrics.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (c) 2024 The Jaeger Authors. -# SPDX-License-Identifier: Apache-2.0 - -import json - -v1_metrics_path = "./V1_Metrics.json" -v2_metrics_path = "./V2_Metrics.json" - -with open(v1_metrics_path, 'r') as file: - v1_metrics = json.load(file) - -with open(v2_metrics_path, 'r') as file: - v2_metrics = json.load(file) - -# Extract names and labels of the metrics -def extract_metrics_with_labels(metrics, strip_prefix=None): - result = {} - for metric in metrics: - name = metric['name'] - if strip_prefix and name.startswith(strip_prefix): - name = name[len(strip_prefix):] - labels = {} - if 'metrics' in metric and 'labels' in metric['metrics'][0]: - labels = metric['metrics'][0]['labels'] - result[name] = labels - return result - - -v1_metrics_with_labels = extract_metrics_with_labels(v1_metrics) -v2_metrics_with_labels = extract_metrics_with_labels( - v2_metrics, strip_prefix="otelcol_") - -# Compare the metrics names and labels -common_metrics = {} -v1_only_metrics = {} -v2_only_metrics = {} - -for name, labels in v1_metrics_with_labels.items(): - if name in v2_metrics_with_labels: - common_metrics[name] = labels - elif not name.startswith("jaeger_agent"): - v1_only_metrics[name] = labels - -for name, labels in v2_metrics_with_labels.items(): - if name not in v1_metrics_with_labels: - v2_only_metrics[name] = labels - -differences = { - "common_metrics": common_metrics, - "v1_only_metrics": v1_only_metrics, - "v2_only_metrics": v2_only_metrics -} - -# Write the differences to a new JSON file -differences_path = "./differences.json" -with open(differences_path, 'w') as file: - json.dump(differences, file, indent=4) - -print(f"Differences written to {differences_path}") diff --git a/scripts/utils/compare_metrics.py b/scripts/utils/compare_metrics.py new file mode 100755 index 00000000000..390f2b7d470 --- /dev/null +++ b/scripts/utils/compare_metrics.py @@ -0,0 +1,130 @@ +# Copyright (c) 2024 The Jaeger Authors. +# SPDX-License-Identifier: Apache-2.0 + +import json +import argparse +import subprocess + +#Instructions of use: + +# To generate V1_Metrics.json and V2_Metrics.json, run the following commands: +# i.e for elastic search first run the following command: +# docker compose -f docker-compose/elasticsearch/v7/docker-compose.yml up +# 1. Generate V1_Metrics.json and V2_Metrics.json by the following commands: +# V1 binary cmd: SPAN_STORAGE_TYPE=elasticsearch go run -tags=ui ./cmd/all-in-one +# extract the metrics by running the following command: +# prom2json http://localhost:14269/metrics > V1_Metrics.json +# Stop the v1 binary and for v2 binary run the following command: +# go run -tags ui ./cmd/jaeger/main.go --config ./cmd/jaeger/config-elasticsearch.yaml +# extract the metrics by running the following command: +# prom2json http://localhost:8888/metrics > V2_Metrics.json +# it is first recomended to generate the differences for all-in-one.json by running the following command: +# python3 compare_metrics.py --out md --is_storage F +# rename that file to all_in_one.json and use it to filter out the overlapping metrics by using the is_storage falg to T +# 2. Run the script with the following command: +# python3 compare_metrics.py --out {json or md} --is_storage {T or F} +# 3. The script will compare the metrics in V1_Metrics.json and V2_Metrics.json and output the differences to differences.json + + +# Extract names and labels of the metrics +def extract_metrics_with_labels(metrics, strip_prefix=None): + result = {} + for metric in metrics: + + name = metric['name'] + print(name) + if strip_prefix and name.startswith(strip_prefix): + name = name[len(strip_prefix):] + labels = {} + if 'metrics' in metric and 'labels' in metric['metrics'][0]: + labels = metric['metrics'][0]['labels'] + result[name] = labels + return result + +def remove_overlapping_metrics(all_in_one_data, other_json_data): + """Remove overlapping metrics found in all_in-one.json from another JSON.""" + # Loop through v1 and v2 metrics to remove overlaps + for metric_category in ['common_metrics', 'v1_only_metrics', 'v2_only_metrics']: + if metric_category in all_in_one_data and metric_category in other_json_data: + for metric in all_in_one_data[metric_category]: + if metric in other_json_data[metric_category]: + del other_json_data[metric_category][metric] + + return other_json_data + + +# Your current compare_metrics.py logic goes here +def main(): + parser = argparse.ArgumentParser(description='Compare metrics and output format.') + parser.add_argument('--out', choices=['json', 'md'], default='json', + help='Output format: json (default) or md') + parser.add_argument('--is_storage', choices=['T','F'],default='F', help='Remove overlapping storage metrics') + # Parse the arguments + args = parser.parse_args() + + # Call your existing compare logic here + print("Running metric comparison...") + v1_metrics_path = "" #Add the path to the V1_Metrics.json file + v2_metrics_path = "" #Add the path to the V2_Metrics.json file + + with open(v1_metrics_path, 'r') as file: + v1_metrics = json.load(file) + + with open(v2_metrics_path, 'r') as file: + v2_metrics = json.load(file) + + v1_metrics_with_labels = extract_metrics_with_labels(v1_metrics) + v2_metrics_with_labels = extract_metrics_with_labels( + v2_metrics, strip_prefix="otelcol_") + + # Compare the metrics names and labels + common_metrics = {} + v1_only_metrics = {} + v2_only_metrics = {} + + for name, labels in v1_metrics_with_labels.items(): + if name in v2_metrics_with_labels: + common_metrics[name] = labels + elif not name.startswith("jaeger_agent"): + v1_only_metrics[name] = labels + + for name, labels in v2_metrics_with_labels.items(): + if name not in v1_metrics_with_labels: + v2_only_metrics[name] = labels + + differences = { + "common_metrics": common_metrics, + "v1_only_metrics": v1_only_metrics, + "v2_only_metrics": v2_only_metrics, + } + + #Write the differences to a new JSON file + differences_path = "./differences.json" + with open(differences_path, 'w') as file: + json.dump(differences, file, indent=4) + + print(f"Differences written to {differences_path}") + if args.is_storage == 'T': + all_in_one_path = "" #Add the path to the all_in_one.json file + with open(all_in_one_path, 'r') as file: + all_in_one_data = json.load(file) + with open(differences_path, 'r') as file: + other_json_data = json.load(file) + other_json_data = remove_overlapping_metrics(all_in_one_data, other_json_data) + with open(differences_path, 'w') as file: + json.dump(other_json_data, file, indent=4) + print(f"Overlapping storage metrics removed from {differences_path}") + # If the user requested markdown output, run metrics_md.py + if args.out == 'md': + try: + print("Running metrics_md.py to generate markdown output...") + subprocess.run(['python3', 'metrics-md.py'], check=True) + except subprocess.CalledProcessError as e: + print(f"Error running metrics_md.py: {e}") + + # If json output is requested or no output type is provided (default is json) + else: + print("Output in JSON format.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/utils/metrics-md.py b/scripts/utils/metrics-md.py new file mode 100644 index 00000000000..2b158697257 --- /dev/null +++ b/scripts/utils/metrics-md.py @@ -0,0 +1,117 @@ +# Copyright (c) 2024 The Jaeger Authors. +# SPDX-License-Identifier: Apache-2.0 + +import json + + +def generate_spans_markdown_table(v1_spans, v2_spans): + """ + Generates a markdown table specifically for spans metrics with two main columns V1 and V2. + + Args: + v1_spans (dict): The dictionary of V1 spans metrics. + v2_spans (dict): The dictionary of V2 spans metrics. + + Returns: + str: The generated markdown table as a string. + """ + table = "### Equivalent Metrics\n\n" + table += "| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters |\n" + table += "|-----------|---------------|-----------|---------------|\n" + + + # Iterate through the metrics using zip_longest to handle mismatched lengths + from itertools import zip_longest + + for (v1_metric, v1_params), (v2_metric, v2_params) in zip_longest(v1_spans.items(), v2_spans.items(), fillvalue=('', {})): + v1_inner_keys = ', '.join(v1_params.keys()) if v1_params else '' + v2_inner_keys = ', '.join(v2_params.keys()) if v2_params else '' + table += f"| {v1_metric} | {v1_inner_keys} | {v2_metric} | {v2_inner_keys} |\n" + + return table + + + +def generate_combined_markdown_table(common_metrics, v1_metrics, v2_metrics): + """ + Generates a markdown table for combined metrics from common, V1, and V2. + + Args: + common_metrics (dict): The dictionary of common metrics. + v1_metrics (dict): The dictionary of V1 only metrics. + v2_metrics (dict): The dictionary of V2 only metrics. + + Returns: + str: The generated markdown table as a string. + """ + table = "### Combined Metrics\n\n" + table += "| V1 Metric | V1 Parameters | V2 Metric | V2 Parameters |\n" + table += "|-----------|---------------|-----------|---------------|\n" + for metric_name, params in common_metrics.items(): + v1_params = ', '.join(common_metrics[metric_name].keys()) if params else 'N/A' + v2_params = ', '.join(common_metrics[metric_name].keys()) if params else 'N/A' + table += f"| {metric_name} | {v1_params} | {metric_name} | {v2_params} |\n" + + # Then, handle V1-only metrics (V2 shows as N/A) + for metric_name, v1_params in v1_metrics.items(): + v1_params_str = ', '.join(v1_params.keys()) if v1_params else 'N/A' + table += f"| {metric_name} | {v1_params_str} | N/A | N/A |\n" + + # Then, handle V2-only metrics (V1 shows as N/A) + for metric_name, v2_params in v2_metrics.items(): + v2_params_str = ', '.join(v2_params.keys()) if v2_params else 'N/A' + table += f"| N/A | N/A | {metric_name} | {v2_params_str} |\n" + + return table + +class ConvertJson: + + def __init__(self, json_fp, h1): + self.fp = json_fp + self.h1 = h1 + self.jdata = self.get_json() + self.mddata = self.format_json_to_md() + + def get_json(self): + with open(self.fp) as f: + res = json.load(f) + return res + + def format_json_to_md(self): + text = f'# {self.h1}\n' + dct = self.jdata + + # Extracting individual metric dictionaries + common_metrics = dct.get("common_metrics", {}) + v1_only_metrics = dct.get("v1_only_metrics", {}) + v2_only_metrics = dct.get("v2_only_metrics", {}) + + # Generate combined table + combined_metrics_table = generate_combined_markdown_table( + common_metrics, v1_only_metrics, v2_only_metrics + ) + + filtered_v1_metrics = { + "jaeger_collector_spans_rejected_total": {"debug": "false", "format": "","svc": "","transport":""}, + "jaeger_build_info": {"build_date": "","revision": ""," version": ""} # Add more metrics as needed + } + + # Hardcoding filtered v2 metrics + filtered_v2_metrics = { + "receiver_refused_spans": {"receiver": "","service_instance_id": "","service_name": "","service_version": "","transport": ""}, + "target_info": {"service_instance_id": "","service_name": "","service_version": ""} # Add more metrics as needed + } + spans_metrics_table = generate_spans_markdown_table(filtered_v1_metrics, filtered_v2_metrics) + text += combined_metrics_table+spans_metrics_table + return text + + def convert_dict_to_md(self, output_fn): + with open(output_fn, 'w') as writer: + writer.writelines(self.mddata) + print('Dict successfully converted to md') + +# Usage +fn = '' # Enter the path of the JSON file generated by compare_metrics.py +title = "TITLE" +converter = ConvertJson(fn, title) +converter.convert_dict_to_md(output_fn='metrics.md') \ No newline at end of file