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

853 opentelemetry metrics for server mode #944

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from

Conversation

dalpasso
Copy link
Collaborator

Implemented OpenTelemetry metrics with Prometheus exporter.

Metrics implemented:

  • number of searches by product type
  • data downloaded from each provider
  • number available providers
  • number available product types

@dalpasso dalpasso self-assigned this Nov 30, 2023
@dalpasso dalpasso linked an issue Nov 30, 2023 that may be closed by this pull request
Copy link
Contributor

github-actions bot commented Nov 30, 2023

Test Results

    4 files  ±0      4 suites  ±0   5m 17s ⏱️ -3s
  539 tests ±0    536 ✅ ±0   3 💤 ±0  0 ❌ ±0 
2 156 runs  ±0  2 058 ✅ ±0  98 💤 ±0  0 ❌ ±0 

Results for commit 96e5a8a. ± Comparison against base commit 0a6208a.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Nov 30, 2023

Code Coverage (Ubuntu)

File Coverage
All files 63%

Minimum allowed coverage is 70%

Generated by 🐒 cobertura-action against 2fa09fc

Copy link
Contributor

github-actions bot commented Nov 30, 2023

Code Coverage (Windows)

File Coverage
All files 20%

Minimum allowed coverage is 70%

Generated by 🐒 cobertura-action against 7edfabe

@dalpasso dalpasso force-pushed the 853-opentelemetry-metrics-for-server-mode branch 2 times, most recently from 79d31be to 8cf83ef Compare December 13, 2023 13:51
@sbrunato sbrunato force-pushed the 853-opentelemetry-metrics-for-server-mode branch from 7afb97b to 08eee64 Compare December 15, 2023 07:58
@dalpasso dalpasso force-pushed the 853-opentelemetry-metrics-for-server-mode branch 2 times, most recently from 2fa09fc to a515210 Compare January 11, 2024 14:57
@alambare-csgroup alambare-csgroup force-pushed the 853-opentelemetry-metrics-for-server-mode branch from a515210 to 0205ce5 Compare January 13, 2024 23:56
@sbrunato sbrunato added the pending Waiting for further information / action label Mar 5, 2024
@dalpasso dalpasso force-pushed the 853-opentelemetry-metrics-for-server-mode branch from abc6c8e to 34848a5 Compare May 16, 2024 12:26
Copy link
Contributor

github-actions bot commented May 16, 2024

badge

Code Coverage (Ubuntu)

Filename                                     Stmts    Miss  Cover    Missing
-----------------------------------------  -------  ------  -------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
__init__.py                                     10       0  100.00%
cli.py                                         302      51  83.11%   60, 644-690, 792-843, 847
config.py                                      349      27  92.26%   81-83, 92, 100, 104-106, 183, 195, 452-454, 518-521, 568-569, 578-579, 658, 727-732, 734
crunch.py                                        5       5  0.00%    20-24
api/__init__.py                                  0       0  100.00%
api/core.py                                    743      76  89.77%   88-97, 371, 596, 640-643, 681, 786, 790-795, 821, 917, 994, 1107, 1197-1209, 1249, 1251, 1255, 1278, 1282-1293, 1306-1312, 1402-1405, 1434-1454, 1511, 1528-1531, 1543-1546, 1914, 1947-1953, 2218, 2222-2225, 2239-2241, 2276
api/search_result.py                            44       6  86.36%   33-35, 70, 79, 86, 100
api/product/__init__.py                          5       0  100.00%
api/product/_assets.py                          44       5  88.64%   27-29, 79, 129
api/product/_product.py                        203      32  84.24%   52-59, 63-65, 169-176, 260-261, 343, 372, 433, 447-450, 463, 487-490, 533-539
api/product/metadata_mapping.py                677      84  87.59%   67-69, 130-132, 233, 265-266, 312-313, 323-335, 337, 348, 354-366, 407-410, 447, 468-471, 494, 502-503, 579-580, 604-605, 611-614, 629-630, 779, 825, 999-1004, 1135, 1149-1169, 1189, 1194, 1304, 1326, 1340, 1353-1372, 1411, 1463, 1501-1505, 1524
api/product/drivers/__init__.py                  5       0  100.00%
api/product/drivers/base.py                      8       2  75.00%   23, 41
plugins/__init__.py                              0       0  100.00%
plugins/base.py                                 23       3  86.96%   25, 48, 55
plugins/manager.py                             131      14  89.31%   49-51, 105-110, 156, 197, 219, 244, 283-284
plugins/apis/__init__.py                         0       0  100.00%
plugins/apis/base.py                             4       0  100.00%
plugins/apis/ecmwf.py                           98      15  84.69%   47-55, 156-158, 205-206, 232-234
plugins/apis/usgs.py                           172      36  79.07%   59-64, 128, 201, 235, 270-272, 277, 303-304, 309, 339-346, 357-362, 384-390, 392-398, 421
plugins/authentication/__init__.py               6       1  83.33%   31
plugins/authentication/aws_auth.py              20       2  90.00%   25-27
plugins/authentication/base.py                  19       3  84.21%   26, 34, 47
plugins/authentication/generic.py               16       3  81.25%   28, 40, 50
plugins/authentication/header.py                17       1  94.12%   27
plugins/authentication/keycloak.py              88      17  80.68%   32-34, 159-160, 190-212, 238-243
plugins/authentication/oauth.py                 15       8  46.67%   25, 32-34, 38-41
plugins/authentication/openid_connect.py       117      11  90.60%   40-42, 153, 159, 172-173, 184-189
plugins/authentication/qsauth.py                36       2  94.44%   32, 83
plugins/authentication/sas_auth.py              49       2  95.92%   32, 76
plugins/authentication/token.py                 90      17  81.11%   35-37, 79, 107, 109, 131-143, 198-201
plugins/authentication/token_exchange.py        35      19  45.71%   74-80, 92-120
plugins/crunch/__init__.py                       0       0  100.00%
plugins/crunch/base.py                          10       2  80.00%   25, 38
plugins/crunch/filter_date.py                   62      15  75.81%   30, 53-58, 72, 81, 90, 93, 105-107, 116-118, 125
plugins/crunch/filter_latest_intersect.py       50      10  80.00%   32-34, 51-52, 71, 80-83, 85, 92-95
plugins/crunch/filter_latest_tpl_name.py        33       2  93.94%   28, 86
plugins/crunch/filter_overlap.py                68      17  75.00%   28-30, 33, 82-85, 91, 99, 110-126
plugins/crunch/filter_property.py               33       8  75.76%   29, 60-65, 68-69, 85-89
plugins/download/__init__.py                     0       0  100.00%
plugins/download/aws.py                        493     165  66.53%   77-83, 272, 285, 352-355, 374-378, 424-426, 430, 464-465, 471-475, 508, 543, 547, 554, 584-592, 596, 634-642, 649-651, 692-766, 784-845, 856-861, 877-890, 919, 934-936, 939, 949-957, 965-978, 988-1007, 1014-1026, 1067, 1093, 1138-1140, 1360
plugins/download/base.py                       266      57  78.57%   59-65, 146, 181, 320-321, 341-347, 378-382, 388-389, 433, 436-450, 462, 466, 539-543, 573-574, 582-599, 606-614, 616-620, 667, 689, 711, 719
plugins/download/creodias_s3.py                 17       9  47.06%   44-58
plugins/download/http.py                       530     132  75.09%   85-91, 124, 203-213, 215-216, 251-254, 318-321, 323-324, 331-336, 354-369, 386-388, 400, 448, 455-461, 479, 493, 507, 515-517, 533-538, 549, 567, 609-613, 635, 675, 720, 734-740, 776-837, 855, 888-897, 923-924, 951-956, 962, 978, 995-996, 1028-1029, 1036, 1098-1104, 1159-1160, 1166, 1176, 1242, 1246, 1260-1276
plugins/download/s3rest.py                     119      27  77.31%   55-58, 121, 162, 197, 227-234, 237-239, 243, 256-262, 270-271, 274-278, 301, 322-325
plugins/search/__init__.py                       0       0  100.00%
plugins/search/base.py                         132      13  90.15%   49-54, 108, 112, 125, 275, 295, 354-355, 375, 384
plugins/search/build_search_result.py          179      24  86.59%   62, 97, 142-143, 149, 160, 296-299, 333, 390-407, 469, 472, 482, 499, 527, 529
plugins/search/creodias_s3.py                   54       3  94.44%   55, 73, 107
plugins/search/csw.py                          107      83  22.43%   43-45, 57-58, 62-63, 74-122, 128-141, 149-181, 199-240
plugins/search/data_request_search.py          197      65  67.01%   52, 89-92, 108, 120, 124-125, 139, 144, 149, 156, 169-172, 226-227, 231, 241-247, 252, 278-281, 289-300, 317, 319, 326-327, 329-330, 348-352, 385, 392, 403, 416, 422-434, 439
plugins/search/qssearch.py                     607      67  88.96%   101, 373-379, 387-388, 495-501, 549, 565, 575, 602, 604, 654-657, 730-731, 772, 791, 806, 859, 880, 883-884, 893, 904, 913, 936, 998-1003, 1007-1008, 1036, 1107, 1159, 1235-1239, 1305-1306, 1327, 1352-1364, 1371, 1402-1403, 1414-1420, 1463, 1478, 1498, 1599-1609
plugins/search/static_stac_search.py            47       3  93.62%   39-40, 82
rest/__init__.py                                 4       2  50.00%   21-22
rest/core.py                                   207      17  91.79%   66-72, 261, 345, 605, 607, 610-612, 684, 691-696
rest/server.py                                 299      53  82.27%   80-81, 107, 130-131, 244-246, 302-303, 315-331, 423-428, 460, 627-634, 667, 711-712, 803-805, 822-827, 858, 860, 864-865, 869-870
rest/stac.py                                   455      88  80.66%   63-65, 279, 301, 373, 410-412, 435, 470-471, 557-596, 633-638, 669, 689-690, 875, 940-942, 1161, 1171-1183, 1196-1218, 1232-1277, 1436-1437
rest/types/__init__.py                           0       0  100.00%
rest/types/eodag_search.py                     185       9  95.14%   52-55, 236-240, 293, 296, 364
rest/types/stac_queryables.py                   32       2  93.75%   28, 116
rest/types/stac_search.py                      121      10  91.74%   48-51, 167, 182-184, 192, 196
rest/utils/__init__.py                          95      13  86.32%   51, 108-109, 128-130, 182, 192-206
rest/utils/cql_evaluate.py                      48       5  89.58%   69, 76, 90, 97, 105
rest/utils/rfc3339.py                           31       3  90.32%   78, 90, 92
types/__init__.py                              110      11  90.00%   53, 70, 129-132, 199, 214-218, 245, 258
types/bbox.py                                   43      19  55.81%   46-61, 72-74, 85-87, 99-101, 113-115, 123
types/download_args.py                           9       0  100.00%
types/queryables.py                             81       0  100.00%
types/search_args.py                            70      18  74.29%   60-64, 71-88, 104
types/whoosh.py                                 15       0  100.00%
utils/__init__.py                              501      42  91.62%   84, 89, 110-112, 193-194, 203-230, 233, 247, 329-333, 409-413, 434-436, 518, 533, 571-572, 968-971, 979-980, 1021-1022, 1102, 1186, 1204, 1380
utils/constraints.py                           119      37  68.91%   94-103, 144, 149, 153, 164, 190-192, 202, 216-232, 241-252
utils/exceptions.py                             40       2  95.00%   23, 97
utils/import_system.py                          30      20  33.33%   27, 67-81, 93-103
utils/logging.py                                29       1  96.55%   123
utils/notebook.py                               44      23  47.73%   25-29, 36-41, 58-62, 72-78, 83-87
utils/requests.py                               55      11  80.00%   69, 96, 98, 100, 102, 104, 123, 128-130, 138
utils/rest.py                                   27       1  96.30%   49
utils/stac_reader.py                            91      28  69.23%   55-56, 63-86, 93-95, 99, 141, 155-158
TOTAL                                         9076    1559  82.82%

Diff against develop

Filename                      Stmts    Miss  Cover
--------------------------  -------  ------  -------
plugins/download/aws.py          +1       0  +0.07%
plugins/download/base.py         +6       0  +0.49%
plugins/download/http.py         +1       0  +0.04%
plugins/download/s3rest.py       +1       0  +0.19%
plugins/search/qssearch.py       +1       0  +0.02%
utils/exceptions.py              +3       0  +0.41%
TOTAL                           +13       0  +0.02%

Results for commit: 96e5a8a

Minimum allowed coverage is 70%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented May 16, 2024

badge

Code Coverage (Windows)

Filename                                     Stmts    Miss  Cover    Missing
-----------------------------------------  -------  ------  -------  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
__init__.py                                     10       0  100.00%
cli.py                                         302      51  83.11%   60, 644-690, 792-843, 847
config.py                                      349      28  91.98%   81-83, 92, 100, 104-106, 183, 195, 452-454, 518-521, 568-569, 578-579, 658, 692, 727-732, 734
crunch.py                                        5       5  0.00%    20-24
api/__init__.py                                  0       0  100.00%
api/core.py                                    743      76  89.77%   88-97, 371, 596, 640-643, 681, 786, 790-795, 821, 917, 994, 1107, 1197-1209, 1249, 1251, 1255, 1278, 1282-1293, 1306-1312, 1402-1405, 1434-1454, 1511, 1528-1531, 1543-1546, 1914, 1947-1953, 2218, 2222-2225, 2239-2241, 2276
api/search_result.py                            44       6  86.36%   33-35, 70, 79, 86, 100
api/product/__init__.py                          5       0  100.00%
api/product/_assets.py                          44       5  88.64%   27-29, 79, 129
api/product/_product.py                        203      32  84.24%   52-59, 63-65, 169-176, 260-261, 343, 372, 433, 447-450, 463, 487-490, 533-539
api/product/metadata_mapping.py                677      84  87.59%   67-69, 130-132, 233, 265-266, 312-313, 323-335, 337, 348, 354-366, 407-410, 447, 468-471, 494, 502-503, 579-580, 604-605, 611-614, 629-630, 779, 825, 999-1004, 1135, 1149-1169, 1189, 1194, 1304, 1326, 1340, 1353-1372, 1411, 1463, 1501-1505, 1524
api/product/drivers/__init__.py                  5       0  100.00%
api/product/drivers/base.py                      8       2  75.00%   23, 41
plugins/__init__.py                              0       0  100.00%
plugins/base.py                                 23       4  82.61%   25, 48, 55, 68
plugins/manager.py                             131      14  89.31%   49-51, 105-110, 156, 197, 219, 244, 283-284
plugins/apis/__init__.py                         0       0  100.00%
plugins/apis/base.py                             4       0  100.00%
plugins/apis/ecmwf.py                           98      15  84.69%   47-55, 156-158, 205-206, 232-234
plugins/apis/usgs.py                           172      36  79.07%   59-64, 128, 201, 235, 270-272, 277, 303-304, 309, 339-346, 357-362, 384-390, 392-398, 421
plugins/authentication/__init__.py               6       1  83.33%   31
plugins/authentication/aws_auth.py              20       2  90.00%   25-27
plugins/authentication/base.py                  19       3  84.21%   26, 34, 47
plugins/authentication/generic.py               16       3  81.25%   28, 40, 50
plugins/authentication/header.py                17       1  94.12%   27
plugins/authentication/keycloak.py              88      17  80.68%   32-34, 159-160, 190-212, 238-243
plugins/authentication/oauth.py                 15       8  46.67%   25, 32-34, 38-41
plugins/authentication/openid_connect.py       117      11  90.60%   40-42, 153, 159, 172-173, 184-189
plugins/authentication/qsauth.py                36       2  94.44%   32, 83
plugins/authentication/sas_auth.py              49       2  95.92%   32, 76
plugins/authentication/token.py                 90      17  81.11%   35-37, 79, 107, 109, 131-143, 198-201
plugins/authentication/token_exchange.py        35      19  45.71%   74-80, 92-120
plugins/crunch/__init__.py                       0       0  100.00%
plugins/crunch/base.py                          10       2  80.00%   25, 38
plugins/crunch/filter_date.py                   62      15  75.81%   30, 53-58, 72, 81, 90, 93, 105-107, 116-118, 125
plugins/crunch/filter_latest_intersect.py       50      35  30.00%   32-34, 48-53, 69-114
plugins/crunch/filter_latest_tpl_name.py        33       2  93.94%   28, 86
plugins/crunch/filter_overlap.py                68      17  75.00%   28-30, 33, 82-85, 91, 99, 110-126
plugins/crunch/filter_property.py               33       8  75.76%   29, 60-65, 68-69, 85-89
plugins/download/__init__.py                     0       0  100.00%
plugins/download/aws.py                        493     165  66.53%   77-83, 272, 285, 352-355, 374-378, 424-426, 430, 464-465, 471-475, 508, 543, 547, 554, 584-592, 596, 634-642, 649-651, 692-766, 784-845, 856-861, 877-890, 919, 934-936, 939, 949-957, 965-978, 988-1007, 1014-1026, 1067, 1093, 1138-1140, 1360
plugins/download/base.py                       266      59  77.82%   59-65, 146, 181, 251-253, 320-321, 341-347, 378-382, 388-389, 433, 436-450, 462, 466, 539-543, 573-574, 582-599, 606-614, 616-620, 667, 689, 711, 719
plugins/download/creodias_s3.py                 17       9  47.06%   44-58
plugins/download/http.py                       530     132  75.09%   85-91, 124, 203-213, 215-216, 251-254, 318-321, 323-324, 331-336, 354-369, 386-388, 400, 448, 455-461, 479, 493, 507, 515-517, 533-538, 549, 567, 609-613, 635, 675, 720, 734-740, 776-837, 855, 888-897, 923-924, 951-956, 962, 978, 995-996, 1028-1029, 1036, 1098-1104, 1159-1160, 1166, 1176, 1242, 1246, 1260-1276
plugins/download/s3rest.py                     119      27  77.31%   55-58, 121, 162, 197, 227-234, 237-239, 243, 256-262, 270-271, 274-278, 301, 322-325
plugins/search/__init__.py                       0       0  100.00%
plugins/search/base.py                         132      18  86.36%   49-54, 108, 112, 125, 275, 295, 354-355, 375, 378-386, 388
plugins/search/build_search_result.py          179      31  82.68%   62, 97, 142-143, 149, 160, 296-299, 333, 390-407, 469, 472, 482, 499, 519-534
plugins/search/creodias_s3.py                   54       3  94.44%   55, 73, 107
plugins/search/csw.py                          107      83  22.43%   43-45, 57-58, 62-63, 74-122, 128-141, 149-181, 199-240
plugins/search/data_request_search.py          197      65  67.01%   52, 89-92, 108, 120, 124-125, 139, 144, 149, 156, 169-172, 226-227, 231, 241-247, 252, 278-281, 289-300, 317, 319, 326-327, 329-330, 348-352, 385, 392, 403, 416, 422-434, 439
plugins/search/qssearch.py                     607      95  84.35%   101, 373-379, 387-388, 495-501, 549, 552, 565, 575, 594-609, 654-657, 730-731, 772, 791, 806, 859, 880, 883-884, 893, 904, 913, 936, 998-1003, 1007-1008, 1036, 1107, 1159, 1235-1239, 1305-1306, 1327, 1352-1364, 1371, 1402-1403, 1414-1420, 1463, 1478, 1498, 1560-1629
plugins/search/static_stac_search.py            47       3  93.62%   39-40, 82
rest/__init__.py                                 4       2  50.00%   21-22
rest/core.py                                   207      96  53.62%   66-72, 153, 155, 157, 163-164, 185-193, 199-205, 252-306, 319-355, 505-536, 554, 604-643, 684, 691-696
rest/server.py                                 299     299  0.00%    18-883
rest/stac.py                                   455     147  67.69%   63-65, 232, 279, 301, 373, 410-412, 435, 470-471, 557-596, 633-638, 669, 677-678, 682-690, 817, 875, 940-942, 959-961, 969-971, 984-986, 1000-1017, 1027-1048, 1058-1080, 1088-1105, 1128-1151, 1161, 1171-1183, 1196-1218, 1232-1277, 1430-1456
rest/types/__init__.py                           0       0  100.00%
rest/types/eodag_search.py                     185      18  90.27%   52-55, 236-240, 273-275, 293, 296, 302, 306, 364, 376-379
rest/types/stac_queryables.py                   32       6  81.25%   28, 55-60, 116
rest/types/stac_search.py                      121      12  90.08%   48-51, 167, 182-184, 192, 196, 240, 243
rest/utils/__init__.py                          95      31  67.37%   51, 79-85, 105, 108-109, 128-130, 143, 150, 175-183, 190-211
rest/utils/cql_evaluate.py                      48       5  89.58%   69, 76, 90, 97, 105
rest/utils/rfc3339.py                           31       5  83.87%   73-74, 78, 90, 92
types/__init__.py                              110      36  67.27%   53, 66-70, 81-93, 120-122, 129-132, 172, 199, 209-221, 226, 245, 250, 258, 268
types/bbox.py                                   43      19  55.81%   46-61, 72-74, 85-87, 99-101, 113-115, 123
types/download_args.py                           9       0  100.00%
types/queryables.py                             81       0  100.00%
types/search_args.py                            70      18  74.29%   60-64, 71-88, 104
types/whoosh.py                                 15       0  100.00%
utils/__init__.py                              501      43  91.42%   84, 89, 110-112, 193-194, 203-230, 233, 247, 329-333, 409-413, 434-436, 518, 533, 571-572, 968-971, 979-980, 1021-1022, 1102, 1185-1186, 1204, 1380
utils/constraints.py                           119      37  68.91%   94-103, 144, 149, 153, 164, 190-192, 202, 216-232, 241-252
utils/exceptions.py                             40       2  95.00%   23, 97
utils/import_system.py                          30      20  33.33%   27, 67-81, 93-103
utils/logging.py                                29       1  96.55%   123
utils/notebook.py                               44      23  47.73%   25-29, 36-41, 58-62, 72-78, 83-87
utils/requests.py                               55      11  80.00%   69, 96, 98, 100, 102, 104, 123, 128-130, 138
utils/rest.py                                   27       1  96.30%   49
utils/stac_reader.py                            91      28  69.23%   55-56, 63-86, 93-95, 99, 141, 155-158
TOTAL                                         9076    2073  77.16%

Diff against develop

Filename                      Stmts    Miss  Cover
--------------------------  -------  ------  -------
plugins/download/aws.py          +1       0  +0.07%
plugins/download/base.py         +6       0  +0.51%
plugins/download/http.py         +1       0  +0.04%
plugins/download/s3rest.py       +1       0  +0.19%
plugins/search/qssearch.py       +1       0  +0.03%
utils/exceptions.py              +3       0  +0.41%
TOTAL                           +13       0  +0.03%

Results for commit: 96e5a8a

Minimum allowed coverage is 70%

♻️ This comment has been updated with latest results

@dalpasso dalpasso force-pushed the 853-opentelemetry-metrics-for-server-mode branch from 0c83fc7 to b87329b Compare May 16, 2024 16:10
@dalpasso dalpasso marked this pull request as ready for review May 22, 2024 07:49
@dalpasso
Copy link
Collaborator Author

Instructions to run the metrics.

Start the OTEL collector:

docker compose -f docker-compose.yml up otel-collector

Set the following environment variables:

export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318/"
export OTEL_METRIC_EXPORT_INTERVAL="5000"

Run EODAG in server mode. The metrics are available on http://localhost:8000/metrics

Comment on lines 148 to 159
{{- if .Values.otel.endpoint }}
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ .Values.otel.endpoint | quote }}
{{- end }}
{{- if .Values.otel.timeout }}
- name: OTEL_EXPORTER_OTLP_TIMEOUT
value: {{ .Values.otel.timeout | quote }}
{{- end }}
{{- if .Values.otel.interval }}
- name: OTEL_METRIC_EXPORT_INTERVAL
value: {{ .Values.otel.interval | quote }}
{{- end }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify that and require OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TIMEOUT and OTEL_METRIC_EXPORT_INTERVAL if otel is enabled. No need to verify parameters individually.

Comment on lines 899 to 990
def telemetry_init(fastapi_app: Optional[FastAPI] = None) -> None:
"""Init telemetry

:param fastapi_app: FastAPI to automatically instrument.
:type fastapi_app: FastAPI"""

if not os.getenv("OTEL_EXPORTER_OTLP_ENDPOINT"):
return None
if "opentelemetry" not in sys.modules:
return None

# Start OTLP exporter
resource = Resource(attributes={SERVICE_NAME: "eodag-serve-rest"})
# trace
tracer_provider = TracerProvider(resource=resource)
processor = BatchSpanProcessor(OTLPSpanExporter())
tracer_provider.add_span_processor(processor)
trace.set_tracer_provider(tracer_provider)
# metrics
reader = PeriodicExportingMetricReader(OTLPMetricExporter())
view_histograms: View = View(
instrument_type=Histogram,
aggregation=ExplicitBucketHistogramAggregation(
boundaries=(
0.25,
0.50,
0.75,
1.0,
1.5,
2.0,
3.0,
4.0,
5.0,
6.0,
7.0,
8.0,
9.0,
10.0,
)
),
)
view_overhead_histograms: View = View(
instrument_type=Histogram,
instrument_name="*overhead*",
aggregation=ExplicitBucketHistogramAggregation(
boundaries=(
0.030,
0.040,
0.050,
0.060,
0.070,
0.080,
0.090,
0.100,
0.125,
0.150,
0.175,
0.200,
0.250,
0.500,
)
),
)
meter_provider = MeterProvider(
resource=resource,
metric_readers=[reader],
views=(
view_histograms,
view_overhead_histograms,
),
)
metrics.set_meter_provider(meter_provider)

# Auto instrumentation
if fastapi_app:
logger.debug("Instrument FastAPI app")
FastAPIInstrumentor.instrument_app(
app=fastapi_app,
tracer_provider=tracer_provider,
meter_provider=meter_provider,
)
logger.debug("Instrument EODAG app")

from eodag.utils.instrumentation.eodag import EODAGInstrumentor

EODAGInstrumentor(eodag_api).instrument(
tracer_provider=tracer_provider,
meter_provider=meter_provider,
)
return None


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this function to a separate file

Comment on lines 1 to 18
# -*- coding: utf-8 -*-
# Copyright 2023, CS GROUP - France, https://www.csgroup.eu/
#
# This file is part of EODAG project
# https://www.github.com/CS-SI/EODAG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""OpenTelemetry auto-instrumentation packages"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be removed, we take the instrumentation from https://github.com/CS-SI/opentelemetry-instrumentation-eodag

Comment on lines 1 to 605
:rtype: Iterable[Observation]
"""
new_available_product_types: List[str] = [
p["ID"] for p in self._eodag_api.list_product_types()
]
observations_dict: Dict[str, int] = {
p: 0 for p in self._last_available_product_types
}
for p in new_available_product_types:
observations_dict[p] = 1
self._last_available_product_types = new_available_product_types
observations = [
Observation(
v,
{"product_type_id": k},
)
for k, v in observations_dict.items()
]
return observations

def _instrument(self, **kwargs) -> None:
"""Instruments EODAG"""
tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(__name__, tracer_provider=tracer_provider)
meter_provider = kwargs.get("meter_provider")
meter = get_meter(__name__, meter_provider=meter_provider)

if self._eodag_api:
meter.create_observable_gauge(
name="eodag.core.available_providers",
callbacks=[self._available_providers_callback],
description="The number available providers",
)
meter.create_observable_gauge(
name="eodag.core.available_product_types",
callbacks=[self._available_product_types_callback],
description="The number available product types",
)

request_duration_seconds = meter.create_histogram(
name="eodag.server.request_duration_seconds",
unit="s",
description="Measures the duration of the inbound HTTP request",
)
outbound_request_duration_seconds = meter.create_histogram(
name="eodag.core.outbound_request_duration_seconds",
unit="s",
description="Measure the duration of the outbound HTTP request",
)
request_overhead_duration_seconds = meter.create_histogram(
name="eodag.server.request_overhead_duration_seconds",
unit="s",
description="Measure the duration of the EODAG overhead on the inbound HTTP request",
)

downloaded_data_counter = meter.create_counter(
name="eodag.download.downloaded_data_bytes_total",
description="Measure data downloaded from each provider and product type",
)
_instrument_download(
tracer,
downloaded_data_counter,
request_duration_seconds,
outbound_request_duration_seconds,
request_overhead_duration_seconds,
)

searched_product_types_counter = meter.create_counter(
name="eodag.core.searched_product_types_total",
description="The number of searches by provider and product type",
)
_instrument_search(
tracer,
searched_product_types_counter,
request_duration_seconds,
outbound_request_duration_seconds,
request_overhead_duration_seconds,
)

def _uninstrument(self, **kwargs) -> None:
"""Uninstrument the library.

This only works if no other module also patches eodag"""
from eodag.rest import server

patches = [
(server, "search_stac_items"),
(server, "download_stac_item"),
(QueryStringSearch, "_request"),
(Download, "progress_callback_decorator"),
]
for p in patches:
instr_func = getattr(p[0], p[1])
if not getattr(
instr_func,
"opentelemetry_instrumentation_eodag_applied",
False,
):
continue
setattr(p[0], p[1], instr_func.__wrapped__)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this as well

Comment on lines 1 to 21
# -*- coding: utf-8 -*-
# Copyright 2023, CS GROUP - France, https://www.csgroup.eu/
#
# This file is part of EODAG project
# https://www.github.com/CS-SI/EODAG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

_instruments = ("eodag ~= 2.0",)

_supports_metrics = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this as well

@dalpasso dalpasso force-pushed the 853-opentelemetry-metrics-for-server-mode branch from ae8bba6 to 96e5a8a Compare May 28, 2024 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending Waiting for further information / action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prometheus metrics for server mode
3 participants