Publish Cloud-OpsBench v1.0.0 benchmark artifacts (part 10)
Browse filesSource: https://github.com/LLM4Ops/Cloud-OpsBench/tree/ea05dafbc87b5985df8721622d63d4229c2b4224
This view is limited to 50 files because it contains too many changes. See raw diff
- benchmark/boutique/codedefect/31/raw_data/metrics.csv +54 -0
- benchmark/boutique/codedefect/31/tool_cache.json +0 -0
- benchmark/boutique/codedefect/32/code/adservice/src/main/java/hipstershop/AdService.java +238 -0
- benchmark/boutique/codedefect/32/code/adservice/src/main/java/hipstershop/AdServiceClient.java +116 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/Program.cs +26 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/Startup.cs +84 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/AlloyDBCartStore.cs +177 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/ICartStore.cs +26 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/RedisCartStore.cs +118 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/SpannerCartStore.cs +185 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/services/CartService.cs +51 -0
- benchmark/boutique/codedefect/32/code/cartservice/src/services/HealthCheckService.cs +41 -0
- benchmark/boutique/codedefect/32/code/checkoutservice/main.go +394 -0
- benchmark/boutique/codedefect/32/code/checkoutservice/money/money.go +132 -0
- benchmark/boutique/codedefect/32/code/currencyservice/client.js +68 -0
- benchmark/boutique/codedefect/32/code/currencyservice/server.js +198 -0
- benchmark/boutique/codedefect/32/code/emailservice/email_client.py +39 -0
- benchmark/boutique/codedefect/32/code/emailservice/email_server.py +200 -0
- benchmark/boutique/codedefect/32/code/emailservice/logger.py +41 -0
- benchmark/boutique/codedefect/32/code/frontend/deployment_details.go +64 -0
- benchmark/boutique/codedefect/32/code/frontend/handlers.go +638 -0
- benchmark/boutique/codedefect/32/code/frontend/main.go +235 -0
- benchmark/boutique/codedefect/32/code/frontend/middleware.go +111 -0
- benchmark/boutique/codedefect/32/code/frontend/money/money.go +132 -0
- benchmark/boutique/codedefect/32/code/frontend/packaging_info.go +79 -0
- benchmark/boutique/codedefect/32/code/frontend/rpc.go +127 -0
- benchmark/boutique/codedefect/32/code/frontend/validator/validator.go +83 -0
- benchmark/boutique/codedefect/32/code/paymentservice/charge.js +86 -0
- benchmark/boutique/codedefect/32/code/paymentservice/index.js +75 -0
- benchmark/boutique/codedefect/32/code/paymentservice/logger.js +27 -0
- benchmark/boutique/codedefect/32/code/paymentservice/server.js +106 -0
- benchmark/boutique/codedefect/32/code/productcatalogservice/catalog_loader.go +161 -0
- benchmark/boutique/codedefect/32/code/productcatalogservice/product_catalog.go +83 -0
- benchmark/boutique/codedefect/32/code/productcatalogservice/server.go +217 -0
- benchmark/boutique/codedefect/32/code/recommendationservice/client.py +39 -0
- benchmark/boutique/codedefect/32/code/recommendationservice/logger.py +41 -0
- benchmark/boutique/codedefect/32/code/recommendationservice/recommendation_server.py +156 -0
- benchmark/boutique/codedefect/32/code/shippingservice/main.go +183 -0
- benchmark/boutique/codedefect/32/code/shippingservice/quote.go +48 -0
- benchmark/boutique/codedefect/32/code/shippingservice/tracker.go +47 -0
- benchmark/boutique/codedefect/32/metadata.json +10 -0
- benchmark/boutique/codedefect/32/raw_data/alert.json +30 -0
- benchmark/boutique/codedefect/32/raw_data/k8s_states.json +0 -0
- benchmark/boutique/codedefect/32/raw_data/logs.json +0 -0
- benchmark/boutique/codedefect/32/raw_data/metrics.csv +54 -0
- benchmark/boutique/codedefect/32/tool_cache.json +0 -0
- benchmark/boutique/codedefect/33/code/adservice/src/main/java/hipstershop/AdService.java +238 -0
- benchmark/boutique/codedefect/33/code/adservice/src/main/java/hipstershop/AdServiceClient.java +116 -0
- benchmark/boutique/codedefect/33/code/cartservice/src/Program.cs +26 -0
- benchmark/boutique/codedefect/33/code/cartservice/src/Startup.cs +84 -0
benchmark/boutique/codedefect/31/raw_data/metrics.csv
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
time,frontend-cpu,frontend-mem,frontend-cpu_cfs,frontend-rps,frontend-success_rate,frontend-network_receive,frontend-network_transmit,frontend-p50latency,frontend-p90latency,frontend-fs_write_bytes,checkoutservice-cpu,checkoutservice-mem,checkoutservice-cpu_cfs,checkoutservice-rps,checkoutservice-success_rate,checkoutservice-network_receive,checkoutservice-network_transmit,checkoutservice-p50latency,checkoutservice-p90latency,checkoutservice-fs_write_bytes,productcatalogservice-cpu,productcatalogservice-mem,productcatalogservice-cpu_cfs,productcatalogservice-rps,productcatalogservice-success_rate,productcatalogservice-network_receive,productcatalogservice-network_transmit,productcatalogservice-p50latency,productcatalogservice-p90latency,productcatalogservice-fs_write_bytes,cartservice-cpu,cartservice-mem,cartservice-cpu_cfs,cartservice-rps,cartservice-success_rate,cartservice-network_receive,cartservice-network_transmit,cartservice-p50latency,cartservice-p90latency,cartservice-fs_write_bytes,currencyservice-cpu,currencyservice-mem,currencyservice-cpu_cfs,currencyservice-rps,currencyservice-success_rate,currencyservice-network_receive,currencyservice-network_transmit,currencyservice-p50latency,currencyservice-p90latency,currencyservice-fs_write_bytes,paymentservice-cpu,paymentservice-mem,paymentservice-cpu_cfs,paymentservice-rps,paymentservice-success_rate,paymentservice-network_receive,paymentservice-network_transmit,paymentservice-p50latency,paymentservice-p90latency,paymentservice-fs_write_bytes,shippingservice-cpu,shippingservice-mem,shippingservice-cpu_cfs,shippingservice-rps,shippingservice-success_rate,shippingservice-network_receive,shippingservice-network_transmit,shippingservice-p50latency,shippingservice-p90latency,shippingservice-fs_write_bytes,emailservice-cpu,emailservice-mem,emailservice-cpu_cfs,emailservice-rps,emailservice-success_rate,emailservice-network_receive,emailservice-network_transmit,emailservice-p50latency,emailservice-p90latency,emailservice-fs_write_bytes,recommendationservice-cpu,recommendationservice-mem,recommendationservice-cpu_cfs,recommendationservice-rps,recommendationservice-success_rate,recommendationservice-network_receive,recommendationservice-network_transmit,recommendationservice-p50latency,recommendationservice-p90latency,recommendationservice-fs_write_bytes,adservice-cpu,adservice-mem,adservice-cpu_cfs,adservice-rps,adservice-success_rate,adservice-network_receive,adservice-network_transmit,adservice-p50latency,adservice-p90latency,adservice-fs_write_bytes,redis-cart-cpu,redis-cart-mem,redis-cart-cpu_cfs,redis-cart-rps,redis-cart-success_rate,redis-cart-network_receive,redis-cart-network_transmit,redis-cart-p50latency,redis-cart-p90latency,redis-cart-fs_write_bytes,master-cpu,master-mem,master-tcp_retans,worker-01-cpu,worker-01-mem,worker-01-tcp_retans,worker-02-cpu,worker-02-mem,worker-02-tcp_retans,worker-03-cpu,worker-03-mem,worker-03-tcp_retans
|
| 2 |
+
2026-05-19 10:29:42,0.001,18780160.0,0.0,0.0,0.0,10.632,10.611,0.0,0.0,0,0.0,37236736.0,0.0,0,0,2.956,2.384,0,0,0,0.001,15114240.0,0.0,0.0,0.0,2.377,1.601,0.0,0.0,0,0.022,78225408.0,0.11,0.0,0.0,3.063,2.831,0.0,0.0,0,0.001,48930816.0,0.0,0.7,1.0,3.484,2.801,2.755,4.77,0,0.002,32059392.0,0.01,0,0,2.062,1.527,0,0,0,0.0,11919360.0,0.0,0.148,1.0,3.881,2.785,0.417,4.0,0,0.001,89534464.0,0.0,0,0,2.82,2.227,0,0,0,0.001,86601728.0,0.0,0.0,0.0,3.703,3.109,0.0,0.0,0,0.003,170713088.0,0.006,0.079,1.0,4.97,3.902,3.534,17.879,0.0,0.003,13320192.0,0.0,0,0,4.668,3.442,0,0,0.0,3.789,34.041,0.067,3.457,30.979,0.0,3.636,29.577,0.0,2.953,33.994,0.0
|
| 3 |
+
2026-05-19 10:29:47,0.001,18780160.0,0.0,0.279,1.0,10.632,10.611,17.233,57.656,0,0.0,37322752.0,0.0,0,0,2.601,2.139,0,0,0,0.001,15114240.0,0.0,1.625,1.0,5.263,3.597,0.256,0.461,0,0.022,78225408.0,0.11,0.0,0.0,3.235,2.941,3.931,22.491,0,0.001,49090560.0,0.0,0.845,1.0,4.58,3.751,2.891,4.701,0,0.0,32378880.0,0.0,0,0,2.268,1.719,0,0,0,0.0,11919360.0,0.0,0.176,1.0,3.859,2.727,0.431,4.863,0,0.001,89534464.0,0.0,0,0,2.82,2.227,0,0,0,0.001,86601728.0,0.0,0.0,0.0,3.703,3.109,3.162,4.891,0,0.003,170713088.0,0.008,0.096,1.0,3.324,2.577,3.324,14.234,0.0,0.004,13508608.0,0.0,0,0,3.713,2.72,0,0,0.0,3.789,34.041,0.067,3.457,30.979,0.0,3.64,29.584,0.0,3.025,33.994,0.0
|
| 4 |
+
2026-05-19 10:29:52,0.002,18780160.0,0.0,0.334,1.0,10.632,10.611,16.869,55.972,0,0.0,27340800.0,0.0,0,0,2.601,2.139,0,0,0,0.001,15114240.0,0.0,1.942,1.0,7.579,5.171,0.268,0.483,0,0.033,78225408.0,0.162,0.388,1.0,3.881,3.679,3.573,21.034,0,0.002,49090560.0,0.0,0.989,1.0,4.58,3.751,2.873,4.678,0,0.0,32378880.0,0.0,0,0,2.267,1.7,0,0,0,0.0,11919360.0,0.0,0.221,1.0,3.859,2.727,0.356,4.538,0,0.001,89534464.0,0.0,0,0,2.717,2.177,0,0,0,0.002,86601728.0,0.0,0.275,1.0,4.705,3.905,3.072,4.729,0,0.003,170713088.0,0.008,0.112,1.0,3.302,2.543,3.266,12.234,0.0,0.004,13508608.0,0.0,0,0,4.227,3.096,0,0,0.0,3.821,34.053,0.0,3.457,30.979,0.0,3.743,29.584,0.0,3.025,33.994,0.0
|
| 5 |
+
2026-05-19 10:29:57,0.002,19005440.0,0.0,0.39,1.0,11.19,11.41,16.624,54.684,0,0.0,27340800.0,0.0,0,0,2.555,2.01,0,0,0,0.001,15388672.0,0.0,2.259,1.0,7.579,5.171,0.268,0.483,0,0.027,78835712.0,0.128,0.46,1.0,4.905,4.651,3.545,20.817,0,0.002,49090560.0,0.0,1.485,1.0,6.34,5.559,2.382,4.564,0,0.0,32378880.0,0.0,0,0,2.267,1.7,0,0,0,0.0,12005376.0,0.0,0.251,1.0,3.859,2.727,0.35,4.341,0,0.001,89534464.0,0.0,0,0,2.876,2.292,0,0,0,0.001,86601728.0,0.0,0.325,1.0,4.902,4.023,3.061,4.71,0,0.003,171315200.0,0.007,0.167,1.0,3.302,2.543,3.208,4.975,0.0,0.004,13508608.0,0.0,0,0,4.604,3.316,0,0,0.0,3.821,34.053,0.0,3.525,30.924,0.0,3.743,29.584,0.0,3.107,34.05,0.0
|
| 6 |
+
2026-05-19 10:30:02,0.002,19005440.0,0.0,0.557,1.0,10.058,10.256,19.479,55.228,0,0.0,27385856.0,0.0,0,0,2.555,2.01,0,0,0,0.001,15388672.0,0.0,3.569,1.0,7.827,5.54,0.269,0.485,0,0.027,78835712.0,0.128,0.532,1.0,4.963,4.498,3.575,23.254,0,0.003,49614848.0,0.0,1.679,1.0,6.34,5.559,2.489,4.633,0,0.0,32509952.0,0.0,0,0,2.267,1.7,0,0,0,0.0,12005376.0,0.0,0.282,1.0,3.988,2.744,0.362,4.383,0,0.0,89534464.0,0.0,0,0,2.876,2.292,0,0,0,0.002,86614016.0,0.0,0.375,1.0,4.902,4.023,3.075,4.735,0,0.003,171315200.0,0.007,0.189,1.0,3.302,2.543,3.198,4.957,0.0,0.004,13377536.0,0.0,0,0,5.107,3.678,0,0,0.0,3.821,34.053,0.0,3.525,30.924,0.0,3.879,29.694,0.0,3.068,34.05,0.0
|
| 7 |
+
2026-05-19 10:30:07,0.003,19005440.0,0.0,0.626,1.0,19.293,19.685,19.315,53.543,0,0.0,27385856.0,0.0,0,0,2.544,1.936,0,0,0,0.001,15998976.0,0.0,4.008,1.0,7.827,5.54,0.272,0.49,0,0.017,78835712.0,0.049,0.581,1.0,4.963,4.498,3.571,23.334,0,0.003,49614848.0,0.0,1.873,1.0,7.53,6.655,2.476,4.619,0,0.0,32509952.0,0.0,0,0,1.699,1.344,0,0,0,0.0,12816384.0,0.0,0.304,1.0,3.988,2.744,0.335,4.04,0,0.001,89534464.0,0.0,0,0,2.205,1.764,0,0,0,0.002,86614016.0,0.0,0.425,1.0,4.902,4.023,3.059,4.706,0,0.003,171315200.0,0.007,0.211,1.0,3.557,2.651,3.175,4.915,0.0,0.004,13377536.0,0.0,0,0,5.271,3.796,0,0,0.0,3.654,34.061,0.133,3.525,30.924,0.0,3.749,29.694,0.0,3.068,34.05,0.0
|
| 8 |
+
2026-05-19 10:30:12,0.003,19161088.0,0.0,0.696,1.0,19.293,19.685,19.187,52.15,0,0.0,27385856.0,0.0,0,0,2.544,1.936,0,0,0,0.001,15998976.0,0.0,4.447,1.0,8.515,6.115,0.272,0.49,0,0.019,82993152.0,0.053,0.651,1.0,4.963,4.498,3.557,23.135,0,0.003,49614848.0,0.0,2.293,1.0,6.474,5.722,2.434,4.601,0,0.0,32653312.0,0.0,0,0,1.699,1.344,0,0,0,0.0,12816384.0,0.0,0.334,1.0,4.005,2.8,0.332,3.934,0,0.001,89534464.0,0.0,0,0,2.603,2.082,0,0,0,0.002,86614016.0,0.0,0.475,1.0,3.425,2.825,3.053,4.695,0,0.002,171315200.0,0.0,0.197,1.0,3.557,2.651,3.161,4.889,0.0,0.004,13377536.0,0.0,0,0,5.485,3.878,0,0,0.0,3.654,34.061,0.133,3.565,30.978,0.0,3.749,29.694,0.0,2.989,34.055,0.0
|
| 9 |
+
2026-05-19 10:30:17,0.003,19161088.0,0.0,0.907,1.0,19.463,20.292,22.161,71.713,0,0.0,27435008.0,0.0,0,0,2.391,1.898,0,0,0,0.001,15998976.0,0.0,5.647,1.0,7.02,5.041,0.276,0.497,0,0.019,82993152.0,0.053,0.833,1.0,4.815,4.321,3.731,68.183,0,0.004,49885184.0,0.0,2.511,1.0,8.866,8.288,2.459,4.584,0,0.0,32653312.0,0.0,0,0,2.348,2.01,0,0,0,0.0,12816384.0,0.0,0.356,1.0,4.005,2.8,0.348,4.103,0,0.001,89534464.0,0.0,0,0,2.603,2.082,0,0,0,0.002,86626304.0,0.0,0.6,1.0,3.796,3.131,3.153,4.875,0,0.003,171626496.0,0.0,0.216,1.0,3.557,2.651,3.17,4.906,0.0,0.004,13381632.0,0.0,0,0,5.485,3.878,0,0,0.0,3.654,34.061,0.133,3.565,30.978,0.0,3.535,29.724,0.0,3.024,34.055,0.0
|
| 10 |
+
2026-05-19 10:30:22,0.003,19161088.0,0.0,0.933,1.0,19.463,20.292,21.394,51.939,0,0.0,17780736.0,0.0,0,0,2.281,1.798,0,0,0,0.002,16506880.0,0.0,5.956,1.0,6.311,4.532,0.273,0.491,0,0.019,84070400.0,0.049,0.933,1.0,4.815,4.321,3.401,23.353,0,0.004,49885184.0,0.0,2.622,1.0,8.866,8.288,2.438,4.549,0,0.0,32653312.0,0.0,0,0,2.878,2.555,0,0,0,0.0,12996608.0,0.0,1.182,1.0,3.591,2.618,0.317,3.478,0,0.001,89534464.0,0.0,0,0,2.675,2.125,0,0,0,0.002,86626304.0,0.0,0.667,1.0,7.688,7.535,3.039,4.67,0,0.003,171626496.0,0.0,0.222,1.0,4.025,3.009,3.072,4.73,0.0,0.003,13381632.0,0.0,0,0,3.791,2.66,0,0,0.0,3.942,34.044,0.467,3.565,30.978,0.0,3.693,29.724,0.0,3.024,34.055,0.0
|
| 11 |
+
2026-05-19 10:30:27,0.008,20283392.0,0.002,0.933,1.0,47.345,50.218,20.5,48.409,0,0.0,17780736.0,0.0,0,0,2.281,1.798,0,0,0,0.003,16506880.0,0.0,5.956,1.0,3.2,2.5,0.27,0.487,0,0.016,84070400.0,0.039,0.933,1.0,4.815,4.321,3.229,17.875,0,0.01,51912704.0,0.006,7.626,1.0,8.866,8.288,2.618,4.779,0,0.0,32919552.0,0.0,0,0,2.878,2.555,0,0,0,0.0,12996608.0,0.0,1.299,1.0,4.788,3.315,0.304,2.764,0,0.001,89534464.0,0.0,0,0,2.553,2.087,0,0,0,0.002,86626304.0,0.0,0.667,1.0,7.688,7.535,3.0,4.6,0,0.003,171626496.0,0.0,0.897,1.0,4.025,3.009,3.304,7.404,0.0,0.004,13381632.0,0.0,0,0,8.926,6.481,0,0,0.0,3.942,34.044,0.467,3.871,31.01,0.0,3.693,29.724,0.0,3.086,34.071,0.0
|
| 12 |
+
2026-05-19 10:30:32,0.008,20283392.0,0.002,4.987,1.0,47.345,50.218,26.323,117.368,0,0.0,18591744.0,0.0,0,0,2.281,1.798,0,0,0,0.003,16506880.0,0.0,26.54,1.0,3.2,2.5,0.316,3.081,0,0.016,84070400.0,0.039,0.933,1.0,5.356,4.842,3.381,44.58,0,0.01,51912704.0,0.006,8.369,1.0,10.156,9.75,2.875,4.971,0,0.0,32919552.0,0.0,0,0,2.622,2.219,0,0,0,0.0,12996608.0,0.0,1.4,1.0,4.58,3.113,0.368,3.9,0,0.001,89534464.0,0.0,0,0,2.553,2.087,0,0,0,0.008,87166976.0,0.002,0.667,1.0,8.48,8.505,3.732,9.36,0,0.003,171626496.0,0.0,0.982,1.0,3.632,2.69,3.578,9.246,0.0,0.004,13537280.0,0.0,0,0,10.588,7.641,0,0,0.0,3.942,34.044,0.467,3.871,31.01,0.0,4.149,29.763,0.0,3.103,34.071,0.0
|
| 13 |
+
2026-05-19 10:30:37,0.008,20283392.0,0.003,5.476,1.0,47.345,50.218,27.326,117.368,0,0.0,18591744.0,0.0,0,0,2.394,1.971,0,0,0,0.006,16777216.0,0.0,29.107,1.0,41.21,32.512,0.328,3.337,0,0.013,84070400.0,0.033,6.21,1.0,19.388,19.467,2.961,46.357,0,0.012,51912704.0,0.008,8.911,1.0,29.061,28.984,2.874,4.977,0,0.0,32919552.0,0.0,0,0,2.622,2.219,0,0,0,0.0,12996608.0,0.0,2.805,1.0,5.346,3.634,0.309,2.989,0,0.001,89534464.0,0.0,0,0,2.336,1.92,0,0,0,0.008,87166976.0,0.002,4.185,1.0,15.517,16.292,3.646,9.093,0,0.002,171626496.0,0.0,1.022,1.0,6.816,4.445,3.574,9.046,0.0,0.004,13537280.0,0.0,0,0,10.588,7.641,0,0,0.0,3.914,34.066,0.067,3.871,31.01,0.0,4.572,29.763,0.0,3.103,34.071,0.0
|
| 14 |
+
2026-05-19 10:30:42,0.01,20283392.0,0.003,5.867,1.0,120.401,131.032,28.205,117.368,0,0.0,18591744.0,0.0,0,0,2.358,2.069,0,0,0,0.008,16777216.0,0.0,30.8,1.0,41.21,32.512,0.334,3.416,0,0.026,87306240.0,0.085,6.796,1.0,19.388,19.467,2.914,40.214,0,0.01,51912704.0,0.007,17.847,1.0,29.061,28.984,2.062,4.72,0,0.0,32325632.0,0.0,0,0,2.622,2.219,0,0,0,0.001,13701120.0,0.0,3.088,1.0,4.386,2.982,0.306,2.814,0,0.001,89538560.0,0.0,0,0,2.336,1.92,0,0,0,0.011,87166976.0,0.003,4.574,1.0,19.035,20.442,3.657,9.05,0,0.017,175181824.0,0.018,2.262,1.0,6.816,4.445,3.343,7.241,0.0,0.004,13545472.0,0.0,0,0,10.588,7.641,0,0,0.0,3.914,34.066,0.067,4.392,31.037,0.0,4.572,29.763,0.0,3.1,33.684,0.0
|
| 15 |
+
2026-05-19 10:30:47,0.022,20697088.0,0.003,9.274,1.0,133.421,145.201,17.804,76.141,0,0.0,18771968.0,0.0,0,0,2.393,1.984,0,0,0,0.009,16777216.0,0.0,52.93,1.0,51.682,40.796,0.283,1.615,0,0.026,87306240.0,0.085,7.022,1.0,25.972,26.491,2.951,21.531,0,0.026,55283712.0,0.007,19.605,1.0,35.776,35.88,2.378,4.644,0,0.0,32325632.0,0.0,0,0,1.427,1.013,0,0,0,0.001,13701120.0,0.0,3.372,1.0,10.917,6.532,0.314,3.092,0,0.001,89538560.0,0.0,0,0,2.336,1.92,0,0,0,0.015,87162880.0,0.002,4.667,1.0,19.035,20.442,3.423,7.816,0,0.017,175181824.0,0.018,2.479,1.0,6.816,4.445,3.217,4.991,0.0,0.005,13545472.0,0.0,0,0,18.804,13.748,0,0,0.0,3.914,34.066,0.067,4.392,31.037,0.0,4.974,29.775,0.0,3.115,33.684,0.0
|
| 16 |
+
2026-05-19 10:30:52,0.022,20697088.0,0.003,10.187,1.0,153.929,163.884,17.786,76.091,0,0.0,18771968.0,0.0,0,0,2.393,1.984,0,0,0,0.007,16777216.0,0.0,58.061,1.0,75.16,60.757,0.285,1.772,0,0.024,88154112.0,0.067,10.487,1.0,32.309,32.462,2.726,6.826,0,0.026,55283712.0,0.007,21.089,1.0,49.593,49.727,2.376,4.646,0,0.0,32325632.0,0.0,0,0,1.614,1.145,0,0,0,0.001,13701120.0,0.0,4.631,1.0,10.917,6.532,0.304,2.802,0,0.001,89538560.0,0.0,0,0,2.615,2.105,0,0,0,0.015,87162880.0,0.002,7.443,1.0,22.501,23.99,3.302,6.586,0,0.017,175181824.0,0.018,2.6,1.0,9.919,6.118,3.215,4.987,0.0,0.004,13545472.0,0.0,0,0,18.804,13.748,0,0,0.0,3.929,34.045,0.0,4.392,31.037,0.0,5.447,29.775,0.0,3.115,33.684,0.0
|
| 17 |
+
2026-05-19 10:30:57,0.029,20697088.0,0.003,10.956,1.0,193.795,210.989,17.612,75.581,0,0.0,18771968.0,0.0,0,0,2.156,1.742,0,0,0,0.014,16834560.0,0.0,61.578,1.0,75.16,60.757,0.287,1.87,0,0.027,88154112.0,0.076,11.485,1.0,32.309,32.462,2.695,4.993,0,0.026,55283712.0,0.007,30.937,1.0,68.261,65.658,1.938,4.552,0,0.0,32448512.0,0.0,0,0,1.801,1.278,0,0,0,0.001,13701120.0,0.0,5.105,1.0,10.917,6.532,0.302,2.695,0,0.001,89538560.0,0.0,0,0,2.615,2.105,0,0,0,0.015,87162880.0,0.002,8.143,1.0,24.923,26.614,3.304,6.596,0,0.024,176574464.0,0.018,3.414,1.0,9.919,6.118,3.18,4.924,0.0,0.005,13410304.0,0.0,0,0,25.695,18.812,0,0,0.0,3.929,34.045,0.0,4.865,31.021,0.0,5.447,29.775,0.0,3.14,33.716,0.0
|
| 18 |
+
2026-05-19 10:31:02,0.035,20848640.0,0.002,13.911,1.0,193.795,210.989,16.734,54.208,0,0.0,8732672.0,0.0,0,0,2.675,2.17,0,0,0,0.015,16834560.0,0.0,81.859,1.0,77.331,63.705,0.275,0.494,0,0.027,88154112.0,0.076,11.978,1.0,45.279,45.592,2.684,4.893,0,0.028,55283712.0,0.009,34.009,1.0,71.158,71.513,2.027,4.538,0,0.0,32448512.0,0.0,0,0,1.806,1.281,0,0,0,0.002,14778368.0,0.0,5.579,1.0,13.234,7.725,0.307,2.886,0,0.001,89538560.0,0.0,0,0,2.615,2.105,0,0,0,0.021,87199744.0,0.002,8.4,1.0,28.136,30.456,3.237,5.362,0,0.024,176574464.0,0.018,3.746,1.0,9.919,6.118,3.138,4.849,0.0,0.005,13410304.0,0.0,0,0,25.695,18.812,0,0,0.0,3.929,34.045,0.0,4.865,31.021,0.0,5.963,29.818,0.0,3.085,33.716,0.0
|
| 19 |
+
2026-05-19 10:31:07,0.038,20848640.0,0.003,15.281,1.0,238.763,259.777,16.71,54.031,0,0.0,8790016.0,0.0,0,0,2.675,2.17,0,0,0,0.018,16834560.0,0.0,89.803,1.0,90.308,74.831,0.275,0.496,0,0.022,88154112.0,0.063,15.524,1.0,45.279,45.592,2.559,4.832,0,0.038,58060800.0,0.009,36.866,1.0,82.015,82.135,2.024,4.539,0,0.0,32448512.0,0.0,0,0,2.359,1.79,0,0,0,0.002,14778368.0,0.0,6.563,1.0,14.714,8.541,0.303,2.752,0,0.0,89538560.0,0.0,0,0,2.282,1.821,0,0,0,0.021,87199744.0,0.002,11.048,1.0,34.832,37.703,3.194,4.95,0,0.024,176574464.0,0.018,3.978,1.0,11.734,6.922,3.136,4.845,0.0,0.005,13410304.0,0.0,0,0,25.695,18.812,0,0,0.0,3.693,34.062,0.067,4.865,31.021,0.0,6.288,29.818,0.0,3.085,33.716,0.0
|
| 20 |
+
2026-05-19 10:31:12,0.043,20848640.0,0.0,16.444,1.0,257.435,279.889,16.521,52.174,0,0.0,8790016.0,0.0,0,0,2.675,2.17,0,0,0,0.021,17338368.0,0.0,95.333,1.0,100.97,83.666,0.276,0.497,0,0.023,88154112.0,0.07,17.003,1.0,47.172,47.348,2.536,4.798,0,0.038,58060800.0,0.009,45.007,1.0,82.015,82.135,1.653,4.451,0,0.0,32448512.0,0.0,0,0,2.359,1.79,0,0,0,0.002,14778368.0,0.0,7.089,1.0,16.994,9.665,0.301,2.658,0,0.001,89538560.0,0.0,0,0,2.282,1.821,0,0,0,0.021,87199744.0,0.002,12.088,1.0,34.832,37.703,3.196,4.952,0,0.024,176574464.0,0.018,4.823,1.0,8.988,5.302,3.116,4.809,0.0,0.005,13414400.0,0.0,0,0,25.787,18.819,0,0,0.0,3.693,34.062,0.067,5.154,31.0,0.0,6.288,29.818,0.0,3.019,33.705,0.0
|
| 21 |
+
2026-05-19 10:31:17,0.046,20963328.0,0.0,16.822,1.0,285.698,311.396,16.231,43.637,0,0.0,8790016.0,0.0,0,0,2.272,1.734,0,0,0,0.021,17338368.0,0.0,105.956,1.0,127.942,106.016,0.269,0.485,0,0.023,91041792.0,0.052,17.756,1.0,47.935,47.576,2.523,4.752,0,0.04,60051456.0,0.003,48.311,1.0,79.76,79.679,1.541,4.402,0,0.0,32702464.0,0.0,0,0,2.487,1.924,0,0,0,0.002,14823424.0,0.0,7.089,1.0,16.994,9.665,0.297,2.476,0,0.001,89538560.0,0.0,0,0,2.001,1.633,0,0,0,0.023,87199744.0,0.0,12.489,1.0,28.721,31.088,3.164,4.895,0,0.015,177655808.0,0.0,4.911,1.0,8.01,4.725,3.062,4.712,0.0,0.005,13414400.0,0.0,0,0,32.365,23.719,0,0,0.0,3.693,34.062,0.067,5.154,31.0,0.0,6.278,29.775,0.0,2.999,33.705,0.0
|
| 22 |
+
2026-05-19 10:31:22,0.046,20963328.0,0.0,16.822,1.0,285.698,311.396,15.668,32.747,0,0.0,8790016.0,0.0,0,0,2.676,2.132,0,0,0,0.022,17338368.0,0.0,105.956,1.0,128.547,107.064,0.263,0.473,0,0.013,91041792.0,0.0,16.778,1.0,47.935,47.576,2.383,4.539,0,0.04,60051456.0,0.003,48.311,1.0,96.499,96.4,1.389,4.301,0,0.0,32702464.0,0.0,0,0,2.059,1.593,0,0,0,0.003,14823424.0,0.0,7.4,1.0,16.978,9.673,0.291,2.148,0,0.001,89538560.0,0.0,0,0,2.062,1.654,0,0,0,0.023,87232512.0,0.0,12.089,1.0,36.311,38.938,3.026,4.646,0,0.019,177655808.0,0.0,4.911,1.0,7.341,4.373,3.009,4.617,0.0,0.005,13414400.0,0.0,0,0,32.365,23.719,0,0,0.0,3.821,34.058,0.0,5.154,31.0,0.0,6.35,29.775,0.0,2.999,33.705,0.0
|
| 23 |
+
2026-05-19 10:31:27,0.047,20963328.0,0.0,16.822,1.0,241.084,262.122,15.37,24.951,0,0.0,8908800.0,0.0,0,0,2.676,2.132,0,0,0,0.023,17137664.0,0.0,105.956,1.0,128.547,107.064,0.261,0.469,0,0.013,91041792.0,0.0,16.778,1.0,48.917,48.652,2.38,4.538,0,0.033,61771776.0,0.002,57.0,1.0,101.69,101.771,1.008,4.223,0,0.0,32960512.0,0.0,0,0,2.586,2.009,0,0,0,0.003,14823424.0,0.0,7.4,1.0,17.2,9.874,0.291,2.148,0,0.001,89538560.0,0.0,0,0,2.062,1.654,0,0,0,0.023,87232512.0,0.0,12.089,1.0,36.311,38.938,3.024,4.643,0,0.019,177655808.0,0.0,4.889,1.0,12.665,7.364,3.005,4.608,0.0,0.005,13553664.0,0.0,0,0,27.431,20.078,0,0,0.0,3.821,34.058,0.0,5.204,31.072,0.0,6.35,29.775,0.0,3.042,33.768,0.0
|
| 24 |
+
2026-05-19 10:31:32,0.048,21118976.0,0.0,17.222,1.0,304.016,332.664,15.316,26.93,0,0.0,8908800.0,0.0,0,0,2.585,2.039,0,0,0,0.023,17137664.0,0.0,110.667,1.0,128.547,107.064,0.26,0.467,0,0.013,92856320.0,0.0,16.778,1.0,48.917,48.652,2.365,4.476,0,0.04,61771776.0,0.003,57.0,1.0,101.69,101.771,0.467,4.16,0,0.0,32960512.0,0.0,0,0,2.637,2.11,0,0,0,0.003,14823424.0,0.0,7.4,1.0,17.2,9.874,0.294,2.327,0,0.001,89538560.0,0.0,0,0,2.527,1.969,0,0,0,0.023,87232512.0,0.0,12.089,1.0,35.842,38.657,3.009,4.617,0,0.018,177815552.0,0.0,4.889,1.0,12.665,7.364,3.0,4.6,0.0,0.005,13553664.0,0.0,0,0,33.389,24.269,0,0,0.0,3.821,34.058,0.0,5.204,31.072,0.0,6.453,29.889,0.0,3.058,33.768,0.0
|
| 25 |
+
2026-05-19 10:31:37,0.048,21118976.0,0.0,17.222,1.0,304.016,332.664,15.316,26.93,0,0.0,9003008.0,0.0,0,0,2.601,2.126,0,0,0,0.024,17137664.0,0.0,110.667,1.0,132.333,110.704,0.26,0.468,0,0.013,92856320.0,0.0,17.267,1.0,49.973,49.831,2.348,4.472,0,0.04,61771776.0,0.003,57.0,1.0,107.335,107.362,0.457,4.138,0,0.0,32960512.0,0.0,0,0,2.637,2.11,0,0,0,0.002,14823424.0,0.0,7.356,1.0,17.2,9.874,0.294,2.302,0,0.001,89538560.0,0.0,0,0,2.316,1.788,0,0,0,0.023,87273472.0,0.0,12.289,1.0,36.177,39.269,3.009,4.616,0,0.018,177815552.0,0.0,4.889,1.0,12.883,7.406,3.0,4.6,0.0,0.005,13553664.0,0.0,0,0,33.389,24.269,0,0,0.0,3.778,33.987,0.0,5.204,31.072,0.0,6.475,29.889,0.0,3.058,33.768,0.0
|
| 26 |
+
2026-05-19 10:31:42,0.048,21118976.0,0.0,17.222,1.0,313.413,343.657,15.316,26.93,0,0.0,9003008.0,0.0,0,0,2.984,2.345,0,0,0,0.023,17227776.0,0.0,110.667,1.0,132.333,110.704,0.26,0.468,0,0.013,92856320.0,0.0,17.267,1.0,49.973,49.831,2.348,4.472,0,0.033,61771776.0,0.002,62.096,1.0,107.335,107.362,0.418,4.016,0,0.0,33095680.0,0.0,0,0,2.726,2.28,0,0,0,0.002,14823424.0,0.0,7.356,1.0,17.26,9.847,0.294,2.302,0,0.001,89542656.0,0.0,0,0,2.316,1.788,0,0,0,0.023,87273472.0,0.0,12.289,1.0,36.177,39.269,3.009,4.616,0,0.019,177815552.0,0.001,5.133,1.0,13.469,7.947,3.0,4.6,0.0,0.005,13426688.0,0.0,0,0,33.389,24.269,0,0,0.0,3.778,33.987,0.0,5.608,31.196,0.0,6.475,29.889,0.0,3.035,33.7,0.0
|
| 27 |
+
2026-05-19 10:31:47,0.049,21118976.0,0.0,16.422,1.0,313.413,343.657,15.696,34.472,0,0.0,9003008.0,0.0,0,0,2.622,2.027,0,0,0,0.023,17227776.0,0.0,109.956,1.0,132.333,110.704,0.26,0.468,0,0.013,92856320.0,0.0,17.267,1.0,49.973,49.831,2.357,4.477,0,0.03,61546496.0,0.009,62.096,1.0,83.669,83.691,0.416,3.997,0,0.0,33095680.0,0.0,0,0,2.831,2.39,0,0,0,0.003,14893056.0,0.0,7.356,1.0,17.168,9.747,0.29,2.074,0,0.001,89542656.0,0.0,0,0,2.316,1.788,0,0,0,0.023,87273472.0,0.0,12.289,1.0,36.177,39.269,3.013,4.623,0,0.018,178323456.0,0.007,5.133,1.0,13.469,7.947,3.0,4.6,0.0,0.005,13426688.0,0.0,0,0,34.03,24.663,0,0,0.0,3.778,33.987,0.0,5.608,31.196,0.0,6.508,29.784,0.0,3.16,33.7,0.0
|
| 28 |
+
2026-05-19 10:31:52,0.039,29868032.0,0.0,16.422,1.0,353.883,384.908,15.696,34.472,0,0.0,9043968.0,0.0,0,0,3.044,2.353,0,0,0,0.023,17256448.0,0.0,109.956,1.0,126.724,105.528,0.26,0.468,0,0.007,92856320.0,0.0,16.533,1.0,32.45,32.35,2.408,4.487,0,0.036,61546496.0,0.01,62.096,1.0,77.828,78.084,0.406,3.958,0,0.0,33230848.0,0.0,0,0,2.831,2.39,0,0,0,0.003,14893056.0,0.0,6.978,1.0,17.168,9.747,0.291,2.16,0,0.001,89542656.0,0.0,0,0,3.761,2.986,0,0,0,0.023,87273472.0,0.0,11.644,1.0,37.143,39.189,3.013,4.624,0,0.018,178323456.0,0.007,5.133,1.0,9.226,5.678,3.0,4.6,0.0,0.005,13438976.0,0.0,0,0,34.03,24.663,0,0,0.0,4.131,33.953,0.2,5.608,31.196,0.0,6.497,29.784,0.0,3.16,33.7,0.0
|
| 29 |
+
2026-05-19 10:31:57,0.035,29868032.0,0.0,16.422,1.0,308.132,334.908,15.696,34.472,0,0.0,9043968.0,0.0,0,0,3.724,2.829,0,0,0,0.022,17256448.0,0.0,109.956,1.0,126.724,105.528,0.26,0.468,0,0.009,92856320.0,0.0,16.533,1.0,50.594,49.353,2.408,4.487,0,0.031,61546496.0,0.009,65.844,1.0,111.314,110.663,0.393,3.906,0,0.0,33230848.0,0.0,0,0,2.831,2.39,0,0,0,0.003,14893056.0,0.0,6.978,1.0,18.313,10.186,0.291,2.16,0,0.001,89542656.0,0.0,0,0,3.761,2.986,0,0,0,0.018,87273472.0,0.0,11.644,1.0,37.143,39.189,3.013,4.624,0,0.017,178323456.0,0.011,4.578,1.0,10.441,6.425,3.0,4.6,0.0,0.005,13438976.0,0.0,0,0,34.17,24.51,0,0,0.0,4.131,33.953,0.2,6.25,31.416,0.0,6.497,29.784,0.0,3.267,33.827,0.0
|
| 30 |
+
2026-05-19 10:32:02,0.032,29868032.0,0.0,13.586,1.0,273.175,297.155,16.0,37.083,0,0.0,9043968.0,0.0,0,0,3.527,2.591,0,0,0,0.022,17256448.0,0.0,106.578,1.0,126.724,105.528,0.261,0.469,0,0.014,95080448.0,0.0,16.533,1.0,50.594,49.353,2.333,4.47,0,0.034,61702144.0,0.007,65.844,1.0,111.314,110.663,0.373,3.792,0,0.0,33230848.0,0.0,0,0,4.059,2.764,0,0,0,0.002,14925824.0,0.0,6.978,1.0,18.313,10.186,0.292,2.229,0,0.001,89542656.0,0.0,0,0,3.232,2.589,0,0,0,0.016,87273472.0,0.0,11.644,1.0,36.87,38.832,3.01,4.618,0,0.017,179060736.0,0.008,4.578,1.0,11.216,6.993,3.0,4.6,0.0,0.005,13438976.0,0.0,0,0,34.965,24.713,0,0,0.0,4.131,33.953,0.2,6.25,31.416,0.0,6.34,29.418,0.0,3.236,33.827,0.0
|
| 31 |
+
2026-05-19 10:32:07,0.047,30109696.0,0.001,18.908,1.0,247.346,268.707,16.028,38.558,0,0.0,9043968.0,0.0,0,0,4.196,3.082,0,0,0,0.022,17199104.0,0.0,106.578,1.0,127.791,105.74,0.261,0.471,0,0.014,95080448.0,0.0,17.133,1.0,50.035,48.735,2.425,4.49,0,0.034,61702144.0,0.009,65.844,1.0,112.317,110.969,0.374,3.798,0,0.0,33357824.0,0.0,0,0,4.76,3.093,0,0,0,0.002,14925824.0,0.0,6.822,1.0,18.935,10.412,0.331,3.372,0,0.001,89542656.0,0.0,0,0,3.855,3.042,0,0,0,0.022,87322624.0,0.0,11.889,1.0,36.87,38.832,3.012,4.622,0,0.017,179060736.0,0.008,4.578,1.0,13.964,8.706,3.012,4.621,0.0,0.005,13438976.0,0.0,0,0,34.965,24.713,0,0,0.0,4.133,33.977,2.533,6.25,31.416,0.0,5.992,29.418,0.0,3.236,33.827,0.0
|
| 32 |
+
2026-05-19 10:32:12,0.047,30109696.0,0.001,19.036,1.0,268.87,289.312,16.037,38.77,0,0.0,9269248.0,0.0,0,0,3.57,2.622,0,0,0,0.022,17199104.0,0.0,106.578,1.0,127.791,105.74,0.262,0.471,0,0.014,95080448.0,0.0,17.133,1.0,49.678,47.923,2.428,4.49,0,0.034,61702144.0,0.009,64.911,1.0,112.317,110.969,0.365,3.733,0,0.0,33357824.0,0.0,0,0,4.76,3.093,0,0,0,0.002,14925824.0,0.0,6.822,1.0,18.658,10.261,0.339,3.486,0,0.0,89542656.0,0.0,0,0,3.855,3.042,0,0,0,0.022,87322624.0,0.0,11.889,1.0,35.762,38.269,3.012,4.622,0,0.017,179060736.0,0.008,4.556,1.0,13.964,8.706,3.023,4.642,0.0,0.005,13438976.0,0.0,0,0,34.965,24.713,0,0,0.0,4.133,33.977,2.533,6.826,31.452,0.0,5.992,29.418,0.0,3.128,33.832,0.0
|
| 33 |
+
2026-05-19 10:32:17,0.029,30679040.0,0.001,18.505,1.0,316.416,340.648,16.413,40.437,0,0.0,9269248.0,0.0,0,0,3.22,2.365,0,0,0,0.022,17199104.0,0.0,106.622,1.0,127.791,105.74,0.263,0.473,0,0.014,47656960.0,0.0,17.133,1.0,49.678,47.923,2.42,4.49,0,0.034,62025728.0,0.009,64.911,1.0,112.317,110.969,0.363,3.718,0,0.0,33357824.0,0.0,0,0,4.186,2.724,0,0,0,0.002,15400960.0,0.0,6.822,1.0,18.658,10.261,0.342,3.518,0,0.0,89542656.0,0.0,0,0,3.336,2.683,0,0,0,0.022,87322624.0,0.0,11.889,1.0,35.762,38.269,3.017,4.63,0,0.016,179105792.0,0.01,4.556,1.0,13.312,8.091,3.025,4.646,0.0,0.005,13438976.0,0.0,0,0,35.08,24.629,0,0,0.0,4.133,33.977,2.533,6.826,31.452,0.0,5.586,29.451,0.0,3.115,33.832,0.0
|
| 34 |
+
2026-05-19 10:32:22,0.033,30679040.0,0.001,18.258,1.0,321.256,346.205,16.643,40.537,0,0.0,9269248.0,0.0,0,0,3.718,2.837,0,0,0,0.022,17231872.0,0.0,106.622,1.0,127.979,105.607,0.262,0.471,0,0.014,47616000.0,0.0,16.533,1.0,42.561,41.057,2.43,4.492,0,0.034,62025728.0,0.009,64.911,1.0,115.948,114.725,0.355,3.652,0,0.0,33357824.0,0.0,0,0,4.186,2.724,0,0,0,0.002,15400960.0,0.0,6.822,1.0,16.559,8.971,0.351,3.622,0,0.001,89542656.0,0.0,0,0,3.336,2.683,0,0,0,0.022,87355392.0,0.0,11.556,1.0,36.219,38.425,3.016,4.629,0,0.016,92495872.0,0.01,4.556,1.0,13.312,8.091,3.02,4.637,0.0,0.005,13426688.0,0.0,0,0,33.595,23.699,0,0,0.0,4.21,33.888,0.533,6.826,31.452,0.0,5.326,29.451,0.0,3.115,33.832,0.0
|
| 35 |
+
2026-05-19 10:32:27,0.038,30679040.0,0.001,18.411,1.0,319.192,343.262,16.638,40.525,0,0.0,6017024.0,0.0,0,0,3.718,2.837,0,0,0,0.022,17231872.0,0.0,106.622,1.0,127.017,105.2,0.262,0.472,0,0.014,47616000.0,0.0,16.533,1.0,40.018,38.246,2.432,4.492,0,0.033,62025728.0,0.0,65.111,1.0,119.797,118.707,0.348,3.584,0,0.0,33357824.0,0.0,0,0,4.655,2.725,0,0,0,0.002,15368192.0,0.0,6.822,1.0,18.403,9.893,0.361,3.711,0,0.001,89542656.0,0.0,0,0,3.336,2.683,0,0,0,0.022,87355392.0,0.0,11.556,1.0,36.219,38.425,3.015,4.627,0,0.016,92495872.0,0.01,4.444,1.0,12.591,7.59,3.022,4.639,0.0,0.005,13426688.0,0.0,0,0,33.595,23.699,0,0,0.0,4.21,33.888,0.533,7.057,31.449,0.0,5.326,29.451,0.0,3.197,33.774,0.0
|
| 36 |
+
2026-05-19 10:32:32,0.034,30679040.0,0.001,13.521,1.0,255.415,272.651,16.608,40.609,0,0.0,6017024.0,0.0,0,0,3.51,2.742,0,0,0,0.022,17231872.0,0.0,103.578,1.0,127.017,105.2,0.262,0.472,0,0.008,47616000.0,0.0,16.533,1.0,48.489,47.094,2.302,4.463,0,0.026,29687808.0,0.0,65.111,1.0,121.796,120.532,0.316,3.078,0,0.0,15368192.0,0.0,0,0,4.655,2.725,0,0,0,0.002,15368192.0,0.0,6.822,1.0,18.403,9.893,0.377,3.827,0,0.001,44675072.0,0.0,0,0,1.911,1.482,0,0,0,0.022,87355392.0,0.0,11.556,1.0,28.266,30.713,3.01,4.618,0,0.013,92495872.0,0.004,4.444,1.0,12.591,7.59,3.027,4.649,0.0,0.005,6672384.0,0.0,0,0,33.561,23.49,0,0,0.0,4.21,33.888,0.533,7.057,31.449,0.0,5.019,29.464,0.0,3.154,33.774,0.0
|
| 37 |
+
2026-05-19 10:32:37,0.048,30879744.0,0.002,15.148,1.0,221.594,236.547,16.858,40.738,0,0.0,6017024.0,0.0,0,0,3.187,2.575,0,0,0,0.022,17248256.0,0.0,103.578,1.0,128.803,106.9,0.262,0.472,0,0.01,47603712.0,0.0,16.911,1.0,46.344,45.643,2.293,4.461,0,0.033,30937088.0,0.001,65.111,1.0,121.796,120.532,0.317,3.103,0,0.0,15368192.0,0.0,0,0,4.655,2.725,0,0,0,0.002,7745536.0,0.0,7.222,1.0,18.403,9.893,0.386,3.876,0,0.001,44675072.0,0.0,0,0,2.276,1.765,0,0,0,0.015,87556096.0,0.0,11.911,1.0,35.833,38.956,3.007,4.612,0,0.015,92639232.0,0.003,4.444,1.0,12.591,7.59,3.024,4.643,0.0,0.004,6672384.0,0.0,0,0,33.362,23.463,0,0,0.0,3.817,33.905,0.0,7.057,31.449,0.0,4.701,29.464,0.0,3.154,33.774,0.0
|
| 38 |
+
2026-05-19 10:32:42,0.052,19849216.0,0.003,16.589,1.0,320.96,345.269,16.859,40.702,0,0.0,6017024.0,0.0,0,0,2.309,2.008,0,0,0,0.023,17248256.0,0.0,103.578,1.0,128.803,106.9,0.262,0.472,0,0.013,47603712.0,0.0,16.911,1.0,46.344,45.643,2.333,4.469,0,0.033,30937088.0,0.001,68.711,1.0,121.796,120.532,0.315,3.06,0,0.0,15368192.0,0.0,0,0,1.75,1.175,0,0,0,0.003,7589888.0,0.0,7.222,1.0,13.777,7.407,0.397,3.931,0,0.001,44675072.0,0.0,0,0,2.276,1.765,0,0,0,0.017,87556096.0,0.0,11.911,1.0,35.833,38.956,3.007,4.612,0,0.015,92639232.0,0.003,4.8,1.0,12.108,7.117,3.022,4.64,0.0,0.005,6684672.0,0.0,0,0,33.362,23.463,0,0,0.0,3.817,33.905,0.0,7.094,31.419,0.0,4.701,29.464,0.0,3.094,33.128,0.0
|
| 39 |
+
2026-05-19 10:32:47,0.053,19849216.0,0.003,17.289,1.0,325.106,351.639,16.953,40.526,0,0.0,5750784.0,0.0,0,0,2.309,2.008,0,0,0,0.023,8630272.0,0.0,112.578,1.0,133.724,111.252,0.262,0.471,0,0.013,47603712.0,0.0,16.911,1.0,48.375,47.684,2.362,4.472,0,0.035,32473088.0,0.001,68.711,1.0,122.563,121.478,0.316,3.085,0,0.0,15368192.0,0.0,0,0,2.62,1.953,0,0,0,0.002,7589888.0,0.0,7.222,1.0,16.984,9.417,0.405,3.955,0,0.0,44675072.0,0.0,0,0,2.276,1.765,0,0,0,0.019,87556096.0,0.0,11.911,1.0,35.833,38.956,3.004,4.607,0,0.013,92639232.0,0.003,4.8,1.0,12.108,7.117,3.022,4.64,0.0,0.005,6684672.0,0.0,0,0,31.743,22.601,0,0,0.0,3.817,33.905,0.0,7.094,31.419,0.0,4.601,29.365,0.0,3.118,33.128,0.0
|
| 40 |
+
2026-05-19 10:32:52,0.045,19849216.0,0.002,16.778,1.0,322.869,351.02,17.091,40.171,0,0.0,5750784.0,0.0,0,0,2.404,2.032,0,0,0,0.023,8630272.0,0.0,112.578,1.0,133.972,111.821,0.261,0.47,0,0.013,47603712.0,0.0,16.556,1.0,48.375,47.684,2.334,4.467,0,0.035,32473088.0,0.001,68.711,1.0,122.563,121.478,0.313,3.013,0,0.0,15626240.0,0.0,0,0,2.62,1.953,0,0,0,0.003,7589888.0,0.0,7.4,1.0,16.984,9.417,0.392,3.897,0,0.001,44675072.0,0.0,0,0,2.782,2.177,0,0,0,0.023,43859968.0,0.0,11.889,1.0,31.025,33.359,3.002,4.603,0,0.011,92639232.0,0.003,4.8,1.0,12.108,7.117,3.009,4.617,0.0,0.005,6684672.0,0.0,0,0,32.297,23.087,0,0,0.0,3.768,33.918,0.4,7.094,31.419,0.0,4.612,29.365,0.0,3.118,33.128,0.0
|
| 41 |
+
2026-05-19 10:32:57,0.053,20099072.0,0.002,16.778,1.0,258.346,280.871,17.091,40.171,0,0.0,5750784.0,0.0,0,0,1.871,1.581,0,0,0,0.022,8650752.0,0.0,112.578,1.0,133.972,111.821,0.261,0.47,0,0.013,47611904.0,0.0,16.556,1.0,48.505,48.085,2.334,4.467,0,0.035,32473088.0,0.001,69.489,1.0,91.676,90.887,0.311,2.963,0,0.0,15626240.0,0.0,0,0,2.62,1.953,0,0,0,0.003,7618560.0,0.0,7.4,1.0,16.775,9.322,0.392,3.897,0,0.001,44675072.0,0.0,0,0,2.782,2.177,0,0,0,0.023,43859968.0,0.0,11.889,1.0,36.673,39.432,3.002,4.603,0,0.015,93097984.0,0.004,4.778,1.0,12.066,7.182,3.0,4.6,0.0,0.005,6696960.0,0.0,0,0,32.297,23.087,0,0,0.0,3.768,33.918,0.4,7.079,31.49,0.0,4.612,29.365,0.0,3.158,33.223,0.0
|
| 42 |
+
2026-05-19 10:33:02,0.053,20099072.0,0.002,16.778,1.0,231.44,251.62,17.091,40.171,0,0.0,5763072.0,0.0,0,0,1.991,1.655,0,0,0,0.022,8650752.0,0.0,111.2,1.0,131.495,109.542,0.261,0.47,0,0.013,47611904.0,0.0,16.556,1.0,48.505,48.085,2.333,4.467,0,0.029,32473088.0,0.001,69.489,1.0,81.3,80.6,0.311,2.963,0,0.0,15626240.0,0.0,0,0,2.951,2.179,0,0,0,0.003,7618560.0,0.0,7.4,1.0,16.814,9.404,0.392,3.897,0,0.001,44675072.0,0.0,0,0,3.003,2.357,0,0,0,0.023,43880448.0,0.0,11.889,1.0,36.673,39.432,3.002,4.603,0,0.015,93097984.0,0.002,4.778,1.0,12.098,7.32,3.0,4.6,0.0,0.005,6696960.0,0.0,0,0,33.127,23.716,0,0,0.0,3.768,33.918,0.4,7.079,31.49,0.0,4.629,29.355,0.0,3.111,33.223,0.0
|
| 43 |
+
2026-05-19 10:33:07,0.053,20099072.0,0.002,16.756,1.0,311.244,341.297,17.015,40.013,0,0.0,5763072.0,0.0,0,0,2.464,2.049,0,0,0,0.022,8654848.0,0.0,111.2,1.0,109.895,91.525,0.262,0.472,0,0.013,47611904.0,0.0,16.956,1.0,36.593,35.904,2.324,4.47,0,0.033,35176448.0,0.0,69.489,1.0,121.498,120.357,0.314,3.034,0,0.0,15626240.0,0.0,0,0,2.951,2.179,0,0,0,0.003,7618560.0,0.0,7.289,1.0,16.814,9.404,0.394,3.906,0,0.001,44675072.0,0.0,0,0,3.003,2.357,0,0,0,0.023,43880448.0,0.0,12.156,1.0,31.036,33.371,3.0,4.6,0,0.015,93097984.0,0.002,4.778,1.0,12.098,7.32,3.0,4.6,0.0,0.005,6696960.0,0.0,0,0,27.862,19.947,0,0,0.0,3.76,33.924,0.0,7.079,31.49,0.0,4.539,29.355,0.0,3.111,33.223,0.0
|
| 44 |
+
2026-05-19 10:33:12,0.053,20099072.0,0.002,16.756,1.0,311.137,342.057,17.015,40.013,0,0.0,5763072.0,0.0,0,0,2.464,2.049,0,0,0,0.022,8654848.0,0.0,111.2,1.0,134.979,112.416,0.262,0.472,0,0.013,48553984.0,0.0,16.956,1.0,40.711,39.944,2.323,4.47,0,0.033,35176448.0,0.0,68.622,1.0,121.498,120.357,0.315,3.065,0,0.0,15904768.0,0.0,0,0,2.951,2.179,0,0,0,0.003,7618560.0,0.0,7.289,1.0,16.948,9.7,0.394,3.906,0,0.001,44675072.0,0.0,0,0,2.708,2.181,0,0,0,0.023,43880448.0,0.0,12.156,1.0,35.448,38.258,3.0,4.6,0,0.015,93392896.0,0.005,4.622,1.0,12.098,7.32,2.996,4.599,0.0,0.005,6668288.0,0.0,0,0,25.101,17.97,0,0,0.0,3.76,33.924,0.0,6.994,31.594,0.0,4.539,29.355,0.0,3.021,33.264,0.0
|
| 45 |
+
2026-05-19 10:33:17,0.05,20234240.0,0.0,16.756,1.0,311.137,342.057,17.015,40.013,0,0.0,5775360.0,0.0,0,0,2.51,2.104,0,0,0,0.022,8654848.0,0.0,112.889,1.0,134.979,112.416,0.262,0.472,0,0.013,48553984.0,0.0,16.956,1.0,49.414,48.483,2.323,4.47,0,0.032,35176448.0,0.0,68.622,1.0,121.498,120.357,0.315,3.065,0,0.0,15904768.0,0.0,0,0,2.421,1.836,0,0,0,0.003,7618560.0,0.0,7.289,1.0,16.759,9.516,0.394,3.906,0,0.001,44675072.0,0.0,0,0,2.546,2.135,0,0,0,0.02,43880448.0,0.0,12.156,1.0,35.448,38.258,3.0,4.6,0,0.016,93392896.0,0.008,4.622,1.0,11.645,6.916,2.996,4.599,0.0,0.005,6668288.0,0.0,0,0,32.219,23.328,0,0,0.0,3.76,33.924,0.0,6.994,31.594,0.0,4.447,29.482,0.0,3.008,33.264,0.0
|
| 46 |
+
2026-05-19 10:33:22,0.05,20234240.0,0.0,16.422,1.0,299.317,331.321,16.952,39.866,0,0.0,5775360.0,0.0,0,0,2.546,2.072,0,0,0,0.018,8654848.0,0.0,112.889,1.0,109.189,90.937,0.263,0.473,0,0.012,48553984.0,0.0,16.267,1.0,49.414,48.483,2.345,4.475,0,0.032,37986304.0,0.0,68.622,1.0,119.612,118.792,0.315,3.072,0,0.0,16039936.0,0.0,0,0,2.421,1.836,0,0,0,0.003,7618560.0,0.0,7.244,1.0,16.759,9.516,0.392,3.897,0,0.0,44675072.0,0.0,0,0,2.617,2.163,0,0,0,0.023,43876352.0,0.0,11.8,1.0,34.315,36.902,3.002,4.603,0,0.016,93392896.0,0.008,4.622,1.0,11.645,6.916,2.995,4.599,0.0,0.005,6668288.0,0.0,0,0,31.997,23.306,0,0,0.0,3.953,33.971,0.0,6.994,31.594,0.0,4.508,29.482,0.0,3.008,33.264,0.0
|
| 47 |
+
2026-05-19 10:33:27,0.05,20234240.0,0.0,16.422,1.0,308.872,341.708,16.952,39.866,0,0.0,5775360.0,0.0,0,0,2.546,2.072,0,0,0,0.016,8654848.0,0.0,112.889,1.0,93.886,77.917,0.263,0.473,0,0.012,48553984.0,0.0,16.267,1.0,50.036,48.909,2.345,4.475,0,0.032,37986304.0,0.0,66.778,1.0,119.612,118.792,0.314,3.035,0,0.0,16039936.0,0.0,0,0,2.623,1.843,0,0,0,0.002,7618560.0,0.0,7.244,1.0,14.354,8.165,0.392,3.897,0,0.001,44679168.0,0.0,0,0,2.617,2.163,0,0,0,0.023,43876352.0,0.0,11.8,1.0,35.234,37.981,3.002,4.603,0,0.016,93392896.0,0.008,4.622,1.0,11.379,6.737,2.992,4.598,0.0,0.005,6668288.0,0.0,0,0,31.997,23.306,0,0,0.0,3.953,33.971,0.0,6.964,31.568,0.0,4.508,29.482,0.0,3.015,33.254,0.0
|
| 48 |
+
2026-05-19 10:33:32,0.052,20307968.0,0.001,16.422,1.0,308.872,341.708,16.952,39.866,0,0.0,5783552.0,0.0,0,0,2.172,1.768,0,0,0,0.022,8667136.0,0.0,109.067,1.0,128.796,107.276,0.263,0.473,0,0.013,48529408.0,0.0,16.267,1.0,48.641,47.351,2.345,4.475,0,0.032,37986304.0,0.0,66.778,1.0,117.527,116.608,0.314,3.035,0,0.0,16039936.0,0.0,0,0,2.623,1.843,0,0,0,0.002,7634944.0,0.0,7.244,1.0,17.044,9.695,0.392,3.897,0,0.001,44679168.0,0.0,0,0,2.421,2.007,0,0,0,0.023,43876352.0,0.0,11.8,1.0,35.234,37.981,3.002,4.603,0,0.016,93675520.0,0.007,4.622,1.0,12.127,7.167,2.991,4.598,0.0,0.004,6668288.0,0.0,0,0,32.896,24.34,0,0,0.0,3.953,33.971,0.0,6.964,31.568,0.0,4.525,29.342,0.0,2.979,33.254,0.0
|
| 49 |
+
2026-05-19 10:33:37,0.052,20307968.0,0.0,16.533,1.0,308.872,341.708,17.042,40.247,0,0.0,5783552.0,0.0,0,0,2.318,1.876,0,0,0,0.022,8667136.0,0.0,109.067,1.0,128.796,107.276,0.264,0.475,0,0.013,48529408.0,0.0,16.667,1.0,48.641,47.351,2.369,4.485,0,0.031,37986304.0,0.0,66.778,1.0,118.288,117.414,0.317,3.099,0,0.0,16039936.0,0.0,0,0,1.985,1.394,0,0,0,0.002,7634944.0,0.0,7.2,1.0,17.044,9.695,0.413,3.987,0,0.001,44679168.0,0.0,0,0,2.407,1.948,0,0,0,0.023,43872256.0,0.0,11.844,1.0,34.998,37.817,3.015,4.627,0,0.014,93675520.0,0.009,4.622,1.0,12.127,7.167,2.991,4.598,0.0,0.005,6676480.0,0.0,0,0,32.706,24.497,0,0,0.0,3.926,33.988,0.067,6.964,31.568,0.0,4.467,29.342,0.0,2.979,33.254,0.0
|
| 50 |
+
2026-05-19 10:33:42,0.052,20307968.0,0.0,16.533,1.0,233.803,259.338,17.042,40.247,0,0.0,5783552.0,0.0,0,0,2.318,1.876,0,0,0,0.022,8667136.0,0.0,109.067,1.0,128.796,107.276,0.264,0.475,0,0.013,48611328.0,0.0,16.667,1.0,50.534,49.334,2.369,4.485,0,0.031,37986304.0,0.0,69.756,1.0,118.288,117.414,0.322,3.216,0,0.0,15630336.0,0.0,0,0,1.766,1.241,0,0,0,0.002,7634944.0,0.0,7.2,1.0,17.079,9.687,0.413,3.987,0,0.001,44675072.0,0.0,0,0,2.407,1.948,0,0,0,0.023,43872256.0,0.0,11.844,1.0,34.998,37.817,3.015,4.627,0,0.017,100278272.0,0.019,4.689,1.0,12.208,7.075,2.989,4.598,0.0,0.005,6676480.0,0.0,0,0,33.96,25.47,0,0,0.0,3.926,33.988,0.067,7.161,31.572,0.0,4.467,29.342,0.0,2.972,33.321,0.0
|
| 51 |
+
2026-05-19 10:33:47,0.054,20369408.0,0.001,16.533,1.0,260.818,289.304,17.042,40.247,0,0.0,5787648.0,0.0,0,0,2.318,1.876,0,0,0,0.022,8671232.0,0.0,112.978,1.0,132.402,110.364,0.264,0.475,0,0.013,48611328.0,0.0,16.667,1.0,52.749,51.502,2.369,4.485,0,0.017,37986304.0,0.0,69.756,1.0,119.845,119.175,0.322,3.216,0,0.0,15630336.0,0.0,0,0,2.429,1.98,0,0,0,0.003,7659520.0,0.0,7.2,1.0,14.803,8.402,0.413,3.987,0,0.001,44675072.0,0.0,0,0,2.407,1.948,0,0,0,0.023,43872256.0,0.0,11.844,1.0,36.056,38.935,3.015,4.627,0,0.017,100278272.0,0.019,4.689,1.0,12.302,7.097,2.987,4.597,0.0,0.005,6684672.0,0.0,0,0,33.96,25.47,0,0,0.0,3.926,33.988,0.067,7.161,31.572,0.0,4.49,29.439,0.0,3.039,33.321,0.0
|
| 52 |
+
2026-05-19 10:33:52,0.054,20369408.0,0.001,17.622,1.0,324.181,359.587,17.567,41.616,0,0.0,5787648.0,0.0,0,0,2.342,1.906,0,0,0,0.022,8671232.0,0.0,112.978,1.0,132.402,110.364,0.265,0.476,0,0.013,48611328.0,0.0,17.4,1.0,52.749,51.502,2.349,4.481,0,0.037,35500032.0,0.011,69.756,1.0,122.73,122.007,0.331,3.378,0,0.0,15630336.0,0.0,0,0,2.429,1.98,0,0,0,0.003,7659520.0,0.0,7.556,1.0,17.166,9.744,0.405,3.953,0,0.001,44675072.0,0.0,0,0,2.29,1.816,0,0,0,0.025,43880448.0,0.0,12.4,1.0,37.692,40.74,3.026,4.646,0,0.017,100278272.0,0.019,4.689,1.0,12.302,7.097,2.996,4.614,0.0,0.005,6684672.0,0.0,0,0,25.44,19.314,0,0,0.0,3.869,33.988,0.0,7.161,31.572,0.0,4.569,29.439,0.0,3.039,33.321,0.0
|
| 53 |
+
2026-05-19 10:33:57,0.057,20369408.0,0.002,17.622,1.0,267.307,296.502,17.567,41.616,0,0.0,5787648.0,0.0,0,0,1.851,1.506,0,0,0,0.023,8671232.0,0.0,112.978,1.0,132.402,110.364,0.265,0.476,0,0.013,48513024.0,0.0,17.4,1.0,53.442,52.377,2.349,4.481,0,0.037,35500032.0,0.011,72.911,1.0,122.73,122.007,0.33,3.35,0,0.0,15630336.0,0.0,0,0,2.429,1.98,0,0,0,0.002,7659520.0,0.0,7.556,1.0,14.458,8.206,0.405,3.953,0,0.001,44675072.0,0.0,0,0,2.726,2.162,0,0,0,0.025,43880448.0,0.0,12.4,1.0,37.692,40.74,3.026,4.646,0,0.018,100278272.0,0.023,5.089,1.0,10.786,6.263,2.996,4.629,0.0,0.005,6684672.0,0.0,0,0,28.54,21.667,0,0,0.0,3.869,33.988,0.0,7.499,31.518,0.0,4.569,29.439,0.0,3.051,33.287,0.0
|
| 54 |
+
2026-05-19 10:34:02,0.047,20369408.0,0.002,17.622,1.0,240.292,266.536,17.567,41.616,0,0.0,5787648.0,0.0,0,0,1.479,1.138,0,0,0,0.023,8773632.0,0.0,116.8,1.0,93.292,77.767,0.264,0.476,0,0.013,48513024.0,0.0,17.4,1.0,53.442,52.377,2.349,4.481,0,0.037,35500032.0,0.011,72.911,1.0,122.73,122.007,0.33,3.35,0,0.0,15867904.0,0.0,0,0,2.739,2.298,0,0,0,0.003,7659520.0,0.0,7.556,1.0,17.556,10.029,0.405,3.953,0,0.0,44675072.0,0.0,0,0,2.726,2.162,0,0,0,0.022,43880448.0,0.0,12.4,1.0,37.692,40.74,3.026,4.646,0,0.014,100278272.0,0.017,5.089,1.0,13.132,7.625,2.995,4.628,0.0,0.005,6684672.0,0.0,0,0,31.639,24.02,0,0,0.0,3.869,33.988,0.0,7.499,31.518,0.0,4.606,29.311,0.0,2.965,33.287,0.0
|
benchmark/boutique/codedefect/31/tool_cache.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
benchmark/boutique/codedefect/32/code/adservice/src/main/java/hipstershop/AdService.java
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2018, Google LLC.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
package hipstershop;
|
| 18 |
+
|
| 19 |
+
import com.google.common.collect.ImmutableListMultimap;
|
| 20 |
+
import com.google.common.collect.ImmutableMap;
|
| 21 |
+
import com.google.common.collect.Iterables;
|
| 22 |
+
import hipstershop.Demo.Ad;
|
| 23 |
+
import hipstershop.Demo.AdRequest;
|
| 24 |
+
import hipstershop.Demo.AdResponse;
|
| 25 |
+
import io.grpc.Server;
|
| 26 |
+
import io.grpc.ServerBuilder;
|
| 27 |
+
import io.grpc.StatusRuntimeException;
|
| 28 |
+
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
|
| 29 |
+
import io.grpc.services.*;
|
| 30 |
+
import io.grpc.stub.StreamObserver;
|
| 31 |
+
import java.io.IOException;
|
| 32 |
+
import java.util.ArrayList;
|
| 33 |
+
import java.util.Collection;
|
| 34 |
+
import java.util.List;
|
| 35 |
+
import java.util.Random;
|
| 36 |
+
import java.util.concurrent.TimeUnit;
|
| 37 |
+
import org.apache.logging.log4j.Level;
|
| 38 |
+
import org.apache.logging.log4j.LogManager;
|
| 39 |
+
import org.apache.logging.log4j.Logger;
|
| 40 |
+
|
| 41 |
+
public final class AdService {
|
| 42 |
+
|
| 43 |
+
private static final Logger logger = LogManager.getLogger(AdService.class);
|
| 44 |
+
|
| 45 |
+
@SuppressWarnings("FieldCanBeLocal")
|
| 46 |
+
private static int MAX_ADS_TO_SERVE = 2;
|
| 47 |
+
|
| 48 |
+
private Server server;
|
| 49 |
+
private HealthStatusManager healthMgr;
|
| 50 |
+
|
| 51 |
+
private static final AdService service = new AdService();
|
| 52 |
+
|
| 53 |
+
private void start() throws IOException {
|
| 54 |
+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "9555"));
|
| 55 |
+
healthMgr = new HealthStatusManager();
|
| 56 |
+
|
| 57 |
+
server =
|
| 58 |
+
ServerBuilder.forPort(port)
|
| 59 |
+
.addService(new AdServiceImpl())
|
| 60 |
+
.addService(healthMgr.getHealthService())
|
| 61 |
+
.build()
|
| 62 |
+
.start();
|
| 63 |
+
logger.info("Ad Service started, listening on " + port);
|
| 64 |
+
Runtime.getRuntime()
|
| 65 |
+
.addShutdownHook(
|
| 66 |
+
new Thread(
|
| 67 |
+
() -> {
|
| 68 |
+
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
|
| 69 |
+
System.err.println(
|
| 70 |
+
"*** shutting down gRPC ads server since JVM is shutting down");
|
| 71 |
+
AdService.this.stop();
|
| 72 |
+
System.err.println("*** server shut down");
|
| 73 |
+
}));
|
| 74 |
+
healthMgr.setStatus("", ServingStatus.SERVING);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
private void stop() {
|
| 78 |
+
if (server != null) {
|
| 79 |
+
healthMgr.clearStatus("");
|
| 80 |
+
server.shutdown();
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
private static class AdServiceImpl extends hipstershop.AdServiceGrpc.AdServiceImplBase {
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Retrieves ads based on context provided in the request {@code AdRequest}.
|
| 88 |
+
*
|
| 89 |
+
* @param req the request containing context.
|
| 90 |
+
* @param responseObserver the stream observer which gets notified with the value of {@code
|
| 91 |
+
* AdResponse}
|
| 92 |
+
*/
|
| 93 |
+
@Override
|
| 94 |
+
public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {
|
| 95 |
+
AdService service = AdService.getInstance();
|
| 96 |
+
try {
|
| 97 |
+
List<Ad> allAds = new ArrayList<>();
|
| 98 |
+
logger.info("received ad request (context_words=" + req.getContextKeysList() + ")");
|
| 99 |
+
if (req.getContextKeysCount() > 0) {
|
| 100 |
+
for (int i = 0; i < req.getContextKeysCount(); i++) {
|
| 101 |
+
Collection<Ad> ads = service.getAdsByCategory(req.getContextKeys(i));
|
| 102 |
+
allAds.addAll(ads);
|
| 103 |
+
}
|
| 104 |
+
} else {
|
| 105 |
+
allAds = service.getRandomAds();
|
| 106 |
+
}
|
| 107 |
+
if (allAds.isEmpty()) {
|
| 108 |
+
// Serve random ads.
|
| 109 |
+
allAds = service.getRandomAds();
|
| 110 |
+
}
|
| 111 |
+
AdResponse reply = AdResponse.newBuilder().addAllAds(allAds).build();
|
| 112 |
+
responseObserver.onNext(reply);
|
| 113 |
+
responseObserver.onCompleted();
|
| 114 |
+
} catch (StatusRuntimeException e) {
|
| 115 |
+
logger.log(Level.WARN, "GetAds Failed with status {}", e.getStatus());
|
| 116 |
+
responseObserver.onError(e);
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
private static final ImmutableListMultimap<String, Ad> adsMap = createAdsMap();
|
| 122 |
+
|
| 123 |
+
private Collection<Ad> getAdsByCategory(String category) {
|
| 124 |
+
return adsMap.get(category);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
private static final Random random = new Random();
|
| 128 |
+
|
| 129 |
+
private List<Ad> getRandomAds() {
|
| 130 |
+
List<Ad> ads = new ArrayList<>(MAX_ADS_TO_SERVE);
|
| 131 |
+
Collection<Ad> allAds = adsMap.values();
|
| 132 |
+
for (int i = 0; i < MAX_ADS_TO_SERVE; i++) {
|
| 133 |
+
ads.add(Iterables.get(allAds, random.nextInt(allAds.size())));
|
| 134 |
+
}
|
| 135 |
+
return ads;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
private static AdService getInstance() {
|
| 139 |
+
return service;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
/** Await termination on the main thread since the grpc library uses daemon threads. */
|
| 143 |
+
private void blockUntilShutdown() throws InterruptedException {
|
| 144 |
+
if (server != null) {
|
| 145 |
+
server.awaitTermination();
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
private static ImmutableListMultimap<String, Ad> createAdsMap() {
|
| 150 |
+
Ad hairdryer =
|
| 151 |
+
Ad.newBuilder()
|
| 152 |
+
.setRedirectUrl("/product/2ZYFJ3GM2N")
|
| 153 |
+
.setText("Hairdryer for sale. 50% off.")
|
| 154 |
+
.build();
|
| 155 |
+
Ad tankTop =
|
| 156 |
+
Ad.newBuilder()
|
| 157 |
+
.setRedirectUrl("/product/66VCHSJNUP")
|
| 158 |
+
.setText("Tank top for sale. 20% off.")
|
| 159 |
+
.build();
|
| 160 |
+
Ad candleHolder =
|
| 161 |
+
Ad.newBuilder()
|
| 162 |
+
.setRedirectUrl("/product/0PUK6V6EV0")
|
| 163 |
+
.setText("Candle holder for sale. 30% off.")
|
| 164 |
+
.build();
|
| 165 |
+
Ad bambooGlassJar =
|
| 166 |
+
Ad.newBuilder()
|
| 167 |
+
.setRedirectUrl("/product/9SIQT8TOJO")
|
| 168 |
+
.setText("Bamboo glass jar for sale. 10% off.")
|
| 169 |
+
.build();
|
| 170 |
+
Ad watch =
|
| 171 |
+
Ad.newBuilder()
|
| 172 |
+
.setRedirectUrl("/product/1YMWWN1N4O")
|
| 173 |
+
.setText("Watch for sale. Buy one, get second kit for free")
|
| 174 |
+
.build();
|
| 175 |
+
Ad mug =
|
| 176 |
+
Ad.newBuilder()
|
| 177 |
+
.setRedirectUrl("/product/6E92ZMYYFZ")
|
| 178 |
+
.setText("Mug for sale. Buy two, get third one for free")
|
| 179 |
+
.build();
|
| 180 |
+
Ad loafers =
|
| 181 |
+
Ad.newBuilder()
|
| 182 |
+
.setRedirectUrl("/product/L9ECAV7KIM")
|
| 183 |
+
.setText("Loafers for sale. Buy one, get second one for free")
|
| 184 |
+
.build();
|
| 185 |
+
return ImmutableListMultimap.<String, Ad>builder()
|
| 186 |
+
.putAll("clothing", tankTop)
|
| 187 |
+
.putAll("accessories", watch)
|
| 188 |
+
.putAll("footwear", loafers)
|
| 189 |
+
.putAll("hair", hairdryer)
|
| 190 |
+
.putAll("decor", candleHolder)
|
| 191 |
+
.putAll("kitchen", bambooGlassJar, mug)
|
| 192 |
+
.build();
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
private static void initStats() {
|
| 196 |
+
if (System.getenv("DISABLE_STATS") != null) {
|
| 197 |
+
logger.info("Stats disabled.");
|
| 198 |
+
return;
|
| 199 |
+
}
|
| 200 |
+
logger.info("Stats enabled, but temporarily unavailable");
|
| 201 |
+
|
| 202 |
+
long sleepTime = 10; /* seconds */
|
| 203 |
+
int maxAttempts = 5;
|
| 204 |
+
|
| 205 |
+
// TODO(arbrown) Implement OpenTelemetry stats
|
| 206 |
+
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
private static void initTracing() {
|
| 210 |
+
if (System.getenv("DISABLE_TRACING") != null) {
|
| 211 |
+
logger.info("Tracing disabled.");
|
| 212 |
+
return;
|
| 213 |
+
}
|
| 214 |
+
logger.info("Tracing enabled but temporarily unavailable");
|
| 215 |
+
logger.info("See https://github.com/GoogleCloudPlatform/microservices-demo/issues/422 for more info.");
|
| 216 |
+
|
| 217 |
+
// TODO(arbrown) Implement OpenTelemetry tracing
|
| 218 |
+
|
| 219 |
+
logger.info("Tracing enabled - Stackdriver exporter initialized.");
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/** Main launches the server from the command line. */
|
| 223 |
+
public static void main(String[] args) throws IOException, InterruptedException {
|
| 224 |
+
|
| 225 |
+
new Thread(
|
| 226 |
+
() -> {
|
| 227 |
+
initStats();
|
| 228 |
+
initTracing();
|
| 229 |
+
})
|
| 230 |
+
.start();
|
| 231 |
+
|
| 232 |
+
// Start the RPC server. You shouldn't see any output from gRPC before this.
|
| 233 |
+
logger.info("AdService starting.");
|
| 234 |
+
final AdService service = AdService.getInstance();
|
| 235 |
+
service.start();
|
| 236 |
+
service.blockUntilShutdown();
|
| 237 |
+
}
|
| 238 |
+
}
|
benchmark/boutique/codedefect/32/code/adservice/src/main/java/hipstershop/AdServiceClient.java
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2018, Google LLC.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
package hipstershop;
|
| 18 |
+
|
| 19 |
+
import hipstershop.Demo.Ad;
|
| 20 |
+
import hipstershop.Demo.AdRequest;
|
| 21 |
+
import hipstershop.Demo.AdResponse;
|
| 22 |
+
import io.grpc.ManagedChannel;
|
| 23 |
+
import io.grpc.ManagedChannelBuilder;
|
| 24 |
+
import io.grpc.StatusRuntimeException;
|
| 25 |
+
import java.util.concurrent.TimeUnit;
|
| 26 |
+
import javax.annotation.Nullable;
|
| 27 |
+
import org.apache.logging.log4j.Level;
|
| 28 |
+
import org.apache.logging.log4j.LogManager;
|
| 29 |
+
import org.apache.logging.log4j.Logger;
|
| 30 |
+
|
| 31 |
+
/** A simple client that requests ads from the Ads Service. */
|
| 32 |
+
public class AdServiceClient {
|
| 33 |
+
|
| 34 |
+
private static final Logger logger = LogManager.getLogger(AdServiceClient.class);
|
| 35 |
+
|
| 36 |
+
private final ManagedChannel channel;
|
| 37 |
+
private final hipstershop.AdServiceGrpc.AdServiceBlockingStub blockingStub;
|
| 38 |
+
|
| 39 |
+
/** Construct client connecting to Ad Service at {@code host:port}. */
|
| 40 |
+
private AdServiceClient(String host, int port) {
|
| 41 |
+
this(
|
| 42 |
+
ManagedChannelBuilder.forAddress(host, port)
|
| 43 |
+
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
|
| 44 |
+
// needing certificates.
|
| 45 |
+
.usePlaintext()
|
| 46 |
+
.build());
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/** Construct client for accessing RouteGuide server using the existing channel. */
|
| 50 |
+
private AdServiceClient(ManagedChannel channel) {
|
| 51 |
+
this.channel = channel;
|
| 52 |
+
blockingStub = hipstershop.AdServiceGrpc.newBlockingStub(channel);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
private void shutdown() throws InterruptedException {
|
| 56 |
+
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/** Get Ads from Server. */
|
| 60 |
+
public void getAds(String contextKey) {
|
| 61 |
+
logger.info("Get Ads with context " + contextKey + " ...");
|
| 62 |
+
AdRequest request = AdRequest.newBuilder().addContextKeys(contextKey).build();
|
| 63 |
+
AdResponse response;
|
| 64 |
+
|
| 65 |
+
try {
|
| 66 |
+
response = blockingStub.getAds(request);
|
| 67 |
+
} catch (StatusRuntimeException e) {
|
| 68 |
+
logger.log(Level.WARN, "RPC failed: " + e.getStatus());
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
for (Ad ads : response.getAdsList()) {
|
| 72 |
+
logger.info("Ads: " + ads.getText());
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
private static int getPortOrDefaultFromArgs(String[] args) {
|
| 77 |
+
int portNumber = 9555;
|
| 78 |
+
if (2 < args.length) {
|
| 79 |
+
try {
|
| 80 |
+
portNumber = Integer.parseInt(args[2]);
|
| 81 |
+
} catch (NumberFormatException e) {
|
| 82 |
+
logger.warn(String.format("Port %s is invalid, use default port %d.", args[2], 9555));
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
return portNumber;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
private static String getStringOrDefaultFromArgs(
|
| 89 |
+
String[] args, int index, @Nullable String defaultString) {
|
| 90 |
+
String s = defaultString;
|
| 91 |
+
if (index < args.length) {
|
| 92 |
+
s = args[index];
|
| 93 |
+
}
|
| 94 |
+
return s;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Ads Service Client main. If provided, the first element of {@code args} is the context key to
|
| 99 |
+
* get the ads from the Ads Service
|
| 100 |
+
*/
|
| 101 |
+
public static void main(String[] args) throws InterruptedException {
|
| 102 |
+
// Add final keyword to pass checkStyle.
|
| 103 |
+
final String contextKeys = getStringOrDefaultFromArgs(args, 0, "camera");
|
| 104 |
+
final String host = getStringOrDefaultFromArgs(args, 1, "localhost");
|
| 105 |
+
final int serverPort = getPortOrDefaultFromArgs(args);
|
| 106 |
+
|
| 107 |
+
AdServiceClient client = new AdServiceClient(host, serverPort);
|
| 108 |
+
try {
|
| 109 |
+
client.getAds(contextKeys);
|
| 110 |
+
} finally {
|
| 111 |
+
client.shutdown();
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
logger.info("Exiting AdServiceClient...");
|
| 115 |
+
}
|
| 116 |
+
}
|
benchmark/boutique/codedefect/32/code/cartservice/src/Program.cs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using Microsoft.AspNetCore.Hosting;
|
| 16 |
+
using Microsoft.Extensions.Hosting;
|
| 17 |
+
using cartservice;
|
| 18 |
+
|
| 19 |
+
CreateHostBuilder(args).Build().Run();
|
| 20 |
+
|
| 21 |
+
static IHostBuilder CreateHostBuilder(string[] args) =>
|
| 22 |
+
Host.CreateDefaultBuilder(args)
|
| 23 |
+
.ConfigureWebHostDefaults(webBuilder =>
|
| 24 |
+
{
|
| 25 |
+
webBuilder.UseStartup<Startup>();
|
| 26 |
+
});
|
benchmark/boutique/codedefect/32/code/cartservice/src/Startup.cs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using Microsoft.AspNetCore.Builder;
|
| 3 |
+
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
| 4 |
+
using Microsoft.AspNetCore.Hosting;
|
| 5 |
+
using Microsoft.AspNetCore.Http;
|
| 6 |
+
using Microsoft.Extensions.Configuration;
|
| 7 |
+
using Microsoft.Extensions.DependencyInjection;
|
| 8 |
+
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
| 9 |
+
using Microsoft.Extensions.Hosting;
|
| 10 |
+
using cartservice.cartstore;
|
| 11 |
+
using cartservice.services;
|
| 12 |
+
using Microsoft.Extensions.Caching.StackExchangeRedis;
|
| 13 |
+
|
| 14 |
+
namespace cartservice
|
| 15 |
+
{
|
| 16 |
+
public class Startup
|
| 17 |
+
{
|
| 18 |
+
public Startup(IConfiguration configuration)
|
| 19 |
+
{
|
| 20 |
+
Configuration = configuration;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
public IConfiguration Configuration { get; }
|
| 24 |
+
|
| 25 |
+
// This method gets called by the runtime. Use this method to add services to the container.
|
| 26 |
+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
| 27 |
+
public void ConfigureServices(IServiceCollection services)
|
| 28 |
+
{
|
| 29 |
+
string redisAddress = Configuration["REDIS_ADDR"];
|
| 30 |
+
string spannerProjectId = Configuration["SPANNER_PROJECT"];
|
| 31 |
+
string spannerConnectionString = Configuration["SPANNER_CONNECTION_STRING"];
|
| 32 |
+
string alloyDBConnectionString = Configuration["ALLOYDB_PRIMARY_IP"];
|
| 33 |
+
|
| 34 |
+
if (!string.IsNullOrEmpty(redisAddress))
|
| 35 |
+
{
|
| 36 |
+
services.AddStackExchangeRedisCache(options =>
|
| 37 |
+
{
|
| 38 |
+
options.Configuration = redisAddress;
|
| 39 |
+
});
|
| 40 |
+
services.AddSingleton<ICartStore, RedisCartStore>();
|
| 41 |
+
}
|
| 42 |
+
else if (!string.IsNullOrEmpty(spannerProjectId) || !string.IsNullOrEmpty(spannerConnectionString))
|
| 43 |
+
{
|
| 44 |
+
services.AddSingleton<ICartStore, SpannerCartStore>();
|
| 45 |
+
}
|
| 46 |
+
else if (!string.IsNullOrEmpty(alloyDBConnectionString))
|
| 47 |
+
{
|
| 48 |
+
Console.WriteLine("Creating AlloyDB cart store");
|
| 49 |
+
services.AddSingleton<ICartStore, AlloyDBCartStore>();
|
| 50 |
+
}
|
| 51 |
+
else
|
| 52 |
+
{
|
| 53 |
+
Console.WriteLine("Redis cache host(hostname+port) was not specified. Starting a cart service using in memory store");
|
| 54 |
+
services.AddDistributedMemoryCache();
|
| 55 |
+
services.AddSingleton<ICartStore, RedisCartStore>();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
services.AddGrpc();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
| 63 |
+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
| 64 |
+
{
|
| 65 |
+
if (env.IsDevelopment())
|
| 66 |
+
{
|
| 67 |
+
app.UseDeveloperExceptionPage();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
app.UseRouting();
|
| 71 |
+
|
| 72 |
+
app.UseEndpoints(endpoints =>
|
| 73 |
+
{
|
| 74 |
+
endpoints.MapGrpcService<CartService>();
|
| 75 |
+
endpoints.MapGrpcService<cartservice.services.HealthCheckService>();
|
| 76 |
+
|
| 77 |
+
endpoints.MapGet("/", async context =>
|
| 78 |
+
{
|
| 79 |
+
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
|
| 80 |
+
});
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/AlloyDBCartStore.cs
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2021 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using System;
|
| 16 |
+
using Grpc.Core;
|
| 17 |
+
using Npgsql;
|
| 18 |
+
using Microsoft.Extensions.Configuration;
|
| 19 |
+
using System.Threading.Tasks;
|
| 20 |
+
using Google.Api.Gax.ResourceNames;
|
| 21 |
+
using Google.Cloud.SecretManager.V1;
|
| 22 |
+
|
| 23 |
+
namespace cartservice.cartstore
|
| 24 |
+
{
|
| 25 |
+
public class AlloyDBCartStore : ICartStore
|
| 26 |
+
{
|
| 27 |
+
private readonly string tableName;
|
| 28 |
+
private readonly string connectionString;
|
| 29 |
+
|
| 30 |
+
public AlloyDBCartStore(IConfiguration configuration)
|
| 31 |
+
{
|
| 32 |
+
// Create a Cloud Secrets client.
|
| 33 |
+
SecretManagerServiceClient client = SecretManagerServiceClient.Create();
|
| 34 |
+
var projectId = configuration["PROJECT_ID"];
|
| 35 |
+
var secretId = configuration["ALLOYDB_SECRET_NAME"];
|
| 36 |
+
SecretVersionName secretVersionName = new SecretVersionName(projectId, secretId, "latest");
|
| 37 |
+
|
| 38 |
+
AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);
|
| 39 |
+
// Convert the payload to a string. Payloads are bytes by default.
|
| 40 |
+
string alloyDBPassword = result.Payload.Data.ToStringUtf8().TrimEnd('\r', '\n');
|
| 41 |
+
|
| 42 |
+
// TODO: Create a separate user for connecting within the application
|
| 43 |
+
// rather than using our superuser
|
| 44 |
+
string alloyDBUser = "postgres";
|
| 45 |
+
string databaseName = configuration["ALLOYDB_DATABASE_NAME"];
|
| 46 |
+
// TODO: Consider splitting workloads into read vs. write and take
|
| 47 |
+
// advantage of the AlloyDB read pools
|
| 48 |
+
string primaryIPAddress = configuration["ALLOYDB_PRIMARY_IP"];
|
| 49 |
+
connectionString = "Host=" +
|
| 50 |
+
primaryIPAddress +
|
| 51 |
+
";Username=" +
|
| 52 |
+
alloyDBUser +
|
| 53 |
+
";Password=" +
|
| 54 |
+
alloyDBPassword +
|
| 55 |
+
";Database=" +
|
| 56 |
+
databaseName;
|
| 57 |
+
|
| 58 |
+
tableName = configuration["ALLOYDB_TABLE_NAME"];
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
public async Task AddItemAsync(string userId, string productId, int quantity)
|
| 63 |
+
{
|
| 64 |
+
Console.WriteLine($"AddItemAsync for {userId} called");
|
| 65 |
+
try
|
| 66 |
+
{
|
| 67 |
+
await using var dataSource = NpgsqlDataSource.Create(connectionString);
|
| 68 |
+
|
| 69 |
+
var fetchCmd = $"SELECT quantity FROM {tableName} WHERE userID='{userId}' AND productID='{productId}'";
|
| 70 |
+
var currentQuantity = 0;
|
| 71 |
+
var cmdRead = dataSource.CreateCommand(fetchCmd);
|
| 72 |
+
await using (var reader = await cmdRead.ExecuteReaderAsync())
|
| 73 |
+
{
|
| 74 |
+
while (await reader.ReadAsync())
|
| 75 |
+
currentQuantity += reader.GetInt32(0);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
var totalQuantity = quantity + currentQuantity;
|
| 79 |
+
|
| 80 |
+
// Use INSERT ... ON CONFLICT to prevent duplicate key error
|
| 81 |
+
var insertCmd = $@"
|
| 82 |
+
INSERT INTO {tableName} (userId, productId, quantity)
|
| 83 |
+
VALUES ('{userId}', '{productId}', {totalQuantity})
|
| 84 |
+
ON CONFLICT (userId, productId)
|
| 85 |
+
DO UPDATE SET quantity = {totalQuantity};
|
| 86 |
+
";
|
| 87 |
+
|
| 88 |
+
await using (var cmdInsert = dataSource.CreateCommand(insertCmd))
|
| 89 |
+
{
|
| 90 |
+
await Task.Run(() =>
|
| 91 |
+
{
|
| 92 |
+
return cmdInsert.ExecuteNonQueryAsync();
|
| 93 |
+
});
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
catch (Exception ex)
|
| 97 |
+
{
|
| 98 |
+
throw new RpcException(
|
| 99 |
+
new Status(StatusCode.FailedPrecondition, $"Unable to access cart storage due to an internal error. {ex}"));
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
public async Task<Hipstershop.Cart> GetCartAsync(string userId)
|
| 105 |
+
{
|
| 106 |
+
Console.WriteLine($"GetCartAsync called for userId={userId}");
|
| 107 |
+
Hipstershop.Cart cart = new();
|
| 108 |
+
cart.UserId = userId;
|
| 109 |
+
try
|
| 110 |
+
{
|
| 111 |
+
await using var dataSource = NpgsqlDataSource.Create(connectionString);
|
| 112 |
+
|
| 113 |
+
var cartFetchCmd = $"SELECT productId, quantity FROM {tableName} WHERE userId = '{userId}'";
|
| 114 |
+
var cmd = dataSource.CreateCommand(cartFetchCmd);
|
| 115 |
+
await using (var reader = await cmd.ExecuteReaderAsync())
|
| 116 |
+
{
|
| 117 |
+
while (await reader.ReadAsync())
|
| 118 |
+
{
|
| 119 |
+
Hipstershop.CartItem item = new()
|
| 120 |
+
{
|
| 121 |
+
ProductId = reader.GetString(0),
|
| 122 |
+
Quantity = reader.GetInt32(1)
|
| 123 |
+
};
|
| 124 |
+
cart.Items.Add(item);
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
await Task.Run(() =>
|
| 128 |
+
{
|
| 129 |
+
return cart;
|
| 130 |
+
});
|
| 131 |
+
}
|
| 132 |
+
catch (Exception ex)
|
| 133 |
+
{
|
| 134 |
+
throw new RpcException(
|
| 135 |
+
new Status(StatusCode.FailedPrecondition, $"Unable to access cart storage due to an internal error. {ex}"));
|
| 136 |
+
}
|
| 137 |
+
return cart;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
public async Task EmptyCartAsync(string userId)
|
| 142 |
+
{
|
| 143 |
+
Console.WriteLine($"EmptyCartAsync called for userId={userId}");
|
| 144 |
+
|
| 145 |
+
try
|
| 146 |
+
{
|
| 147 |
+
await using var dataSource = NpgsqlDataSource.Create(connectionString);
|
| 148 |
+
var deleteCmd = $"DELETE FROM {tableName} WHERE userID = '{userId}'";
|
| 149 |
+
await using (var cmd = dataSource.CreateCommand(deleteCmd))
|
| 150 |
+
{
|
| 151 |
+
await Task.Run(() =>
|
| 152 |
+
{
|
| 153 |
+
return cmd.ExecuteNonQueryAsync();
|
| 154 |
+
});
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
catch (Exception ex)
|
| 158 |
+
{
|
| 159 |
+
throw new RpcException(
|
| 160 |
+
new Status(StatusCode.FailedPrecondition, $"Unable to access cart storage due to an internal error. {ex}"));
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
public bool Ping()
|
| 165 |
+
{
|
| 166 |
+
try
|
| 167 |
+
{
|
| 168 |
+
return true;
|
| 169 |
+
}
|
| 170 |
+
catch (Exception)
|
| 171 |
+
{
|
| 172 |
+
return false;
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/ICartStore.cs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using System.Threading.Tasks;
|
| 16 |
+
|
| 17 |
+
namespace cartservice.cartstore
|
| 18 |
+
{
|
| 19 |
+
public interface ICartStore
|
| 20 |
+
{
|
| 21 |
+
Task AddItemAsync(string userId, string productId, int quantity);
|
| 22 |
+
Task EmptyCartAsync(string userId);
|
| 23 |
+
Task<Hipstershop.Cart> GetCartAsync(string userId);
|
| 24 |
+
bool Ping();
|
| 25 |
+
}
|
| 26 |
+
}
|
benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/RedisCartStore.cs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using System;
|
| 16 |
+
using System.Linq;
|
| 17 |
+
using System.Threading.Tasks;
|
| 18 |
+
using Grpc.Core;
|
| 19 |
+
using Microsoft.Extensions.Caching.Distributed;
|
| 20 |
+
using Google.Protobuf;
|
| 21 |
+
|
| 22 |
+
namespace cartservice.cartstore
|
| 23 |
+
{
|
| 24 |
+
public class RedisCartStore : ICartStore
|
| 25 |
+
{
|
| 26 |
+
private readonly IDistributedCache _cache;
|
| 27 |
+
|
| 28 |
+
public RedisCartStore(IDistributedCache cache)
|
| 29 |
+
{
|
| 30 |
+
_cache = cache;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
public async Task AddItemAsync(string userId, string productId, int quantity)
|
| 34 |
+
{
|
| 35 |
+
Console.WriteLine($"AddItemAsync called with userId={userId}, productId={productId}, quantity={quantity}");
|
| 36 |
+
|
| 37 |
+
try
|
| 38 |
+
{
|
| 39 |
+
Hipstershop.Cart cart;
|
| 40 |
+
var value = await _cache.GetAsync(userId);
|
| 41 |
+
if (value == null)
|
| 42 |
+
{
|
| 43 |
+
cart = new Hipstershop.Cart();
|
| 44 |
+
cart.UserId = userId;
|
| 45 |
+
cart.Items.Add(new Hipstershop.CartItem { ProductId = productId, Quantity = quantity });
|
| 46 |
+
}
|
| 47 |
+
else
|
| 48 |
+
{
|
| 49 |
+
cart = Hipstershop.Cart.Parser.ParseFrom(value);
|
| 50 |
+
var existingItem = cart.Items.SingleOrDefault(i => i.ProductId == productId);
|
| 51 |
+
if (existingItem == null)
|
| 52 |
+
{
|
| 53 |
+
cart.Items.Add(new Hipstershop.CartItem { ProductId = productId, Quantity = quantity });
|
| 54 |
+
}
|
| 55 |
+
else
|
| 56 |
+
{
|
| 57 |
+
existingItem.Quantity += quantity;
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
await _cache.SetAsync(userId, cart.ToByteArray());
|
| 61 |
+
}
|
| 62 |
+
catch (Exception ex)
|
| 63 |
+
{
|
| 64 |
+
throw new RpcException(new Status(StatusCode.FailedPrecondition, $"Can't access cart storage. {ex}"));
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
public async Task EmptyCartAsync(string userId)
|
| 69 |
+
{
|
| 70 |
+
Console.WriteLine($"EmptyCartAsync called with userId={userId}");
|
| 71 |
+
|
| 72 |
+
try
|
| 73 |
+
{
|
| 74 |
+
var cart = new Hipstershop.Cart();
|
| 75 |
+
await _cache.SetAsync(userId, cart.ToByteArray());
|
| 76 |
+
}
|
| 77 |
+
catch (Exception ex)
|
| 78 |
+
{
|
| 79 |
+
throw new RpcException(new Status(StatusCode.FailedPrecondition, $"Can't access cart storage. {ex}"));
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
public async Task<Hipstershop.Cart> GetCartAsync(string userId)
|
| 84 |
+
{
|
| 85 |
+
Console.WriteLine($"GetCartAsync called with userId={userId}");
|
| 86 |
+
|
| 87 |
+
try
|
| 88 |
+
{
|
| 89 |
+
// Access the cart from the cache
|
| 90 |
+
var value = await _cache.GetAsync(userId);
|
| 91 |
+
|
| 92 |
+
if (value != null)
|
| 93 |
+
{
|
| 94 |
+
return Hipstershop.Cart.Parser.ParseFrom(value);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
// We decided to return empty cart in cases when user wasn't in the cache before
|
| 98 |
+
return new Hipstershop.Cart();
|
| 99 |
+
}
|
| 100 |
+
catch (Exception ex)
|
| 101 |
+
{
|
| 102 |
+
throw new RpcException(new Status(StatusCode.FailedPrecondition, $"Can't access cart storage. {ex}"));
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
public bool Ping()
|
| 107 |
+
{
|
| 108 |
+
try
|
| 109 |
+
{
|
| 110 |
+
return true;
|
| 111 |
+
}
|
| 112 |
+
catch (Exception)
|
| 113 |
+
{
|
| 114 |
+
return false;
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
}
|
benchmark/boutique/codedefect/32/code/cartservice/src/cartstore/SpannerCartStore.cs
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2021 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using System;
|
| 16 |
+
using Google.Cloud.Spanner.Data;
|
| 17 |
+
using Grpc.Core;
|
| 18 |
+
using Microsoft.Extensions.Configuration;
|
| 19 |
+
using System.Threading.Tasks;
|
| 20 |
+
|
| 21 |
+
namespace cartservice.cartstore
|
| 22 |
+
{
|
| 23 |
+
public class SpannerCartStore : ICartStore
|
| 24 |
+
{
|
| 25 |
+
private static readonly string TableName = "CartItems";
|
| 26 |
+
private static readonly string DefaultInstanceName = "onlineboutique";
|
| 27 |
+
private static readonly string DefaultDatabaseName = "carts";
|
| 28 |
+
private readonly string databaseString;
|
| 29 |
+
|
| 30 |
+
public SpannerCartStore(IConfiguration configuration)
|
| 31 |
+
{
|
| 32 |
+
string spannerProjectId = configuration["SPANNER_PROJECT"];
|
| 33 |
+
string spannerInstanceId = configuration["SPANNER_INSTANCE"];
|
| 34 |
+
string spannerDatabaseId = configuration["SPANNER_DATABASE"];
|
| 35 |
+
string spannerConnectionString = configuration["SPANNER_CONNECTION_STRING"];
|
| 36 |
+
SpannerConnectionStringBuilder builder = new();
|
| 37 |
+
if (!string.IsNullOrEmpty(spannerConnectionString)) {
|
| 38 |
+
builder.DataSource = spannerConnectionString;
|
| 39 |
+
databaseString = builder.ToString();
|
| 40 |
+
Console.WriteLine($"Spanner connection string: ${databaseString}");
|
| 41 |
+
return;
|
| 42 |
+
}
|
| 43 |
+
if (string.IsNullOrEmpty(spannerInstanceId))
|
| 44 |
+
spannerInstanceId = DefaultInstanceName;
|
| 45 |
+
if (string.IsNullOrEmpty(spannerDatabaseId))
|
| 46 |
+
spannerDatabaseId = DefaultDatabaseName;
|
| 47 |
+
builder.DataSource =
|
| 48 |
+
$"projects/{spannerProjectId}/instances/{spannerInstanceId}/databases/{spannerDatabaseId}";
|
| 49 |
+
databaseString = builder.ToString();
|
| 50 |
+
Console.WriteLine($"Built Spanner connection string: '{databaseString}'");
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
public async Task AddItemAsync(string userId, string productId, int quantity)
|
| 55 |
+
{
|
| 56 |
+
Console.WriteLine($"AddItemAsync for {userId} called");
|
| 57 |
+
try
|
| 58 |
+
{
|
| 59 |
+
using SpannerConnection spannerConnection = new(databaseString);
|
| 60 |
+
await spannerConnection.RunWithRetriableTransactionAsync(async transaction =>
|
| 61 |
+
{
|
| 62 |
+
int currentQuantity = 0;
|
| 63 |
+
var quantityLookup = spannerConnection.CreateSelectCommand(
|
| 64 |
+
$"SELECT * FROM {TableName} WHERE userId = @userId AND productId = @productId",
|
| 65 |
+
new SpannerParameterCollection
|
| 66 |
+
{
|
| 67 |
+
{ "userId", SpannerDbType.String },
|
| 68 |
+
{ "productId", SpannerDbType.String }
|
| 69 |
+
});
|
| 70 |
+
quantityLookup.Parameters["userId"].Value = userId;
|
| 71 |
+
quantityLookup.Parameters["productId"].Value = productId;
|
| 72 |
+
quantityLookup.Transaction = transaction;
|
| 73 |
+
using (var reader = await quantityLookup.ExecuteReaderAsync())
|
| 74 |
+
{
|
| 75 |
+
while (await reader.ReadAsync()) {
|
| 76 |
+
currentQuantity += reader.GetFieldValue<int>("quantity");
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
var cmd = spannerConnection.CreateInsertOrUpdateCommand(TableName,
|
| 81 |
+
new SpannerParameterCollection
|
| 82 |
+
{
|
| 83 |
+
{ "userId", SpannerDbType.String },
|
| 84 |
+
{ "productId", SpannerDbType.String },
|
| 85 |
+
{ "quantity", SpannerDbType.Int64 }
|
| 86 |
+
});
|
| 87 |
+
cmd.Parameters["userId"].Value = userId;
|
| 88 |
+
cmd.Parameters["productId"].Value = productId;
|
| 89 |
+
cmd.Parameters["quantity"].Value = currentQuantity + quantity;
|
| 90 |
+
cmd.Transaction = transaction;
|
| 91 |
+
await Task.Run(() =>
|
| 92 |
+
{
|
| 93 |
+
return cmd.ExecuteNonQueryAsync();
|
| 94 |
+
});
|
| 95 |
+
});
|
| 96 |
+
}
|
| 97 |
+
catch (Exception ex)
|
| 98 |
+
{
|
| 99 |
+
throw new RpcException(
|
| 100 |
+
new Status(StatusCode.FailedPrecondition, $"Can't access cart storage at {databaseString}. {ex}"));
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
public async Task<Hipstershop.Cart> GetCartAsync(string userId)
|
| 106 |
+
{
|
| 107 |
+
Console.WriteLine($"GetCartAsync called for userId={userId}");
|
| 108 |
+
Hipstershop.Cart cart = new();
|
| 109 |
+
try
|
| 110 |
+
{
|
| 111 |
+
using SpannerConnection spannerConnection = new(databaseString);
|
| 112 |
+
var cmd = spannerConnection.CreateSelectCommand(
|
| 113 |
+
$"SELECT * FROM {TableName} WHERE userId = @userId",
|
| 114 |
+
new SpannerParameterCollection {
|
| 115 |
+
{ "userId", SpannerDbType.String }
|
| 116 |
+
}
|
| 117 |
+
);
|
| 118 |
+
cmd.Parameters["userId"].Value = userId;
|
| 119 |
+
using var reader = await cmd.ExecuteReaderAsync();
|
| 120 |
+
while (await reader.ReadAsync())
|
| 121 |
+
{
|
| 122 |
+
// Only add the userId if something is in the cart.
|
| 123 |
+
// This is based on how the cartservice example behaves.
|
| 124 |
+
// An empty cart has no userId attached.
|
| 125 |
+
cart.UserId = userId;
|
| 126 |
+
|
| 127 |
+
Hipstershop.CartItem item = new()
|
| 128 |
+
{
|
| 129 |
+
ProductId = reader.GetFieldValue<string>("productId"),
|
| 130 |
+
Quantity = reader.GetFieldValue<int>("quantity")
|
| 131 |
+
};
|
| 132 |
+
cart.Items.Add(item);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
return cart;
|
| 136 |
+
}
|
| 137 |
+
catch (Exception ex)
|
| 138 |
+
{
|
| 139 |
+
throw new RpcException(
|
| 140 |
+
new Status(StatusCode.FailedPrecondition, $"Can't access cart storage at {databaseString}. {ex}"));
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
public async Task EmptyCartAsync(string userId)
|
| 146 |
+
{
|
| 147 |
+
Console.WriteLine($"EmptyCartAsync called for userId={userId}");
|
| 148 |
+
|
| 149 |
+
try
|
| 150 |
+
{
|
| 151 |
+
using SpannerConnection spannerConnection = new(databaseString);
|
| 152 |
+
await Task.Run(() =>
|
| 153 |
+
{
|
| 154 |
+
var cmd = spannerConnection.CreateDmlCommand(
|
| 155 |
+
$"DELETE FROM {TableName} WHERE userId = @userId",
|
| 156 |
+
new SpannerParameterCollection
|
| 157 |
+
{
|
| 158 |
+
{ "userId", SpannerDbType.String }
|
| 159 |
+
});
|
| 160 |
+
cmd.Parameters["userId"].Value = userId;
|
| 161 |
+
return cmd.ExecuteNonQueryAsync();
|
| 162 |
+
});
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
catch (Exception ex)
|
| 166 |
+
{
|
| 167 |
+
throw new RpcException(
|
| 168 |
+
new Status(StatusCode.FailedPrecondition, $"Can't access cart storage at {databaseString}. {ex}"));
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
public bool Ping()
|
| 173 |
+
{
|
| 174 |
+
try
|
| 175 |
+
{
|
| 176 |
+
return true;
|
| 177 |
+
}
|
| 178 |
+
catch (Exception)
|
| 179 |
+
{
|
| 180 |
+
return false;
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
benchmark/boutique/codedefect/32/code/cartservice/src/services/CartService.cs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using System;
|
| 16 |
+
using System.Threading.Tasks;
|
| 17 |
+
using Grpc.Core;
|
| 18 |
+
using Microsoft.Extensions.Logging;
|
| 19 |
+
using cartservice.cartstore;
|
| 20 |
+
using Hipstershop;
|
| 21 |
+
|
| 22 |
+
namespace cartservice.services
|
| 23 |
+
{
|
| 24 |
+
public class CartService : Hipstershop.CartService.CartServiceBase
|
| 25 |
+
{
|
| 26 |
+
private readonly static Empty Empty = new Empty();
|
| 27 |
+
private readonly ICartStore _cartStore;
|
| 28 |
+
|
| 29 |
+
public CartService(ICartStore cartStore)
|
| 30 |
+
{
|
| 31 |
+
_cartStore = cartStore;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public async override Task<Empty> AddItem(AddItemRequest request, ServerCallContext context)
|
| 35 |
+
{
|
| 36 |
+
await _cartStore.AddItemAsync(request.UserId, request.Item.ProductId, request.Item.Quantity);
|
| 37 |
+
return Empty;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public override Task<Cart> GetCart(GetCartRequest request, ServerCallContext context)
|
| 41 |
+
{
|
| 42 |
+
return _cartStore.GetCartAsync(request.UserId);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public async override Task<Empty> EmptyCart(EmptyCartRequest request, ServerCallContext context)
|
| 46 |
+
{
|
| 47 |
+
await _cartStore.EmptyCartAsync(request.UserId);
|
| 48 |
+
return Empty;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
benchmark/boutique/codedefect/32/code/cartservice/src/services/HealthCheckService.cs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using System;
|
| 16 |
+
using System.Threading.Tasks;
|
| 17 |
+
using Grpc.Core;
|
| 18 |
+
using Grpc.Health.V1;
|
| 19 |
+
using static Grpc.Health.V1.Health;
|
| 20 |
+
using cartservice.cartstore;
|
| 21 |
+
|
| 22 |
+
namespace cartservice.services
|
| 23 |
+
{
|
| 24 |
+
internal class HealthCheckService : HealthBase
|
| 25 |
+
{
|
| 26 |
+
private ICartStore _cartStore { get; }
|
| 27 |
+
|
| 28 |
+
public HealthCheckService (ICartStore cartStore)
|
| 29 |
+
{
|
| 30 |
+
_cartStore = cartStore;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
public override Task<HealthCheckResponse> Check(HealthCheckRequest request, ServerCallContext context)
|
| 34 |
+
{
|
| 35 |
+
Console.WriteLine ("Checking CartService Health");
|
| 36 |
+
return Task.FromResult(new HealthCheckResponse {
|
| 37 |
+
Status = _cartStore.Ping() ? HealthCheckResponse.Types.ServingStatus.Serving : HealthCheckResponse.Types.ServingStatus.NotServing
|
| 38 |
+
});
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
}
|
benchmark/boutique/codedefect/32/code/checkoutservice/main.go
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"context"
|
| 19 |
+
"fmt"
|
| 20 |
+
"net"
|
| 21 |
+
"os"
|
| 22 |
+
"time"
|
| 23 |
+
|
| 24 |
+
"cloud.google.com/go/profiler"
|
| 25 |
+
"github.com/google/uuid"
|
| 26 |
+
"github.com/pkg/errors"
|
| 27 |
+
"github.com/sirupsen/logrus"
|
| 28 |
+
"google.golang.org/grpc"
|
| 29 |
+
"google.golang.org/grpc/codes"
|
| 30 |
+
"google.golang.org/grpc/credentials/insecure"
|
| 31 |
+
"google.golang.org/grpc/health"
|
| 32 |
+
"google.golang.org/grpc/status"
|
| 33 |
+
|
| 34 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
|
| 35 |
+
money "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money"
|
| 36 |
+
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
| 37 |
+
|
| 38 |
+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
| 39 |
+
"go.opentelemetry.io/otel"
|
| 40 |
+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
| 41 |
+
"go.opentelemetry.io/otel/propagation"
|
| 42 |
+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
const (
|
| 46 |
+
listenPort = "5050"
|
| 47 |
+
usdCurrency = "USD"
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
var log *logrus.Logger
|
| 51 |
+
|
| 52 |
+
func init() {
|
| 53 |
+
log = logrus.New()
|
| 54 |
+
log.Level = logrus.DebugLevel
|
| 55 |
+
log.Formatter = &logrus.JSONFormatter{
|
| 56 |
+
FieldMap: logrus.FieldMap{
|
| 57 |
+
logrus.FieldKeyTime: "timestamp",
|
| 58 |
+
logrus.FieldKeyLevel: "severity",
|
| 59 |
+
logrus.FieldKeyMsg: "message",
|
| 60 |
+
},
|
| 61 |
+
TimestampFormat: time.RFC3339Nano,
|
| 62 |
+
}
|
| 63 |
+
log.Out = os.Stdout
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
type checkoutService struct {
|
| 67 |
+
pb.UnimplementedCheckoutServiceServer
|
| 68 |
+
|
| 69 |
+
productCatalogSvcAddr string
|
| 70 |
+
productCatalogSvcConn *grpc.ClientConn
|
| 71 |
+
|
| 72 |
+
cartSvcAddr string
|
| 73 |
+
cartSvcConn *grpc.ClientConn
|
| 74 |
+
|
| 75 |
+
currencySvcAddr string
|
| 76 |
+
currencySvcConn *grpc.ClientConn
|
| 77 |
+
|
| 78 |
+
shippingSvcAddr string
|
| 79 |
+
shippingSvcConn *grpc.ClientConn
|
| 80 |
+
|
| 81 |
+
emailSvcAddr string
|
| 82 |
+
emailSvcConn *grpc.ClientConn
|
| 83 |
+
|
| 84 |
+
paymentSvcAddr string
|
| 85 |
+
paymentSvcConn *grpc.ClientConn
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
func main() {
|
| 89 |
+
ctx := context.Background()
|
| 90 |
+
if os.Getenv("ENABLE_TRACING") == "1" {
|
| 91 |
+
log.Info("Tracing enabled.")
|
| 92 |
+
initTracing()
|
| 93 |
+
|
| 94 |
+
} else {
|
| 95 |
+
log.Info("Tracing disabled.")
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if os.Getenv("ENABLE_PROFILER") == "1" {
|
| 99 |
+
log.Info("Profiling enabled.")
|
| 100 |
+
go initProfiling("checkoutservice", "1.0.0")
|
| 101 |
+
} else {
|
| 102 |
+
log.Info("Profiling disabled.")
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
port := listenPort
|
| 106 |
+
if os.Getenv("PORT") != "" {
|
| 107 |
+
port = os.Getenv("PORT")
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
svc := new(checkoutService)
|
| 111 |
+
mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR")
|
| 112 |
+
mustMapEnv(&svc.productCatalogSvcAddr, "PRODUCT_CATALOG_SERVICE_ADDR")
|
| 113 |
+
mustMapEnv(&svc.cartSvcAddr, "CART_SERVICE_ADDR")
|
| 114 |
+
mustMapEnv(&svc.currencySvcAddr, "CURRENCY_SERVICE_ADDR")
|
| 115 |
+
mustMapEnv(&svc.emailSvcAddr, "EMAIL_SERVICE_ADDR")
|
| 116 |
+
mustMapEnv(&svc.paymentSvcAddr, "PAYMENT_SERVICE_ADDR")
|
| 117 |
+
|
| 118 |
+
mustConnGRPC(ctx, &svc.shippingSvcConn, svc.shippingSvcAddr)
|
| 119 |
+
mustConnGRPC(ctx, &svc.productCatalogSvcConn, svc.productCatalogSvcAddr)
|
| 120 |
+
mustConnGRPC(ctx, &svc.cartSvcConn, svc.cartSvcAddr)
|
| 121 |
+
mustConnGRPC(ctx, &svc.currencySvcConn, svc.currencySvcAddr)
|
| 122 |
+
mustConnGRPC(ctx, &svc.emailSvcConn, svc.emailSvcAddr)
|
| 123 |
+
mustConnGRPC(ctx, &svc.paymentSvcConn, svc.paymentSvcAddr)
|
| 124 |
+
|
| 125 |
+
log.Infof("service config: %+v", svc)
|
| 126 |
+
|
| 127 |
+
lis, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
|
| 128 |
+
if err != nil {
|
| 129 |
+
log.Fatal(err)
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
var srv *grpc.Server
|
| 133 |
+
|
| 134 |
+
// Propagate trace context always
|
| 135 |
+
otel.SetTextMapPropagator(
|
| 136 |
+
propagation.NewCompositeTextMapPropagator(
|
| 137 |
+
propagation.TraceContext{}, propagation.Baggage{}))
|
| 138 |
+
srv = grpc.NewServer(
|
| 139 |
+
grpc.StatsHandler(otelgrpc.NewServerHandler()),
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
pb.RegisterCheckoutServiceServer(srv, svc)
|
| 143 |
+
healthcheck := health.NewServer()
|
| 144 |
+
healthpb.RegisterHealthServer(srv, healthcheck)
|
| 145 |
+
log.Infof("starting to listen on tcp: %q", lis.Addr().String())
|
| 146 |
+
err = srv.Serve(lis)
|
| 147 |
+
log.Fatal(err)
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
func initStats() {
|
| 151 |
+
//TODO(arbrown) Implement OpenTelemetry stats
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
func initTracing() {
|
| 155 |
+
var (
|
| 156 |
+
collectorAddr string
|
| 157 |
+
collectorConn *grpc.ClientConn
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
ctx := context.Background()
|
| 161 |
+
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
|
| 162 |
+
defer cancel()
|
| 163 |
+
|
| 164 |
+
mustMapEnv(&collectorAddr, "COLLECTOR_SERVICE_ADDR")
|
| 165 |
+
mustConnGRPC(ctx, &collectorConn, collectorAddr)
|
| 166 |
+
|
| 167 |
+
exporter, err := otlptracegrpc.New(
|
| 168 |
+
ctx,
|
| 169 |
+
otlptracegrpc.WithGRPCConn(collectorConn))
|
| 170 |
+
if err != nil {
|
| 171 |
+
log.Warnf("warn: Failed to create trace exporter: %v", err)
|
| 172 |
+
}
|
| 173 |
+
tp := sdktrace.NewTracerProvider(
|
| 174 |
+
sdktrace.WithBatcher(exporter),
|
| 175 |
+
sdktrace.WithSampler(sdktrace.AlwaysSample()))
|
| 176 |
+
otel.SetTracerProvider(tp)
|
| 177 |
+
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
func initProfiling(service, version string) {
|
| 181 |
+
// TODO(ahmetb) this method is duplicated in other microservices using Go
|
| 182 |
+
// since they are not sharing packages.
|
| 183 |
+
for i := 1; i <= 3; i++ {
|
| 184 |
+
if err := profiler.Start(profiler.Config{
|
| 185 |
+
Service: service,
|
| 186 |
+
ServiceVersion: version,
|
| 187 |
+
// ProjectID must be set if not running on GCP.
|
| 188 |
+
// ProjectID: "my-project",
|
| 189 |
+
}); err != nil {
|
| 190 |
+
log.Warnf("failed to start profiler: %+v", err)
|
| 191 |
+
} else {
|
| 192 |
+
log.Info("started Stackdriver profiler")
|
| 193 |
+
return
|
| 194 |
+
}
|
| 195 |
+
d := time.Second * 10 * time.Duration(i)
|
| 196 |
+
log.Infof("sleeping %v to retry initializing Stackdriver profiler", d)
|
| 197 |
+
time.Sleep(d)
|
| 198 |
+
}
|
| 199 |
+
log.Warn("could not initialize Stackdriver profiler after retrying, giving up")
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
func mustMapEnv(target *string, envKey string) {
|
| 203 |
+
v := os.Getenv(envKey)
|
| 204 |
+
if v == "" {
|
| 205 |
+
panic(fmt.Sprintf("environment variable %q not set", envKey))
|
| 206 |
+
}
|
| 207 |
+
*target = v
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
func mustConnGRPC(ctx context.Context, conn **grpc.ClientConn, addr string) {
|
| 211 |
+
var err error
|
| 212 |
+
_, cancel := context.WithTimeout(ctx, time.Second*3)
|
| 213 |
+
defer cancel()
|
| 214 |
+
*conn, err = grpc.NewClient(addr,
|
| 215 |
+
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
| 216 |
+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
|
| 217 |
+
if err != nil {
|
| 218 |
+
panic(errors.Wrapf(err, "grpc: failed to connect %s", addr))
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
func (cs *checkoutService) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
| 223 |
+
return &healthpb.HealthCheckResponse{Status: healthpb.HealthCheckResponse_SERVING}, nil
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
func (cs *checkoutService) Watch(req *healthpb.HealthCheckRequest, ws healthpb.Health_WatchServer) error {
|
| 227 |
+
return status.Errorf(codes.Unimplemented, "health check via Watch not implemented")
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderRequest) (*pb.PlaceOrderResponse, error) {
|
| 231 |
+
log.Infof("[PlaceOrder] user_id=%q user_currency=%q", req.UserId, req.UserCurrency)
|
| 232 |
+
|
| 233 |
+
orderID, err := uuid.NewUUID()
|
| 234 |
+
if err != nil {
|
| 235 |
+
return nil, status.Errorf(codes.Internal, "failed to generate order uuid")
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
prep, err := cs.prepareOrderItemsAndShippingQuoteFromCart(ctx, req.UserId, req.UserCurrency, req.Address)
|
| 239 |
+
if err != nil {
|
| 240 |
+
return nil, status.Errorf(codes.Internal, err.Error())
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
total := pb.Money{CurrencyCode: req.UserCurrency,
|
| 244 |
+
Units: 0,
|
| 245 |
+
Nanos: 0}
|
| 246 |
+
total = money.Must(money.Sum(total, *prep.shippingCostLocalized))
|
| 247 |
+
for _, it := range prep.orderItems {
|
| 248 |
+
multPrice := money.MultiplySlow(*it.Cost, uint32(it.GetItem().GetQuantity()))
|
| 249 |
+
total = money.Must(money.Sum(total, multPrice))
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
txID, err := cs.chargeCard(ctx, &total, req.CreditCard)
|
| 253 |
+
if err != nil {
|
| 254 |
+
return nil, status.Errorf(codes.Internal, "failed to charge card: %+v", err)
|
| 255 |
+
}
|
| 256 |
+
log.Infof("payment went through (transaction_id: %s)", txID)
|
| 257 |
+
|
| 258 |
+
shippingTrackingID, err := cs.shipOrder(ctx, req.Address, prep.cartItems)
|
| 259 |
+
if err != nil {
|
| 260 |
+
return nil, status.Errorf(codes.Unavailable, "shipping error: %+v", err)
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
_ = cs.emptyUserCart(ctx, req.UserId)
|
| 264 |
+
|
| 265 |
+
orderResult := &pb.OrderResult{
|
| 266 |
+
OrderId: orderID.String(),
|
| 267 |
+
ShippingTrackingId: shippingTrackingID,
|
| 268 |
+
ShippingCost: prep.shippingCostLocalized,
|
| 269 |
+
ShippingAddress: req.Address,
|
| 270 |
+
Items: prep.orderItems,
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
if err := cs.sendOrderConfirmation(ctx, req.Email, orderResult); err != nil {
|
| 274 |
+
log.Warnf("failed to send order confirmation to %q: %+v", req.Email, err)
|
| 275 |
+
} else {
|
| 276 |
+
log.Infof("order confirmation email sent to %q", req.Email)
|
| 277 |
+
}
|
| 278 |
+
resp := &pb.PlaceOrderResponse{Order: orderResult}
|
| 279 |
+
return resp, nil
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
type orderPrep struct {
|
| 283 |
+
orderItems []*pb.OrderItem
|
| 284 |
+
cartItems []*pb.CartItem
|
| 285 |
+
shippingCostLocalized *pb.Money
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
func (cs *checkoutService) prepareOrderItemsAndShippingQuoteFromCart(ctx context.Context, userID, userCurrency string, address *pb.Address) (orderPrep, error) {
|
| 289 |
+
var out orderPrep
|
| 290 |
+
cartItems, err := cs.getUserCart(ctx, userID)
|
| 291 |
+
if err != nil {
|
| 292 |
+
return out, fmt.Errorf("cart failure: %+v", err)
|
| 293 |
+
}
|
| 294 |
+
orderItems, err := cs.prepOrderItems(ctx, cartItems, userCurrency)
|
| 295 |
+
if err != nil {
|
| 296 |
+
return out, fmt.Errorf("failed to prepare order: %+v", err)
|
| 297 |
+
}
|
| 298 |
+
shippingUSD, err := cs.quoteShipping(ctx, address, cartItems)
|
| 299 |
+
if err != nil {
|
| 300 |
+
return out, fmt.Errorf("shipping quote failure: %+v", err)
|
| 301 |
+
}
|
| 302 |
+
shippingPrice, err := cs.convertCurrency(ctx, shippingUSD, userCurrency)
|
| 303 |
+
if err != nil {
|
| 304 |
+
return out, fmt.Errorf("failed to convert shipping cost to currency: %+v", err)
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
out.shippingCostLocalized = shippingPrice
|
| 308 |
+
out.cartItems = cartItems
|
| 309 |
+
out.orderItems = orderItems
|
| 310 |
+
return out, nil
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
func (cs *checkoutService) quoteShipping(ctx context.Context, address *pb.Address, items []*pb.CartItem) (*pb.Money, error) {
|
| 314 |
+
shippingQuote, err := pb.NewShippingServiceClient(cs.shippingSvcConn).
|
| 315 |
+
GetQuote(ctx, &pb.GetQuoteRequest{
|
| 316 |
+
Address: address,
|
| 317 |
+
Items: items})
|
| 318 |
+
if err != nil {
|
| 319 |
+
return nil, fmt.Errorf("failed to get shipping quote: %+v", err)
|
| 320 |
+
}
|
| 321 |
+
return shippingQuote.GetCostUsd(), nil
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
func (cs *checkoutService) getUserCart(ctx context.Context, userID string) ([]*pb.CartItem, error) {
|
| 325 |
+
cart, err := pb.NewCartServiceClient(cs.cartSvcConn).GetCart(ctx, &pb.GetCartRequest{UserId: userID})
|
| 326 |
+
if err != nil {
|
| 327 |
+
return nil, fmt.Errorf("failed to get user cart during checkout: %+v", err)
|
| 328 |
+
}
|
| 329 |
+
return cart.GetItems(), nil
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
func (cs *checkoutService) emptyUserCart(ctx context.Context, userID string) error {
|
| 333 |
+
if _, err := pb.NewCartServiceClient(cs.cartSvcConn).EmptyCart(ctx, &pb.EmptyCartRequest{UserId: userID}); err != nil {
|
| 334 |
+
return fmt.Errorf("failed to empty user cart during checkout: %+v", err)
|
| 335 |
+
}
|
| 336 |
+
return nil
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
func (cs *checkoutService) prepOrderItems(ctx context.Context, items []*pb.CartItem, userCurrency string) ([]*pb.OrderItem, error) {
|
| 340 |
+
out := make([]*pb.OrderItem, len(items))
|
| 341 |
+
cl := pb.NewProductCatalogServiceClient(cs.productCatalogSvcConn)
|
| 342 |
+
|
| 343 |
+
for i, item := range items {
|
| 344 |
+
product, err := cl.GetProduct(ctx, &pb.GetProductRequest{Id: item.GetProductId()})
|
| 345 |
+
if err != nil {
|
| 346 |
+
return nil, fmt.Errorf("failed to get product #%q", item.GetProductId())
|
| 347 |
+
}
|
| 348 |
+
price, err := cs.convertCurrency(ctx, product.GetPriceUsd(), userCurrency)
|
| 349 |
+
if err != nil {
|
| 350 |
+
return nil, fmt.Errorf("failed to convert price of %q to %s", item.GetProductId(), userCurrency)
|
| 351 |
+
}
|
| 352 |
+
out[i] = &pb.OrderItem{
|
| 353 |
+
Item: item,
|
| 354 |
+
Cost: price}
|
| 355 |
+
}
|
| 356 |
+
return out, nil
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
func (cs *checkoutService) convertCurrency(ctx context.Context, from *pb.Money, toCurrency string) (*pb.Money, error) {
|
| 360 |
+
result, err := pb.NewCurrencyServiceClient(cs.currencySvcConn).Convert(context.TODO(), &pb.CurrencyConversionRequest{
|
| 361 |
+
From: from,
|
| 362 |
+
ToCode: toCurrency})
|
| 363 |
+
if err != nil {
|
| 364 |
+
return nil, fmt.Errorf("failed to convert currency: %+v", err)
|
| 365 |
+
}
|
| 366 |
+
return result, err
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
func (cs *checkoutService) chargeCard(ctx context.Context, amount *pb.Money, paymentInfo *pb.CreditCardInfo) (string, error) {
|
| 370 |
+
paymentResp, err := pb.NewPaymentServiceClient(cs.paymentSvcConn).Charge(ctx, &pb.ChargeRequest{
|
| 371 |
+
Amount: amount,
|
| 372 |
+
CreditCard: paymentInfo})
|
| 373 |
+
if err != nil {
|
| 374 |
+
return "", fmt.Errorf("could not charge the card: %+v", err)
|
| 375 |
+
}
|
| 376 |
+
return paymentResp.GetTransactionId(), nil
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
func (cs *checkoutService) sendOrderConfirmation(ctx context.Context, email string, order *pb.OrderResult) error {
|
| 380 |
+
_, err := pb.NewEmailServiceClient(cs.emailSvcConn).SendOrderConfirmation(ctx, &pb.SendOrderConfirmationRequest{
|
| 381 |
+
Email: email,
|
| 382 |
+
Order: order})
|
| 383 |
+
return err
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
func (cs *checkoutService) shipOrder(ctx context.Context, address *pb.Address, items []*pb.CartItem) (string, error) {
|
| 387 |
+
resp, err := pb.NewShippingServiceClient(cs.shippingSvcConn).ShipOrder(ctx, &pb.ShipOrderRequest{
|
| 388 |
+
Address: address,
|
| 389 |
+
Items: items})
|
| 390 |
+
if err != nil {
|
| 391 |
+
return "", fmt.Errorf("shipment failed: %+v", err)
|
| 392 |
+
}
|
| 393 |
+
return resp.GetTrackingId(), nil
|
| 394 |
+
}
|
benchmark/boutique/codedefect/32/code/checkoutservice/money/money.go
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package money
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"errors"
|
| 19 |
+
|
| 20 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const (
|
| 24 |
+
nanosMin = -999999999
|
| 25 |
+
nanosMax = +999999999
|
| 26 |
+
nanosMod = 1000000000
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
var (
|
| 30 |
+
ErrInvalidValue = errors.New("one of the specified money values is invalid")
|
| 31 |
+
ErrMismatchingCurrency = errors.New("mismatching currency codes")
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
// IsValid checks if specified value has a valid units/nanos signs and ranges.
|
| 35 |
+
func IsValid(m pb.Money) bool {
|
| 36 |
+
return signMatches(m) && validNanos(m.GetNanos())
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func signMatches(m pb.Money) bool {
|
| 40 |
+
return m.GetNanos() == 0 || m.GetUnits() == 0 || (m.GetNanos() < 0) == (m.GetUnits() < 0)
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
func validNanos(nanos int32) bool { return nanosMin <= nanos && nanos <= nanosMax }
|
| 44 |
+
|
| 45 |
+
// IsZero returns true if the specified money value is equal to zero.
|
| 46 |
+
func IsZero(m pb.Money) bool { return m.GetUnits() == 0 && m.GetNanos() == 0 }
|
| 47 |
+
|
| 48 |
+
// IsPositive returns true if the specified money value is valid and is
|
| 49 |
+
// positive.
|
| 50 |
+
func IsPositive(m pb.Money) bool {
|
| 51 |
+
return IsValid(m) && m.GetUnits() > 0 || (m.GetUnits() == 0 && m.GetNanos() > 0)
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// IsNegative returns true if the specified money value is valid and is
|
| 55 |
+
// negative.
|
| 56 |
+
func IsNegative(m pb.Money) bool {
|
| 57 |
+
return IsValid(m) && m.GetUnits() < 0 || (m.GetUnits() == 0 && m.GetNanos() < 0)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// AreSameCurrency returns true if values l and r have a currency code and
|
| 61 |
+
// they are the same values.
|
| 62 |
+
func AreSameCurrency(l, r pb.Money) bool {
|
| 63 |
+
return l.GetCurrencyCode() == r.GetCurrencyCode() && l.GetCurrencyCode() != ""
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// AreEquals returns true if values l and r are the equal, including the
|
| 67 |
+
// currency. This does not check validity of the provided values.
|
| 68 |
+
func AreEquals(l, r pb.Money) bool {
|
| 69 |
+
return l.GetCurrencyCode() == r.GetCurrencyCode() &&
|
| 70 |
+
l.GetUnits() == r.GetUnits() && l.GetNanos() == r.GetNanos()
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// Negate returns the same amount with the sign negated.
|
| 74 |
+
func Negate(m pb.Money) pb.Money {
|
| 75 |
+
return pb.Money{
|
| 76 |
+
Units: -m.GetUnits(),
|
| 77 |
+
Nanos: -m.GetNanos(),
|
| 78 |
+
CurrencyCode: m.GetCurrencyCode()}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Must panics if the given error is not nil. This can be used with other
|
| 82 |
+
// functions like: "m := Must(Sum(a,b))".
|
| 83 |
+
func Must(v pb.Money, err error) pb.Money {
|
| 84 |
+
if err != nil {
|
| 85 |
+
panic(err)
|
| 86 |
+
}
|
| 87 |
+
return v
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// Sum adds two values. Returns an error if one of the values are invalid or
|
| 91 |
+
// currency codes are not matching (unless currency code is unspecified for
|
| 92 |
+
// both).
|
| 93 |
+
func Sum(l, r pb.Money) (pb.Money, error) {
|
| 94 |
+
if !IsValid(l) || !IsValid(r) {
|
| 95 |
+
return pb.Money{}, ErrInvalidValue
|
| 96 |
+
} else if l.GetCurrencyCode() != r.GetCurrencyCode() {
|
| 97 |
+
return pb.Money{}, ErrMismatchingCurrency
|
| 98 |
+
}
|
| 99 |
+
units := l.GetUnits() + r.GetUnits()
|
| 100 |
+
nanos := l.GetNanos() + r.GetNanos()
|
| 101 |
+
|
| 102 |
+
if (units == 0 && nanos == 0) || (units > 0 && nanos >= 0) || (units < 0 && nanos <= 0) {
|
| 103 |
+
// same sign <units, nanos>
|
| 104 |
+
units += int64(nanos / nanosMod)
|
| 105 |
+
nanos = nanos % nanosMod
|
| 106 |
+
} else {
|
| 107 |
+
// different sign. nanos guaranteed to not to go over the limit
|
| 108 |
+
if units > 0 {
|
| 109 |
+
units--
|
| 110 |
+
nanos += nanosMod
|
| 111 |
+
} else {
|
| 112 |
+
units++
|
| 113 |
+
nanos -= nanosMod
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return pb.Money{
|
| 118 |
+
Units: units,
|
| 119 |
+
Nanos: nanos,
|
| 120 |
+
CurrencyCode: l.GetCurrencyCode()}, nil
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// MultiplySlow is a slow multiplication operation done through adding the value
|
| 124 |
+
// to itself n-1 times.
|
| 125 |
+
func MultiplySlow(m pb.Money, n uint32) pb.Money {
|
| 126 |
+
out := m
|
| 127 |
+
for n > 1 {
|
| 128 |
+
out = Must(Sum(out, m))
|
| 129 |
+
n--
|
| 130 |
+
}
|
| 131 |
+
return out
|
| 132 |
+
}
|
benchmark/boutique/codedefect/32/code/currencyservice/client.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
*
|
| 3 |
+
* Copyright 2015 gRPC authors.
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
* you may not use this file except in compliance with the License.
|
| 7 |
+
* You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*
|
| 17 |
+
*/
|
| 18 |
+
require('@google-cloud/trace-agent').start();
|
| 19 |
+
|
| 20 |
+
const path = require('path');
|
| 21 |
+
const grpc = require('grpc');
|
| 22 |
+
const pino = require('pino');
|
| 23 |
+
|
| 24 |
+
const PROTO_PATH = path.join(__dirname, './proto/demo.proto');
|
| 25 |
+
const PORT = 7000;
|
| 26 |
+
|
| 27 |
+
const shopProto = grpc.load(PROTO_PATH).hipstershop;
|
| 28 |
+
const client = new shopProto.CurrencyService(`localhost:${PORT}`,
|
| 29 |
+
grpc.credentials.createInsecure());
|
| 30 |
+
|
| 31 |
+
const logger = pino({
|
| 32 |
+
name: 'currencyservice-client',
|
| 33 |
+
messageKey: 'message',
|
| 34 |
+
formatters: {
|
| 35 |
+
level (logLevelString, logLevelNum) {
|
| 36 |
+
return { severity: logLevelString }
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
const request = {
|
| 42 |
+
from: {
|
| 43 |
+
currency_code: 'CHF',
|
| 44 |
+
units: 300,
|
| 45 |
+
nanos: 0
|
| 46 |
+
},
|
| 47 |
+
to_code: 'EUR'
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
function _moneyToString (m) {
|
| 51 |
+
return `${m.units}.${m.nanos.toString().padStart(9,'0')} ${m.currency_code}`;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
client.getSupportedCurrencies({}, (err, response) => {
|
| 55 |
+
if (err) {
|
| 56 |
+
logger.error(`Error in getSupportedCurrencies: ${err}`);
|
| 57 |
+
} else {
|
| 58 |
+
logger.info(`Currency codes: ${response.currency_codes}`);
|
| 59 |
+
}
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
client.convert(request, (err, response) => {
|
| 63 |
+
if (err) {
|
| 64 |
+
logger.error(`Error in convert: ${err}`);
|
| 65 |
+
} else {
|
| 66 |
+
logger.log(`Convert: ${_moneyToString(request.from)} to ${_moneyToString(response)}`);
|
| 67 |
+
}
|
| 68 |
+
});
|
benchmark/boutique/codedefect/32/code/currencyservice/server.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2018 Google LLC.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
const pino = require('pino');
|
| 18 |
+
const logger = pino({
|
| 19 |
+
name: 'currencyservice-server',
|
| 20 |
+
messageKey: 'message',
|
| 21 |
+
formatters: {
|
| 22 |
+
level (logLevelString, logLevelNum) {
|
| 23 |
+
return { severity: logLevelString }
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
if(process.env.DISABLE_PROFILER) {
|
| 29 |
+
logger.info("Profiler disabled.")
|
| 30 |
+
}
|
| 31 |
+
else {
|
| 32 |
+
logger.info("Profiler enabled.")
|
| 33 |
+
require('@google-cloud/profiler').start({
|
| 34 |
+
serviceContext: {
|
| 35 |
+
service: 'currencyservice',
|
| 36 |
+
version: '1.0.0'
|
| 37 |
+
}
|
| 38 |
+
});
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Register GRPC OTel Instrumentation for trace propagation
|
| 42 |
+
// regardless of whether tracing is emitted.
|
| 43 |
+
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
|
| 44 |
+
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
|
| 45 |
+
|
| 46 |
+
registerInstrumentations({
|
| 47 |
+
instrumentations: [new GrpcInstrumentation()]
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
if(process.env.ENABLE_TRACING == "1") {
|
| 51 |
+
logger.info("Tracing enabled.")
|
| 52 |
+
|
| 53 |
+
const { resourceFromAttributes } = require('@opentelemetry/resources');
|
| 54 |
+
|
| 55 |
+
const { ATTR_SERVICE_NAME } = require('@opentelemetry/semantic-conventions');
|
| 56 |
+
|
| 57 |
+
const opentelemetry = require('@opentelemetry/sdk-node');
|
| 58 |
+
|
| 59 |
+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-grpc');
|
| 60 |
+
|
| 61 |
+
const collectorUrl = process.env.COLLECTOR_SERVICE_ADDR;
|
| 62 |
+
const traceExporter = new OTLPTraceExporter({url: collectorUrl});
|
| 63 |
+
const sdk = new opentelemetry.NodeSDK({
|
| 64 |
+
resource: resourceFromAttributes({
|
| 65 |
+
[ ATTR_SERVICE_NAME ]: process.env.OTEL_SERVICE_NAME || 'currencyservice',
|
| 66 |
+
}),
|
| 67 |
+
traceExporter: traceExporter,
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
sdk.start()
|
| 71 |
+
}
|
| 72 |
+
else {
|
| 73 |
+
logger.info("Tracing disabled.")
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
const path = require('path');
|
| 77 |
+
const grpc = require('@grpc/grpc-js');
|
| 78 |
+
const protoLoader = require('@grpc/proto-loader');
|
| 79 |
+
|
| 80 |
+
const MAIN_PROTO_PATH = path.join(__dirname, './proto/demo.proto');
|
| 81 |
+
const HEALTH_PROTO_PATH = path.join(__dirname, './proto/grpc/health/v1/health.proto');
|
| 82 |
+
|
| 83 |
+
const PORT = process.env.PORT;
|
| 84 |
+
|
| 85 |
+
const shopProto = _loadProto(MAIN_PROTO_PATH).hipstershop;
|
| 86 |
+
const healthProto = _loadProto(HEALTH_PROTO_PATH).grpc.health.v1;
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Helper function that loads a protobuf file.
|
| 90 |
+
*/
|
| 91 |
+
function _loadProto (path) {
|
| 92 |
+
const packageDefinition = protoLoader.loadSync(
|
| 93 |
+
path,
|
| 94 |
+
{
|
| 95 |
+
keepCase: true,
|
| 96 |
+
longs: String,
|
| 97 |
+
enums: String,
|
| 98 |
+
defaults: true,
|
| 99 |
+
oneofs: true
|
| 100 |
+
}
|
| 101 |
+
);
|
| 102 |
+
return grpc.loadPackageDefinition(packageDefinition);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Helper function that gets currency data from a stored JSON file
|
| 107 |
+
* Uses public data from European Central Bank
|
| 108 |
+
*/
|
| 109 |
+
function _getCurrencyData (callback) {
|
| 110 |
+
const data = require('./data/currency_conversion.json');
|
| 111 |
+
callback(data);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Helper function that handles decimal/fractional carrying
|
| 116 |
+
*/
|
| 117 |
+
function _carry (amount) {
|
| 118 |
+
const fractionSize = Math.pow(10, 9);
|
| 119 |
+
amount.nanos += (amount.units % 1) * fractionSize;
|
| 120 |
+
amount.units = Math.floor(amount.units) + Math.floor(amount.nanos / fractionSize);
|
| 121 |
+
amount.nanos = amount.nanos % fractionSize;
|
| 122 |
+
return amount;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Lists the supported currencies
|
| 127 |
+
*/
|
| 128 |
+
function getSupportedCurrencies (call, callback) {
|
| 129 |
+
logger.info('Getting supported currencies...');
|
| 130 |
+
_getCurrencyData((data) => {
|
| 131 |
+
callback(null, {currency_codes: Object.keys(data)});
|
| 132 |
+
});
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Converts between currencies
|
| 137 |
+
*/
|
| 138 |
+
function convert (call, callback) {
|
| 139 |
+
try {
|
| 140 |
+
_getCurrencyData((data) => {
|
| 141 |
+
const request = call.request;
|
| 142 |
+
|
| 143 |
+
// Convert: from_currency --> EUR
|
| 144 |
+
const from = request.from;
|
| 145 |
+
const euros = _carry({
|
| 146 |
+
units: from.units / data[from.currency_code],
|
| 147 |
+
nanos: from.nanos / data[from.currency_code]
|
| 148 |
+
});
|
| 149 |
+
|
| 150 |
+
euros.nanos = Math.round(euros.nanos);
|
| 151 |
+
|
| 152 |
+
// Convert: EUR --> to_currency
|
| 153 |
+
const result = _carry({
|
| 154 |
+
units: euros.units * data[request.to_code],
|
| 155 |
+
nanos: euros.nanos * data[request.to_code]
|
| 156 |
+
});
|
| 157 |
+
|
| 158 |
+
result.units = Math.floor(result.units);
|
| 159 |
+
result.nanos = Math.floor(result.nanos);
|
| 160 |
+
result.currency_code = request.to_code;
|
| 161 |
+
|
| 162 |
+
logger.info(`conversion request successful`);
|
| 163 |
+
callback(null, result);
|
| 164 |
+
});
|
| 165 |
+
} catch (err) {
|
| 166 |
+
logger.error(`conversion request failed: ${err}`);
|
| 167 |
+
callback(err.message);
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/**
|
| 172 |
+
* Endpoint for health checks
|
| 173 |
+
*/
|
| 174 |
+
function check (call, callback) {
|
| 175 |
+
callback(null, { status: 'SERVING' });
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* Starts an RPC server that receives requests for the
|
| 180 |
+
* CurrencyConverter service at the sample server port
|
| 181 |
+
*/
|
| 182 |
+
function main () {
|
| 183 |
+
logger.info(`Starting gRPC server on port ${PORT}...`);
|
| 184 |
+
const server = new grpc.Server();
|
| 185 |
+
server.addService(shopProto.CurrencyService.service, {getSupportedCurrencies, convert});
|
| 186 |
+
server.addService(healthProto.Health.service, {check});
|
| 187 |
+
|
| 188 |
+
server.bindAsync(
|
| 189 |
+
`[::]:${PORT}`,
|
| 190 |
+
grpc.ServerCredentials.createInsecure(),
|
| 191 |
+
function() {
|
| 192 |
+
logger.info(`CurrencyService gRPC server started on port ${PORT}`);
|
| 193 |
+
server.start();
|
| 194 |
+
},
|
| 195 |
+
);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
main();
|
benchmark/boutique/codedefect/32/code/emailservice/email_client.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2018 Google LLC
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
|
| 17 |
+
import grpc
|
| 18 |
+
|
| 19 |
+
import demo_pb2
|
| 20 |
+
import demo_pb2_grpc
|
| 21 |
+
|
| 22 |
+
from logger import getJSONLogger
|
| 23 |
+
logger = getJSONLogger('emailservice-client')
|
| 24 |
+
|
| 25 |
+
def send_confirmation_email(email, order):
|
| 26 |
+
channel = grpc.insecure_channel('[::]:8080')
|
| 27 |
+
stub = demo_pb2_grpc.EmailServiceStub(channel)
|
| 28 |
+
try:
|
| 29 |
+
response = stub.SendOrderConfirmation(demo_pb2.SendOrderConfirmationRequest(
|
| 30 |
+
email = email,
|
| 31 |
+
order = order
|
| 32 |
+
))
|
| 33 |
+
logger.info('Request sent.')
|
| 34 |
+
except grpc.RpcError as err:
|
| 35 |
+
logger.error(err.details())
|
| 36 |
+
logger.error('{}, {}'.format(err.code().name, err.code().value))
|
| 37 |
+
|
| 38 |
+
if __name__ == '__main__':
|
| 39 |
+
logger.info('Client for email service.')
|
benchmark/boutique/codedefect/32/code/emailservice/email_server.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2018 Google LLC
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
|
| 17 |
+
from concurrent import futures
|
| 18 |
+
import argparse
|
| 19 |
+
import os
|
| 20 |
+
import sys
|
| 21 |
+
import time
|
| 22 |
+
import grpc
|
| 23 |
+
import traceback
|
| 24 |
+
from jinja2 import Environment, FileSystemLoader, select_autoescape, TemplateError
|
| 25 |
+
from google.api_core.exceptions import GoogleAPICallError
|
| 26 |
+
from google.auth.exceptions import DefaultCredentialsError
|
| 27 |
+
|
| 28 |
+
import demo_pb2
|
| 29 |
+
import demo_pb2_grpc
|
| 30 |
+
from grpc_health.v1 import health_pb2
|
| 31 |
+
from grpc_health.v1 import health_pb2_grpc
|
| 32 |
+
|
| 33 |
+
from opentelemetry import trace
|
| 34 |
+
from opentelemetry.instrumentation.grpc import GrpcInstrumentorServer
|
| 35 |
+
from opentelemetry.sdk.trace import TracerProvider
|
| 36 |
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
| 37 |
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
| 38 |
+
|
| 39 |
+
# @TODO: Temporarily removed in https://github.com/GoogleCloudPlatform/microservices-demo/pull/3196
|
| 40 |
+
# import googlecloudprofiler
|
| 41 |
+
|
| 42 |
+
from logger import getJSONLogger
|
| 43 |
+
logger = getJSONLogger('emailservice-server')
|
| 44 |
+
|
| 45 |
+
# Loads confirmation email template from file
|
| 46 |
+
env = Environment(
|
| 47 |
+
loader=FileSystemLoader('templates'),
|
| 48 |
+
autoescape=select_autoescape(['html', 'xml'])
|
| 49 |
+
)
|
| 50 |
+
template = env.get_template('confirmation.html')
|
| 51 |
+
|
| 52 |
+
class BaseEmailService(demo_pb2_grpc.EmailServiceServicer):
|
| 53 |
+
def Check(self, request, context):
|
| 54 |
+
return health_pb2.HealthCheckResponse(
|
| 55 |
+
status=health_pb2.HealthCheckResponse.SERVING)
|
| 56 |
+
|
| 57 |
+
def Watch(self, request, context):
|
| 58 |
+
return health_pb2.HealthCheckResponse(
|
| 59 |
+
status=health_pb2.HealthCheckResponse.UNIMPLEMENTED)
|
| 60 |
+
|
| 61 |
+
class EmailService(BaseEmailService):
|
| 62 |
+
def __init__(self):
|
| 63 |
+
raise Exception('cloud mail client not implemented')
|
| 64 |
+
super().__init__()
|
| 65 |
+
|
| 66 |
+
@staticmethod
|
| 67 |
+
def send_email(client, email_address, content):
|
| 68 |
+
response = client.send_message(
|
| 69 |
+
sender = client.sender_path(project_id, region, sender_id),
|
| 70 |
+
envelope_from_authority = '',
|
| 71 |
+
header_from_authority = '',
|
| 72 |
+
envelope_from_address = from_address,
|
| 73 |
+
simple_message = {
|
| 74 |
+
"from": {
|
| 75 |
+
"address_spec": from_address,
|
| 76 |
+
},
|
| 77 |
+
"to": [{
|
| 78 |
+
"address_spec": email_address
|
| 79 |
+
}],
|
| 80 |
+
"subject": "Your Confirmation Email",
|
| 81 |
+
"html_body": content
|
| 82 |
+
}
|
| 83 |
+
)
|
| 84 |
+
logger.info("Message sent: {}".format(response.rfc822_message_id))
|
| 85 |
+
|
| 86 |
+
def SendOrderConfirmation(self, request, context):
|
| 87 |
+
email = request.email
|
| 88 |
+
order = request.order
|
| 89 |
+
|
| 90 |
+
try:
|
| 91 |
+
confirmation = template.render(order = order)
|
| 92 |
+
except TemplateError as err:
|
| 93 |
+
context.set_details("An error occurred when preparing the confirmation mail.")
|
| 94 |
+
logger.error(err.message)
|
| 95 |
+
context.set_code(grpc.StatusCode.INTERNAL)
|
| 96 |
+
return demo_pb2.Empty()
|
| 97 |
+
|
| 98 |
+
try:
|
| 99 |
+
EmailService.send_email(self.client, email, confirmation)
|
| 100 |
+
except GoogleAPICallError as err:
|
| 101 |
+
context.set_details("An error occurred when sending the email.")
|
| 102 |
+
print(err.message)
|
| 103 |
+
context.set_code(grpc.StatusCode.INTERNAL)
|
| 104 |
+
return demo_pb2.Empty()
|
| 105 |
+
|
| 106 |
+
return demo_pb2.Empty()
|
| 107 |
+
|
| 108 |
+
class DummyEmailService(BaseEmailService):
|
| 109 |
+
def SendOrderConfirmation(self, request, context):
|
| 110 |
+
logger.info('A request to send order confirmation email to {} has been received.'.format(request.email))
|
| 111 |
+
return demo_pb2.Empty()
|
| 112 |
+
|
| 113 |
+
class HealthCheck():
|
| 114 |
+
def Check(self, request, context):
|
| 115 |
+
return health_pb2.HealthCheckResponse(
|
| 116 |
+
status=health_pb2.HealthCheckResponse.SERVING)
|
| 117 |
+
|
| 118 |
+
def start(dummy_mode):
|
| 119 |
+
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),)
|
| 120 |
+
service = None
|
| 121 |
+
if dummy_mode:
|
| 122 |
+
service = DummyEmailService()
|
| 123 |
+
else:
|
| 124 |
+
raise Exception('non-dummy mode not implemented yet')
|
| 125 |
+
|
| 126 |
+
demo_pb2_grpc.add_EmailServiceServicer_to_server(service, server)
|
| 127 |
+
health_pb2_grpc.add_HealthServicer_to_server(service, server)
|
| 128 |
+
|
| 129 |
+
port = os.environ.get('PORT', "8080")
|
| 130 |
+
logger.info("listening on port: "+port)
|
| 131 |
+
server.add_insecure_port('[::]:'+port)
|
| 132 |
+
server.start()
|
| 133 |
+
try:
|
| 134 |
+
while True:
|
| 135 |
+
time.sleep(3600)
|
| 136 |
+
except KeyboardInterrupt:
|
| 137 |
+
server.stop(0)
|
| 138 |
+
|
| 139 |
+
def initStackdriverProfiling():
|
| 140 |
+
project_id = None
|
| 141 |
+
try:
|
| 142 |
+
project_id = os.environ["GCP_PROJECT_ID"]
|
| 143 |
+
except KeyError:
|
| 144 |
+
# Environment variable not set
|
| 145 |
+
pass
|
| 146 |
+
|
| 147 |
+
# @TODO: Temporarily removed in https://github.com/GoogleCloudPlatform/microservices-demo/pull/3196
|
| 148 |
+
# for retry in range(1,4):
|
| 149 |
+
# try:
|
| 150 |
+
# if project_id:
|
| 151 |
+
# googlecloudprofiler.start(service='email_server', service_version='1.0.0', verbose=0, project_id=project_id)
|
| 152 |
+
# else:
|
| 153 |
+
# googlecloudprofiler.start(service='email_server', service_version='1.0.0', verbose=0)
|
| 154 |
+
# logger.info("Successfully started Stackdriver Profiler.")
|
| 155 |
+
# return
|
| 156 |
+
# except (BaseException) as exc:
|
| 157 |
+
# logger.info("Unable to start Stackdriver Profiler Python agent. " + str(exc))
|
| 158 |
+
# if (retry < 4):
|
| 159 |
+
# logger.info("Sleeping %d to retry initializing Stackdriver Profiler"%(retry*10))
|
| 160 |
+
# time.sleep (1)
|
| 161 |
+
# else:
|
| 162 |
+
# logger.warning("Could not initialize Stackdriver Profiler after retrying, giving up")
|
| 163 |
+
return
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
if __name__ == '__main__':
|
| 167 |
+
logger.info('starting the email service in dummy mode.')
|
| 168 |
+
|
| 169 |
+
# Profiler
|
| 170 |
+
try:
|
| 171 |
+
if "DISABLE_PROFILER" in os.environ:
|
| 172 |
+
raise KeyError()
|
| 173 |
+
else:
|
| 174 |
+
logger.info("Profiler enabled.")
|
| 175 |
+
initStackdriverProfiling()
|
| 176 |
+
except KeyError:
|
| 177 |
+
logger.info("Profiler disabled.")
|
| 178 |
+
|
| 179 |
+
# Tracing
|
| 180 |
+
try:
|
| 181 |
+
if os.environ["ENABLE_TRACING"] == "1":
|
| 182 |
+
otel_endpoint = os.getenv("COLLECTOR_SERVICE_ADDR", "localhost:4317")
|
| 183 |
+
trace.set_tracer_provider(TracerProvider())
|
| 184 |
+
trace.get_tracer_provider().add_span_processor(
|
| 185 |
+
BatchSpanProcessor(
|
| 186 |
+
OTLPSpanExporter(
|
| 187 |
+
endpoint = otel_endpoint,
|
| 188 |
+
insecure = True
|
| 189 |
+
)
|
| 190 |
+
)
|
| 191 |
+
)
|
| 192 |
+
grpc_server_instrumentor = GrpcInstrumentorServer()
|
| 193 |
+
grpc_server_instrumentor.instrument()
|
| 194 |
+
|
| 195 |
+
except (KeyError, DefaultCredentialsError):
|
| 196 |
+
logger.info("Tracing disabled.")
|
| 197 |
+
except Exception as e:
|
| 198 |
+
logger.warn(f"Exception on Cloud Trace setup: {traceback.format_exc()}, tracing disabled.")
|
| 199 |
+
|
| 200 |
+
start(dummy_mode = True)
|
benchmark/boutique/codedefect/32/code/emailservice/logger.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2018 Google LLC
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
|
| 17 |
+
import logging
|
| 18 |
+
import sys
|
| 19 |
+
from pythonjsonlogger import jsonlogger
|
| 20 |
+
|
| 21 |
+
# TODO(yoshifumi) this class is duplicated since other Python services are
|
| 22 |
+
# not sharing the modules for logging.
|
| 23 |
+
class CustomJsonFormatter(jsonlogger.JsonFormatter):
|
| 24 |
+
def add_fields(self, log_record, record, message_dict):
|
| 25 |
+
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
|
| 26 |
+
if not log_record.get('timestamp'):
|
| 27 |
+
log_record['timestamp'] = record.created
|
| 28 |
+
if log_record.get('severity'):
|
| 29 |
+
log_record['severity'] = log_record['severity'].upper()
|
| 30 |
+
else:
|
| 31 |
+
log_record['severity'] = record.levelname
|
| 32 |
+
|
| 33 |
+
def getJSONLogger(name):
|
| 34 |
+
logger = logging.getLogger(name)
|
| 35 |
+
handler = logging.StreamHandler(sys.stdout)
|
| 36 |
+
formatter = CustomJsonFormatter('%(timestamp)s %(severity)s %(name)s %(message)s')
|
| 37 |
+
handler.setFormatter(formatter)
|
| 38 |
+
logger.addHandler(handler)
|
| 39 |
+
logger.setLevel(logging.INFO)
|
| 40 |
+
logger.propagate = False
|
| 41 |
+
return logger
|
benchmark/boutique/codedefect/32/code/frontend/deployment_details.go
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"net/http"
|
| 5 |
+
"os"
|
| 6 |
+
"time"
|
| 7 |
+
|
| 8 |
+
"cloud.google.com/go/compute/metadata"
|
| 9 |
+
"github.com/sirupsen/logrus"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
var deploymentDetailsMap map[string]string
|
| 13 |
+
var log *logrus.Logger
|
| 14 |
+
|
| 15 |
+
func init() {
|
| 16 |
+
initializeLogger()
|
| 17 |
+
// Use a goroutine to ensure loadDeploymentDetails()'s GCP API
|
| 18 |
+
// calls don't block non-GCP deployments. See issue #685.
|
| 19 |
+
go loadDeploymentDetails()
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
func initializeLogger() {
|
| 23 |
+
log = logrus.New()
|
| 24 |
+
log.Level = logrus.DebugLevel
|
| 25 |
+
log.Formatter = &logrus.JSONFormatter{
|
| 26 |
+
FieldMap: logrus.FieldMap{
|
| 27 |
+
logrus.FieldKeyTime: "timestamp",
|
| 28 |
+
logrus.FieldKeyLevel: "severity",
|
| 29 |
+
logrus.FieldKeyMsg: "message",
|
| 30 |
+
},
|
| 31 |
+
TimestampFormat: time.RFC3339Nano,
|
| 32 |
+
}
|
| 33 |
+
log.Out = os.Stdout
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
func loadDeploymentDetails() {
|
| 37 |
+
deploymentDetailsMap = make(map[string]string)
|
| 38 |
+
var metaServerClient = metadata.NewClient(&http.Client{})
|
| 39 |
+
|
| 40 |
+
podHostname, err := os.Hostname()
|
| 41 |
+
if err != nil {
|
| 42 |
+
log.Error("Failed to fetch the hostname for the Pod", err)
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
podCluster, err := metaServerClient.InstanceAttributeValue("cluster-name")
|
| 46 |
+
if err != nil {
|
| 47 |
+
log.Error("Failed to fetch the name of the cluster in which the pod is running", err)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
podZone, err := metaServerClient.Zone()
|
| 51 |
+
if err != nil {
|
| 52 |
+
log.Error("Failed to fetch the Zone of the node where the pod is scheduled", err)
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
deploymentDetailsMap["HOSTNAME"] = podHostname
|
| 56 |
+
deploymentDetailsMap["CLUSTERNAME"] = podCluster
|
| 57 |
+
deploymentDetailsMap["ZONE"] = podZone
|
| 58 |
+
|
| 59 |
+
log.WithFields(logrus.Fields{
|
| 60 |
+
"cluster": podCluster,
|
| 61 |
+
"zone": podZone,
|
| 62 |
+
"hostname": podHostname,
|
| 63 |
+
}).Debug("Loaded deployment details")
|
| 64 |
+
}
|
benchmark/boutique/codedefect/32/code/frontend/handlers.go
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"context"
|
| 19 |
+
"encoding/json"
|
| 20 |
+
"fmt"
|
| 21 |
+
"html/template"
|
| 22 |
+
"io"
|
| 23 |
+
"math/rand"
|
| 24 |
+
"net"
|
| 25 |
+
"net/http"
|
| 26 |
+
"os"
|
| 27 |
+
"strconv"
|
| 28 |
+
"strings"
|
| 29 |
+
"time"
|
| 30 |
+
|
| 31 |
+
"github.com/gorilla/mux"
|
| 32 |
+
"github.com/pkg/errors"
|
| 33 |
+
"github.com/sirupsen/logrus"
|
| 34 |
+
|
| 35 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/frontend/genproto"
|
| 36 |
+
"github.com/GoogleCloudPlatform/microservices-demo/src/frontend/money"
|
| 37 |
+
"github.com/GoogleCloudPlatform/microservices-demo/src/frontend/validator"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
type platformDetails struct {
|
| 41 |
+
css string
|
| 42 |
+
provider string
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
var (
|
| 46 |
+
frontendMessage = strings.TrimSpace(os.Getenv("FRONTEND_MESSAGE"))
|
| 47 |
+
isCymbalBrand = "true" == strings.ToLower(os.Getenv("CYMBAL_BRANDING"))
|
| 48 |
+
assistantEnabled = "true" == strings.ToLower(os.Getenv("ENABLE_ASSISTANT"))
|
| 49 |
+
templates = template.Must(template.New("").
|
| 50 |
+
Funcs(template.FuncMap{
|
| 51 |
+
"renderMoney": renderMoney,
|
| 52 |
+
"renderCurrencyLogo": renderCurrencyLogo,
|
| 53 |
+
}).ParseGlob("templates/*.html"))
|
| 54 |
+
plat platformDetails
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
var validEnvs = []string{"local", "gcp", "azure", "aws", "onprem", "alibaba"}
|
| 58 |
+
|
| 59 |
+
func (fe *frontendServer) homeHandler(w http.ResponseWriter, r *http.Request) {
|
| 60 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 61 |
+
log.WithField("currency", currentCurrency(r)).Info("home")
|
| 62 |
+
currencies, err := fe.getCurrencies(r.Context())
|
| 63 |
+
if err != nil {
|
| 64 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
|
| 65 |
+
return
|
| 66 |
+
}
|
| 67 |
+
products, err := fe.getProducts(r.Context())
|
| 68 |
+
if err != nil {
|
| 69 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve products"), http.StatusInternalServerError)
|
| 70 |
+
return
|
| 71 |
+
}
|
| 72 |
+
cart, err := fe.getCart(r.Context(), sessionID(r))
|
| 73 |
+
if err != nil {
|
| 74 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve cart"), http.StatusInternalServerError)
|
| 75 |
+
return
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
type productView struct {
|
| 79 |
+
Item *pb.Product
|
| 80 |
+
Price *pb.Money
|
| 81 |
+
}
|
| 82 |
+
ps := make([]productView, len(products))
|
| 83 |
+
for i, p := range products {
|
| 84 |
+
price, err := fe.convertCurrency(r.Context(), p.GetPriceUsd(), currentCurrency(r))
|
| 85 |
+
if err != nil {
|
| 86 |
+
renderHTTPError(log, r, w, errors.Wrapf(err, "failed to do currency conversion for product %s", p.GetId()), http.StatusInternalServerError)
|
| 87 |
+
return
|
| 88 |
+
}
|
| 89 |
+
ps[i] = productView{p, price}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// Set ENV_PLATFORM (default to local if not set; use env var if set; otherwise detect GCP, which overrides env)_
|
| 93 |
+
var env = os.Getenv("ENV_PLATFORM")
|
| 94 |
+
// Only override from env variable if set + valid env
|
| 95 |
+
if env == "" || stringinSlice(validEnvs, env) == false {
|
| 96 |
+
fmt.Println("env platform is either empty or invalid")
|
| 97 |
+
env = "local"
|
| 98 |
+
}
|
| 99 |
+
// Autodetect GCP
|
| 100 |
+
addrs, err := net.LookupHost("metadata.google.internal.")
|
| 101 |
+
if err == nil && len(addrs) >= 0 {
|
| 102 |
+
log.Debugf("Detected Google metadata server: %v, setting ENV_PLATFORM to GCP.", addrs)
|
| 103 |
+
env = "gcp"
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
log.Debugf("ENV_PLATFORM is: %s", env)
|
| 107 |
+
plat = platformDetails{}
|
| 108 |
+
plat.setPlatformDetails(strings.ToLower(env))
|
| 109 |
+
|
| 110 |
+
if err := templates.ExecuteTemplate(w, "home", injectCommonTemplateData(r, map[string]interface{}{
|
| 111 |
+
"show_currency": true,
|
| 112 |
+
"currencies": currencies,
|
| 113 |
+
"products": ps,
|
| 114 |
+
"cart_size": cartSize(cart),
|
| 115 |
+
"banner_color": os.Getenv("BANNER_COLOR"), // illustrates canary deployments
|
| 116 |
+
"ad": fe.chooseAd(r.Context(), []string{}, log),
|
| 117 |
+
})); err != nil {
|
| 118 |
+
log.Error(err)
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
func (plat *platformDetails) setPlatformDetails(env string) {
|
| 123 |
+
if env == "aws" {
|
| 124 |
+
plat.provider = "AWS"
|
| 125 |
+
plat.css = "aws-platform"
|
| 126 |
+
} else if env == "onprem" {
|
| 127 |
+
plat.provider = "On-Premises"
|
| 128 |
+
plat.css = "onprem-platform"
|
| 129 |
+
} else if env == "azure" {
|
| 130 |
+
plat.provider = "Azure"
|
| 131 |
+
plat.css = "azure-platform"
|
| 132 |
+
} else if env == "gcp" {
|
| 133 |
+
plat.provider = "Google Cloud"
|
| 134 |
+
plat.css = "gcp-platform"
|
| 135 |
+
} else if env == "alibaba" {
|
| 136 |
+
plat.provider = "Alibaba Cloud"
|
| 137 |
+
plat.css = "alibaba-platform"
|
| 138 |
+
} else {
|
| 139 |
+
plat.provider = "local"
|
| 140 |
+
plat.css = "local"
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
func (fe *frontendServer) productHandler(w http.ResponseWriter, r *http.Request) {
|
| 145 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 146 |
+
id := mux.Vars(r)["id"]
|
| 147 |
+
if id == "" {
|
| 148 |
+
renderHTTPError(log, r, w, errors.New("product id not specified"), http.StatusBadRequest)
|
| 149 |
+
return
|
| 150 |
+
}
|
| 151 |
+
log.WithField("id", id).WithField("currency", currentCurrency(r)).
|
| 152 |
+
Debug("serving product page")
|
| 153 |
+
|
| 154 |
+
p, err := fe.getProduct(r.Context(), id)
|
| 155 |
+
if err != nil {
|
| 156 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve product"), http.StatusInternalServerError)
|
| 157 |
+
return
|
| 158 |
+
}
|
| 159 |
+
currencies, err := fe.getCurrencies(r.Context())
|
| 160 |
+
if err != nil {
|
| 161 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
|
| 162 |
+
return
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
cart, err := fe.getCart(r.Context(), sessionID(r))
|
| 166 |
+
if err != nil {
|
| 167 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve cart"), http.StatusInternalServerError)
|
| 168 |
+
return
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
price, err := fe.convertCurrency(r.Context(), p.GetPriceUsd(), currentCurrency(r))
|
| 172 |
+
if err != nil {
|
| 173 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to convert currency"), http.StatusInternalServerError)
|
| 174 |
+
return
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// ignores the error retrieving recommendations since it is not critical
|
| 178 |
+
recommendations, err := fe.getRecommendations(r.Context(), sessionID(r), []string{id})
|
| 179 |
+
if err != nil {
|
| 180 |
+
log.WithField("error", err).Warn("failed to get product recommendations")
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
product := struct {
|
| 184 |
+
Item *pb.Product
|
| 185 |
+
Price *pb.Money
|
| 186 |
+
}{p, price}
|
| 187 |
+
|
| 188 |
+
// Fetch packaging info (weight/dimensions) of the product
|
| 189 |
+
// The packaging service is an optional microservice you can run as part of a Google Cloud demo.
|
| 190 |
+
var packagingInfo *PackagingInfo = nil
|
| 191 |
+
if isPackagingServiceConfigured() {
|
| 192 |
+
packagingInfo, err = httpGetPackagingInfo(id)
|
| 193 |
+
if err != nil {
|
| 194 |
+
fmt.Println("Failed to obtain product's packaging info:", err)
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
if err := templates.ExecuteTemplate(w, "product", injectCommonTemplateData(r, map[string]interface{}{
|
| 199 |
+
"ad": fe.chooseAd(r.Context(), p.Categories, log),
|
| 200 |
+
"show_currency": true,
|
| 201 |
+
"currencies": currencies,
|
| 202 |
+
"product": product,
|
| 203 |
+
"recommendations": recommendations,
|
| 204 |
+
"cart_size": cartSize(cart),
|
| 205 |
+
"packagingInfo": packagingInfo,
|
| 206 |
+
})); err != nil {
|
| 207 |
+
log.Println(err)
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
func (fe *frontendServer) addToCartHandler(w http.ResponseWriter, r *http.Request) {
|
| 212 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 213 |
+
quantity, _ := strconv.ParseUint(r.FormValue("quantity"), 10, 32)
|
| 214 |
+
productID := r.FormValue("product_id")
|
| 215 |
+
payload := validator.AddToCartPayload{
|
| 216 |
+
Quantity: quantity,
|
| 217 |
+
ProductID: productID,
|
| 218 |
+
}
|
| 219 |
+
if err := payload.Validate(); err != nil {
|
| 220 |
+
renderHTTPError(log, r, w, validator.ValidationErrorResponse(err), http.StatusUnprocessableEntity)
|
| 221 |
+
return
|
| 222 |
+
}
|
| 223 |
+
log.WithField("product", payload.ProductID).WithField("quantity", payload.Quantity).Debug("adding to cart")
|
| 224 |
+
|
| 225 |
+
p, err := fe.getProduct(r.Context(), payload.ProductID)
|
| 226 |
+
if err != nil {
|
| 227 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve product"), http.StatusInternalServerError)
|
| 228 |
+
return
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
userID := sessionID(r)
|
| 232 |
+
productID = p.GetId()
|
| 233 |
+
userID, productID = productID, userID
|
| 234 |
+
if err := fe.insertCart(r.Context(), userID, productID, int32(payload.Quantity)); err != nil {
|
| 235 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to add to cart"), http.StatusInternalServerError)
|
| 236 |
+
return
|
| 237 |
+
}
|
| 238 |
+
w.Header().Set("location", baseUrl + "/cart")
|
| 239 |
+
w.WriteHeader(http.StatusFound)
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
func (fe *frontendServer) emptyCartHandler(w http.ResponseWriter, r *http.Request) {
|
| 243 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 244 |
+
log.Debug("emptying cart")
|
| 245 |
+
|
| 246 |
+
if err := fe.emptyCart(r.Context(), sessionID(r)); err != nil {
|
| 247 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to empty cart"), http.StatusInternalServerError)
|
| 248 |
+
return
|
| 249 |
+
}
|
| 250 |
+
w.Header().Set("location", baseUrl + "/")
|
| 251 |
+
w.WriteHeader(http.StatusFound)
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
func (fe *frontendServer) viewCartHandler(w http.ResponseWriter, r *http.Request) {
|
| 255 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 256 |
+
log.Debug("view user cart")
|
| 257 |
+
currencies, err := fe.getCurrencies(r.Context())
|
| 258 |
+
if err != nil {
|
| 259 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
|
| 260 |
+
return
|
| 261 |
+
}
|
| 262 |
+
cart, err := fe.getCart(r.Context(), sessionID(r))
|
| 263 |
+
if err != nil {
|
| 264 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve cart"), http.StatusInternalServerError)
|
| 265 |
+
return
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
// ignores the error retrieving recommendations since it is not critical
|
| 269 |
+
recommendations, err := fe.getRecommendations(r.Context(), sessionID(r), cartIDs(cart))
|
| 270 |
+
if err != nil {
|
| 271 |
+
log.WithField("error", err).Warn("failed to get product recommendations")
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
shippingCost, err := fe.getShippingQuote(r.Context(), cart, currentCurrency(r))
|
| 275 |
+
if err != nil {
|
| 276 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to get shipping quote"), http.StatusInternalServerError)
|
| 277 |
+
return
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
type cartItemView struct {
|
| 281 |
+
Item *pb.Product
|
| 282 |
+
Quantity int32
|
| 283 |
+
Price *pb.Money
|
| 284 |
+
}
|
| 285 |
+
items := make([]cartItemView, len(cart))
|
| 286 |
+
totalPrice := pb.Money{CurrencyCode: currentCurrency(r)}
|
| 287 |
+
for i, item := range cart {
|
| 288 |
+
p, err := fe.getProduct(r.Context(), item.GetProductId())
|
| 289 |
+
if err != nil {
|
| 290 |
+
renderHTTPError(log, r, w, errors.Wrapf(err, "could not retrieve product #%s", item.GetProductId()), http.StatusInternalServerError)
|
| 291 |
+
return
|
| 292 |
+
}
|
| 293 |
+
price, err := fe.convertCurrency(r.Context(), p.GetPriceUsd(), currentCurrency(r))
|
| 294 |
+
if err != nil {
|
| 295 |
+
renderHTTPError(log, r, w, errors.Wrapf(err, "could not convert currency for product #%s", item.GetProductId()), http.StatusInternalServerError)
|
| 296 |
+
return
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
multPrice := money.MultiplySlow(*price, uint32(item.GetQuantity()))
|
| 300 |
+
items[i] = cartItemView{
|
| 301 |
+
Item: p,
|
| 302 |
+
Quantity: item.GetQuantity(),
|
| 303 |
+
Price: &multPrice}
|
| 304 |
+
totalPrice = money.Must(money.Sum(totalPrice, multPrice))
|
| 305 |
+
}
|
| 306 |
+
totalPrice = money.Must(money.Sum(totalPrice, *shippingCost))
|
| 307 |
+
year := time.Now().Year()
|
| 308 |
+
|
| 309 |
+
if err := templates.ExecuteTemplate(w, "cart", injectCommonTemplateData(r, map[string]interface{}{
|
| 310 |
+
"currencies": currencies,
|
| 311 |
+
"recommendations": recommendations,
|
| 312 |
+
"cart_size": cartSize(cart),
|
| 313 |
+
"shipping_cost": shippingCost,
|
| 314 |
+
"show_currency": true,
|
| 315 |
+
"total_cost": totalPrice,
|
| 316 |
+
"items": items,
|
| 317 |
+
"expiration_years": []int{year, year + 1, year + 2, year + 3, year + 4},
|
| 318 |
+
})); err != nil {
|
| 319 |
+
log.Println(err)
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
func (fe *frontendServer) placeOrderHandler(w http.ResponseWriter, r *http.Request) {
|
| 324 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 325 |
+
log.Debug("placing order")
|
| 326 |
+
|
| 327 |
+
var (
|
| 328 |
+
email = r.FormValue("email")
|
| 329 |
+
streetAddress = r.FormValue("street_address")
|
| 330 |
+
zipCode, _ = strconv.ParseInt(r.FormValue("zip_code"), 10, 32)
|
| 331 |
+
city = r.FormValue("city")
|
| 332 |
+
state = r.FormValue("state")
|
| 333 |
+
country = r.FormValue("country")
|
| 334 |
+
ccNumber = r.FormValue("credit_card_number")
|
| 335 |
+
ccMonth, _ = strconv.ParseInt(r.FormValue("credit_card_expiration_month"), 10, 32)
|
| 336 |
+
ccYear, _ = strconv.ParseInt(r.FormValue("credit_card_expiration_year"), 10, 32)
|
| 337 |
+
ccCVV, _ = strconv.ParseInt(r.FormValue("credit_card_cvv"), 10, 32)
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
payload := validator.PlaceOrderPayload{
|
| 341 |
+
Email: email,
|
| 342 |
+
StreetAddress: streetAddress,
|
| 343 |
+
ZipCode: zipCode,
|
| 344 |
+
City: city,
|
| 345 |
+
State: state,
|
| 346 |
+
Country: country,
|
| 347 |
+
CcNumber: ccNumber,
|
| 348 |
+
CcMonth: ccMonth,
|
| 349 |
+
CcYear: ccYear,
|
| 350 |
+
CcCVV: ccCVV,
|
| 351 |
+
}
|
| 352 |
+
if err := payload.Validate(); err != nil {
|
| 353 |
+
renderHTTPError(log, r, w, validator.ValidationErrorResponse(err), http.StatusUnprocessableEntity)
|
| 354 |
+
return
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
order, err := pb.NewCheckoutServiceClient(fe.checkoutSvcConn).
|
| 358 |
+
PlaceOrder(r.Context(), &pb.PlaceOrderRequest{
|
| 359 |
+
Email: payload.Email,
|
| 360 |
+
CreditCard: &pb.CreditCardInfo{
|
| 361 |
+
CreditCardNumber: payload.CcNumber,
|
| 362 |
+
CreditCardExpirationMonth: int32(payload.CcMonth),
|
| 363 |
+
CreditCardExpirationYear: int32(payload.CcYear),
|
| 364 |
+
CreditCardCvv: int32(payload.CcCVV)},
|
| 365 |
+
UserId: sessionID(r),
|
| 366 |
+
UserCurrency: currentCurrency(r),
|
| 367 |
+
Address: &pb.Address{
|
| 368 |
+
StreetAddress: payload.StreetAddress,
|
| 369 |
+
City: payload.City,
|
| 370 |
+
State: payload.State,
|
| 371 |
+
ZipCode: int32(payload.ZipCode),
|
| 372 |
+
Country: payload.Country},
|
| 373 |
+
})
|
| 374 |
+
if err != nil {
|
| 375 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to complete the order"), http.StatusInternalServerError)
|
| 376 |
+
return
|
| 377 |
+
}
|
| 378 |
+
log.WithField("order", order.GetOrder().GetOrderId()).Info("order placed")
|
| 379 |
+
|
| 380 |
+
order.GetOrder().GetItems()
|
| 381 |
+
recommendations, _ := fe.getRecommendations(r.Context(), sessionID(r), nil)
|
| 382 |
+
|
| 383 |
+
totalPaid := *order.GetOrder().GetShippingCost()
|
| 384 |
+
for _, v := range order.GetOrder().GetItems() {
|
| 385 |
+
multPrice := money.MultiplySlow(*v.GetCost(), uint32(v.GetItem().GetQuantity()))
|
| 386 |
+
totalPaid = money.Must(money.Sum(totalPaid, multPrice))
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
currencies, err := fe.getCurrencies(r.Context())
|
| 390 |
+
if err != nil {
|
| 391 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
|
| 392 |
+
return
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
if err := templates.ExecuteTemplate(w, "order", injectCommonTemplateData(r, map[string]interface{}{
|
| 396 |
+
"show_currency": false,
|
| 397 |
+
"currencies": currencies,
|
| 398 |
+
"order": order.GetOrder(),
|
| 399 |
+
"total_paid": &totalPaid,
|
| 400 |
+
"recommendations": recommendations,
|
| 401 |
+
})); err != nil {
|
| 402 |
+
log.Println(err)
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
func (fe *frontendServer) assistantHandler(w http.ResponseWriter, r *http.Request) {
|
| 407 |
+
currencies, err := fe.getCurrencies(r.Context())
|
| 408 |
+
if err != nil {
|
| 409 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
|
| 410 |
+
return
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
if err := templates.ExecuteTemplate(w, "assistant", injectCommonTemplateData(r, map[string]interface{}{
|
| 414 |
+
"show_currency": false,
|
| 415 |
+
"currencies": currencies,
|
| 416 |
+
})); err != nil {
|
| 417 |
+
log.Println(err)
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
func (fe *frontendServer) logoutHandler(w http.ResponseWriter, r *http.Request) {
|
| 422 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 423 |
+
log.Debug("logging out")
|
| 424 |
+
for _, c := range r.Cookies() {
|
| 425 |
+
c.Expires = time.Now().Add(-time.Hour * 24 * 365)
|
| 426 |
+
c.MaxAge = -1
|
| 427 |
+
http.SetCookie(w, c)
|
| 428 |
+
}
|
| 429 |
+
w.Header().Set("Location", baseUrl + "/")
|
| 430 |
+
w.WriteHeader(http.StatusFound)
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
func (fe *frontendServer) getProductByID(w http.ResponseWriter, r *http.Request) {
|
| 434 |
+
id := mux.Vars(r)["ids"]
|
| 435 |
+
if id == "" {
|
| 436 |
+
return
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
p, err := fe.getProduct(r.Context(), id)
|
| 440 |
+
if err != nil {
|
| 441 |
+
return
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
jsonData, err := json.Marshal(p)
|
| 445 |
+
if err != nil {
|
| 446 |
+
fmt.Println(err)
|
| 447 |
+
return
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
w.Write(jsonData)
|
| 451 |
+
w.WriteHeader(http.StatusOK)
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
func (fe *frontendServer) chatBotHandler(w http.ResponseWriter, r *http.Request) {
|
| 455 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 456 |
+
type Response struct {
|
| 457 |
+
Message string `json:"message"`
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
type LLMResponse struct {
|
| 461 |
+
Content string `json:"content"`
|
| 462 |
+
Details map[string]any `json:"details"`
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
var response LLMResponse
|
| 466 |
+
|
| 467 |
+
url := "http://" + fe.shoppingAssistantSvcAddr
|
| 468 |
+
req, err := http.NewRequest(http.MethodPost, url, r.Body)
|
| 469 |
+
if err != nil {
|
| 470 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to create request"), http.StatusInternalServerError)
|
| 471 |
+
return
|
| 472 |
+
}
|
| 473 |
+
req.Header.Set("Content-Type", "application/json")
|
| 474 |
+
req.Header.Set("Accept", "application/json")
|
| 475 |
+
res, err := http.DefaultClient.Do(req)
|
| 476 |
+
if err != nil {
|
| 477 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to send request"), http.StatusInternalServerError)
|
| 478 |
+
return
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
body, err := io.ReadAll(res.Body)
|
| 482 |
+
if err != nil {
|
| 483 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to read response"), http.StatusInternalServerError)
|
| 484 |
+
return
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
fmt.Printf("%+v\n", body)
|
| 488 |
+
fmt.Printf("%+v\n", res)
|
| 489 |
+
|
| 490 |
+
err = json.Unmarshal(body, &response)
|
| 491 |
+
if err != nil {
|
| 492 |
+
renderHTTPError(log, r, w, errors.Wrap(err, "failed to unmarshal body"), http.StatusInternalServerError)
|
| 493 |
+
return
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
// respond with the same message
|
| 497 |
+
json.NewEncoder(w).Encode(Response{Message: response.Content})
|
| 498 |
+
|
| 499 |
+
w.WriteHeader(http.StatusOK)
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
func (fe *frontendServer) setCurrencyHandler(w http.ResponseWriter, r *http.Request) {
|
| 503 |
+
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
| 504 |
+
cur := r.FormValue("currency_code")
|
| 505 |
+
payload := validator.SetCurrencyPayload{Currency: cur}
|
| 506 |
+
if err := payload.Validate(); err != nil {
|
| 507 |
+
renderHTTPError(log, r, w, validator.ValidationErrorResponse(err), http.StatusUnprocessableEntity)
|
| 508 |
+
return
|
| 509 |
+
}
|
| 510 |
+
log.WithField("curr.new", payload.Currency).WithField("curr.old", currentCurrency(r)).
|
| 511 |
+
Debug("setting currency")
|
| 512 |
+
|
| 513 |
+
if payload.Currency != "" {
|
| 514 |
+
http.SetCookie(w, &http.Cookie{
|
| 515 |
+
Name: cookieCurrency,
|
| 516 |
+
Value: payload.Currency,
|
| 517 |
+
MaxAge: cookieMaxAge,
|
| 518 |
+
})
|
| 519 |
+
}
|
| 520 |
+
referer := r.Header.Get("referer")
|
| 521 |
+
if referer == "" {
|
| 522 |
+
referer = baseUrl + "/"
|
| 523 |
+
}
|
| 524 |
+
w.Header().Set("Location", referer)
|
| 525 |
+
w.WriteHeader(http.StatusFound)
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
// chooseAd queries for advertisements available and randomly chooses one, if
|
| 529 |
+
// available. It ignores the error retrieving the ad since it is not critical.
|
| 530 |
+
func (fe *frontendServer) chooseAd(ctx context.Context, ctxKeys []string, log logrus.FieldLogger) *pb.Ad {
|
| 531 |
+
ads, err := fe.getAd(ctx, ctxKeys)
|
| 532 |
+
if err != nil {
|
| 533 |
+
log.WithField("error", err).Warn("failed to retrieve ads")
|
| 534 |
+
return nil
|
| 535 |
+
}
|
| 536 |
+
return ads[rand.Intn(len(ads))]
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
func renderHTTPError(log logrus.FieldLogger, r *http.Request, w http.ResponseWriter, err error, code int) {
|
| 540 |
+
log.WithField("error", err).Error("request error")
|
| 541 |
+
errMsg := fmt.Sprintf("%+v", err)
|
| 542 |
+
|
| 543 |
+
w.WriteHeader(code)
|
| 544 |
+
|
| 545 |
+
if templateErr := templates.ExecuteTemplate(w, "error", injectCommonTemplateData(r, map[string]interface{}{
|
| 546 |
+
"error": errMsg,
|
| 547 |
+
"status_code": code,
|
| 548 |
+
"status": http.StatusText(code),
|
| 549 |
+
})); templateErr != nil {
|
| 550 |
+
log.Println(templateErr)
|
| 551 |
+
}
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
func injectCommonTemplateData(r *http.Request, payload map[string]interface{}) map[string]interface{} {
|
| 555 |
+
data := map[string]interface{}{
|
| 556 |
+
"session_id": sessionID(r),
|
| 557 |
+
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
| 558 |
+
"user_currency": currentCurrency(r),
|
| 559 |
+
"platform_css": plat.css,
|
| 560 |
+
"platform_name": plat.provider,
|
| 561 |
+
"is_cymbal_brand": isCymbalBrand,
|
| 562 |
+
"assistant_enabled": assistantEnabled,
|
| 563 |
+
"deploymentDetails": deploymentDetailsMap,
|
| 564 |
+
"frontendMessage": frontendMessage,
|
| 565 |
+
"currentYear": time.Now().Year(),
|
| 566 |
+
"baseUrl": baseUrl,
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
for k, v := range payload {
|
| 570 |
+
data[k] = v
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
return data
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
func currentCurrency(r *http.Request) string {
|
| 577 |
+
c, _ := r.Cookie(cookieCurrency)
|
| 578 |
+
if c != nil {
|
| 579 |
+
return c.Value
|
| 580 |
+
}
|
| 581 |
+
return defaultCurrency
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
func sessionID(r *http.Request) string {
|
| 585 |
+
v := r.Context().Value(ctxKeySessionID{})
|
| 586 |
+
if v != nil {
|
| 587 |
+
return v.(string)
|
| 588 |
+
}
|
| 589 |
+
return ""
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
func cartIDs(c []*pb.CartItem) []string {
|
| 593 |
+
out := make([]string, len(c))
|
| 594 |
+
for i, v := range c {
|
| 595 |
+
out[i] = v.GetProductId()
|
| 596 |
+
}
|
| 597 |
+
return out
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
// get total # of items in cart
|
| 601 |
+
func cartSize(c []*pb.CartItem) int {
|
| 602 |
+
cartSize := 0
|
| 603 |
+
for _, item := range c {
|
| 604 |
+
cartSize += int(item.GetQuantity())
|
| 605 |
+
}
|
| 606 |
+
return cartSize
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
func renderMoney(money pb.Money) string {
|
| 610 |
+
currencyLogo := renderCurrencyLogo(money.GetCurrencyCode())
|
| 611 |
+
return fmt.Sprintf("%s%d.%02d", currencyLogo, money.GetUnits(), money.GetNanos()/10000000)
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
func renderCurrencyLogo(currencyCode string) string {
|
| 615 |
+
logos := map[string]string{
|
| 616 |
+
"USD": "$",
|
| 617 |
+
"CAD": "$",
|
| 618 |
+
"JPY": "¥",
|
| 619 |
+
"EUR": "€",
|
| 620 |
+
"TRY": "₺",
|
| 621 |
+
"GBP": "£",
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
logo := "$" //default
|
| 625 |
+
if val, ok := logos[currencyCode]; ok {
|
| 626 |
+
logo = val
|
| 627 |
+
}
|
| 628 |
+
return logo
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
func stringinSlice(slice []string, val string) bool {
|
| 632 |
+
for _, item := range slice {
|
| 633 |
+
if item == val {
|
| 634 |
+
return true
|
| 635 |
+
}
|
| 636 |
+
}
|
| 637 |
+
return false
|
| 638 |
+
}
|
benchmark/boutique/codedefect/32/code/frontend/main.go
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"context"
|
| 19 |
+
"fmt"
|
| 20 |
+
"net/http"
|
| 21 |
+
"os"
|
| 22 |
+
"time"
|
| 23 |
+
|
| 24 |
+
"cloud.google.com/go/profiler"
|
| 25 |
+
"github.com/gorilla/mux"
|
| 26 |
+
"github.com/pkg/errors"
|
| 27 |
+
"github.com/sirupsen/logrus"
|
| 28 |
+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
| 29 |
+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
| 30 |
+
"go.opentelemetry.io/otel"
|
| 31 |
+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
| 32 |
+
"go.opentelemetry.io/otel/propagation"
|
| 33 |
+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
| 34 |
+
"google.golang.org/grpc"
|
| 35 |
+
"google.golang.org/grpc/credentials/insecure"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
const (
|
| 39 |
+
port = "8080"
|
| 40 |
+
defaultCurrency = "USD"
|
| 41 |
+
cookieMaxAge = 60 * 60 * 48
|
| 42 |
+
|
| 43 |
+
cookiePrefix = "shop_"
|
| 44 |
+
cookieSessionID = cookiePrefix + "session-id"
|
| 45 |
+
cookieCurrency = cookiePrefix + "currency"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
var (
|
| 49 |
+
whitelistedCurrencies = map[string]bool{
|
| 50 |
+
"USD": true,
|
| 51 |
+
"EUR": true,
|
| 52 |
+
"CAD": true,
|
| 53 |
+
"JPY": true,
|
| 54 |
+
"GBP": true,
|
| 55 |
+
"TRY": true,
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
baseUrl = ""
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
type ctxKeySessionID struct{}
|
| 62 |
+
|
| 63 |
+
type frontendServer struct {
|
| 64 |
+
productCatalogSvcAddr string
|
| 65 |
+
productCatalogSvcConn *grpc.ClientConn
|
| 66 |
+
|
| 67 |
+
currencySvcAddr string
|
| 68 |
+
currencySvcConn *grpc.ClientConn
|
| 69 |
+
|
| 70 |
+
cartSvcAddr string
|
| 71 |
+
cartSvcConn *grpc.ClientConn
|
| 72 |
+
|
| 73 |
+
recommendationSvcAddr string
|
| 74 |
+
recommendationSvcConn *grpc.ClientConn
|
| 75 |
+
|
| 76 |
+
checkoutSvcAddr string
|
| 77 |
+
checkoutSvcConn *grpc.ClientConn
|
| 78 |
+
|
| 79 |
+
shippingSvcAddr string
|
| 80 |
+
shippingSvcConn *grpc.ClientConn
|
| 81 |
+
|
| 82 |
+
adSvcAddr string
|
| 83 |
+
adSvcConn *grpc.ClientConn
|
| 84 |
+
|
| 85 |
+
collectorAddr string
|
| 86 |
+
collectorConn *grpc.ClientConn
|
| 87 |
+
|
| 88 |
+
shoppingAssistantSvcAddr string
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
func main() {
|
| 92 |
+
ctx := context.Background()
|
| 93 |
+
log := logrus.New()
|
| 94 |
+
log.Level = logrus.DebugLevel
|
| 95 |
+
log.Formatter = &logrus.JSONFormatter{
|
| 96 |
+
FieldMap: logrus.FieldMap{
|
| 97 |
+
logrus.FieldKeyTime: "timestamp",
|
| 98 |
+
logrus.FieldKeyLevel: "severity",
|
| 99 |
+
logrus.FieldKeyMsg: "message",
|
| 100 |
+
},
|
| 101 |
+
TimestampFormat: time.RFC3339Nano,
|
| 102 |
+
}
|
| 103 |
+
log.Out = os.Stdout
|
| 104 |
+
|
| 105 |
+
svc := new(frontendServer)
|
| 106 |
+
|
| 107 |
+
otel.SetTextMapPropagator(
|
| 108 |
+
propagation.NewCompositeTextMapPropagator(
|
| 109 |
+
propagation.TraceContext{}, propagation.Baggage{}))
|
| 110 |
+
|
| 111 |
+
baseUrl = os.Getenv("BASE_URL")
|
| 112 |
+
|
| 113 |
+
if os.Getenv("ENABLE_TRACING") == "1" {
|
| 114 |
+
log.Info("Tracing enabled.")
|
| 115 |
+
initTracing(log, ctx, svc)
|
| 116 |
+
} else {
|
| 117 |
+
log.Info("Tracing disabled.")
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if os.Getenv("ENABLE_PROFILER") == "1" {
|
| 121 |
+
log.Info("Profiling enabled.")
|
| 122 |
+
go initProfiling(log, "frontend", "1.0.0")
|
| 123 |
+
} else {
|
| 124 |
+
log.Info("Profiling disabled.")
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
srvPort := port
|
| 128 |
+
if os.Getenv("PORT") != "" {
|
| 129 |
+
srvPort = os.Getenv("PORT")
|
| 130 |
+
}
|
| 131 |
+
addr := os.Getenv("LISTEN_ADDR")
|
| 132 |
+
mustMapEnv(&svc.productCatalogSvcAddr, "PRODUCT_CATALOG_SERVICE_ADDR")
|
| 133 |
+
mustMapEnv(&svc.currencySvcAddr, "CURRENCY_SERVICE_ADDR")
|
| 134 |
+
mustMapEnv(&svc.cartSvcAddr, "CART_SERVICE_ADDR")
|
| 135 |
+
mustMapEnv(&svc.recommendationSvcAddr, "RECOMMENDATION_SERVICE_ADDR")
|
| 136 |
+
mustMapEnv(&svc.checkoutSvcAddr, "CHECKOUT_SERVICE_ADDR")
|
| 137 |
+
mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR")
|
| 138 |
+
mustMapEnv(&svc.adSvcAddr, "AD_SERVICE_ADDR")
|
| 139 |
+
mustMapEnv(&svc.shoppingAssistantSvcAddr, "SHOPPING_ASSISTANT_SERVICE_ADDR")
|
| 140 |
+
|
| 141 |
+
mustConnGRPC(ctx, &svc.currencySvcConn, svc.currencySvcAddr)
|
| 142 |
+
mustConnGRPC(ctx, &svc.productCatalogSvcConn, svc.productCatalogSvcAddr)
|
| 143 |
+
mustConnGRPC(ctx, &svc.cartSvcConn, svc.cartSvcAddr)
|
| 144 |
+
mustConnGRPC(ctx, &svc.recommendationSvcConn, svc.recommendationSvcAddr)
|
| 145 |
+
mustConnGRPC(ctx, &svc.shippingSvcConn, svc.shippingSvcAddr)
|
| 146 |
+
mustConnGRPC(ctx, &svc.checkoutSvcConn, svc.checkoutSvcAddr)
|
| 147 |
+
mustConnGRPC(ctx, &svc.adSvcConn, svc.adSvcAddr)
|
| 148 |
+
|
| 149 |
+
r := mux.NewRouter()
|
| 150 |
+
r.HandleFunc(baseUrl+"/", svc.homeHandler).Methods(http.MethodGet, http.MethodHead)
|
| 151 |
+
r.HandleFunc(baseUrl+"/product/{id}", svc.productHandler).Methods(http.MethodGet, http.MethodHead)
|
| 152 |
+
r.HandleFunc(baseUrl+"/cart", svc.viewCartHandler).Methods(http.MethodGet, http.MethodHead)
|
| 153 |
+
r.HandleFunc(baseUrl+"/cart", svc.addToCartHandler).Methods(http.MethodPost)
|
| 154 |
+
r.HandleFunc(baseUrl+"/cart/empty", svc.emptyCartHandler).Methods(http.MethodPost)
|
| 155 |
+
r.HandleFunc(baseUrl+"/setCurrency", svc.setCurrencyHandler).Methods(http.MethodPost)
|
| 156 |
+
r.HandleFunc(baseUrl+"/logout", svc.logoutHandler).Methods(http.MethodGet)
|
| 157 |
+
r.HandleFunc(baseUrl+"/cart/checkout", svc.placeOrderHandler).Methods(http.MethodPost)
|
| 158 |
+
r.HandleFunc(baseUrl+"/assistant", svc.assistantHandler).Methods(http.MethodGet)
|
| 159 |
+
r.PathPrefix(baseUrl + "/static/").Handler(http.StripPrefix(baseUrl+"/static/", http.FileServer(http.Dir("./static/"))))
|
| 160 |
+
r.HandleFunc(baseUrl+"/robots.txt", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "User-agent: *\nDisallow: /") })
|
| 161 |
+
r.HandleFunc(baseUrl+"/_healthz", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "ok") })
|
| 162 |
+
r.HandleFunc(baseUrl+"/product-meta/{ids}", svc.getProductByID).Methods(http.MethodGet)
|
| 163 |
+
r.HandleFunc(baseUrl+"/bot", svc.chatBotHandler).Methods(http.MethodPost)
|
| 164 |
+
|
| 165 |
+
var handler http.Handler = r
|
| 166 |
+
handler = &logHandler{log: log, next: handler} // add logging
|
| 167 |
+
handler = ensureSessionID(handler) // add session ID
|
| 168 |
+
handler = otelhttp.NewHandler(handler, "frontend") // add OTel tracing
|
| 169 |
+
|
| 170 |
+
log.Infof("starting server on %s:%s", addr, srvPort)
|
| 171 |
+
log.Fatal(http.ListenAndServe(addr+":"+srvPort, handler))
|
| 172 |
+
}
|
| 173 |
+
func initStats(log logrus.FieldLogger) {
|
| 174 |
+
// TODO(arbrown) Implement OpenTelemtry stats
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
func initTracing(log logrus.FieldLogger, ctx context.Context, svc *frontendServer) (*sdktrace.TracerProvider, error) {
|
| 178 |
+
mustMapEnv(&svc.collectorAddr, "COLLECTOR_SERVICE_ADDR")
|
| 179 |
+
mustConnGRPC(ctx, &svc.collectorConn, svc.collectorAddr)
|
| 180 |
+
exporter, err := otlptracegrpc.New(
|
| 181 |
+
ctx,
|
| 182 |
+
otlptracegrpc.WithGRPCConn(svc.collectorConn))
|
| 183 |
+
if err != nil {
|
| 184 |
+
log.Warnf("warn: Failed to create trace exporter: %v", err)
|
| 185 |
+
}
|
| 186 |
+
tp := sdktrace.NewTracerProvider(
|
| 187 |
+
sdktrace.WithBatcher(exporter),
|
| 188 |
+
sdktrace.WithSampler(sdktrace.AlwaysSample()))
|
| 189 |
+
otel.SetTracerProvider(tp)
|
| 190 |
+
|
| 191 |
+
return tp, err
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
func initProfiling(log logrus.FieldLogger, service, version string) {
|
| 195 |
+
// TODO(ahmetb) this method is duplicated in other microservices using Go
|
| 196 |
+
// since they are not sharing packages.
|
| 197 |
+
for i := 1; i <= 3; i++ {
|
| 198 |
+
log = log.WithField("retry", i)
|
| 199 |
+
if err := profiler.Start(profiler.Config{
|
| 200 |
+
Service: service,
|
| 201 |
+
ServiceVersion: version,
|
| 202 |
+
// ProjectID must be set if not running on GCP.
|
| 203 |
+
// ProjectID: "my-project",
|
| 204 |
+
}); err != nil {
|
| 205 |
+
log.Warnf("warn: failed to start profiler: %+v", err)
|
| 206 |
+
} else {
|
| 207 |
+
log.Info("started Stackdriver profiler")
|
| 208 |
+
return
|
| 209 |
+
}
|
| 210 |
+
d := time.Second * 10 * time.Duration(i)
|
| 211 |
+
log.Debugf("sleeping %v to retry initializing Stackdriver profiler", d)
|
| 212 |
+
time.Sleep(d)
|
| 213 |
+
}
|
| 214 |
+
log.Warn("warning: could not initialize Stackdriver profiler after retrying, giving up")
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
func mustMapEnv(target *string, envKey string) {
|
| 218 |
+
v := os.Getenv(envKey)
|
| 219 |
+
if v == "" {
|
| 220 |
+
panic(fmt.Sprintf("environment variable %q not set", envKey))
|
| 221 |
+
}
|
| 222 |
+
*target = v
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
func mustConnGRPC(ctx context.Context, conn **grpc.ClientConn, addr string) {
|
| 226 |
+
var err error
|
| 227 |
+
_, cancel := context.WithTimeout(ctx, time.Second*3)
|
| 228 |
+
defer cancel()
|
| 229 |
+
*conn, err = grpc.NewClient(addr,
|
| 230 |
+
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
| 231 |
+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
|
| 232 |
+
if err != nil {
|
| 233 |
+
panic(errors.Wrapf(err, "grpc: failed to connect %s", addr))
|
| 234 |
+
}
|
| 235 |
+
}
|
benchmark/boutique/codedefect/32/code/frontend/middleware.go
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"context"
|
| 19 |
+
"net/http"
|
| 20 |
+
"time"
|
| 21 |
+
"os"
|
| 22 |
+
|
| 23 |
+
"github.com/google/uuid"
|
| 24 |
+
"github.com/sirupsen/logrus"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
type ctxKeyLog struct{}
|
| 28 |
+
type ctxKeyRequestID struct{}
|
| 29 |
+
|
| 30 |
+
type logHandler struct {
|
| 31 |
+
log *logrus.Logger
|
| 32 |
+
next http.Handler
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
type responseRecorder struct {
|
| 36 |
+
b int
|
| 37 |
+
status int
|
| 38 |
+
w http.ResponseWriter
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
func (r *responseRecorder) Header() http.Header { return r.w.Header() }
|
| 42 |
+
|
| 43 |
+
func (r *responseRecorder) Write(p []byte) (int, error) {
|
| 44 |
+
if r.status == 0 {
|
| 45 |
+
r.status = http.StatusOK
|
| 46 |
+
}
|
| 47 |
+
n, err := r.w.Write(p)
|
| 48 |
+
r.b += n
|
| 49 |
+
return n, err
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func (r *responseRecorder) WriteHeader(statusCode int) {
|
| 53 |
+
r.status = statusCode
|
| 54 |
+
r.w.WriteHeader(statusCode)
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
func (lh *logHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
| 58 |
+
ctx := r.Context()
|
| 59 |
+
requestID, _ := uuid.NewRandom()
|
| 60 |
+
ctx = context.WithValue(ctx, ctxKeyRequestID{}, requestID.String())
|
| 61 |
+
|
| 62 |
+
start := time.Now()
|
| 63 |
+
rr := &responseRecorder{w: w}
|
| 64 |
+
log := lh.log.WithFields(logrus.Fields{
|
| 65 |
+
"http.req.path": r.URL.Path,
|
| 66 |
+
"http.req.method": r.Method,
|
| 67 |
+
"http.req.id": requestID.String(),
|
| 68 |
+
})
|
| 69 |
+
if v, ok := r.Context().Value(ctxKeySessionID{}).(string); ok {
|
| 70 |
+
log = log.WithField("session", v)
|
| 71 |
+
}
|
| 72 |
+
log.Debug("request started")
|
| 73 |
+
defer func() {
|
| 74 |
+
log.WithFields(logrus.Fields{
|
| 75 |
+
"http.resp.took_ms": int64(time.Since(start) / time.Millisecond),
|
| 76 |
+
"http.resp.status": rr.status,
|
| 77 |
+
"http.resp.bytes": rr.b}).Debugf("request complete")
|
| 78 |
+
}()
|
| 79 |
+
|
| 80 |
+
ctx = context.WithValue(ctx, ctxKeyLog{}, log)
|
| 81 |
+
r = r.WithContext(ctx)
|
| 82 |
+
lh.next.ServeHTTP(rr, r)
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
func ensureSessionID(next http.Handler) http.HandlerFunc {
|
| 86 |
+
return func(w http.ResponseWriter, r *http.Request) {
|
| 87 |
+
var sessionID string
|
| 88 |
+
c, err := r.Cookie(cookieSessionID)
|
| 89 |
+
if err == http.ErrNoCookie {
|
| 90 |
+
if os.Getenv("ENABLE_SINGLE_SHARED_SESSION") == "true" {
|
| 91 |
+
// Hard coded user id, shared across sessions
|
| 92 |
+
sessionID = "12345678-1234-1234-1234-123456789123"
|
| 93 |
+
} else {
|
| 94 |
+
u, _ := uuid.NewRandom()
|
| 95 |
+
sessionID = u.String()
|
| 96 |
+
}
|
| 97 |
+
http.SetCookie(w, &http.Cookie{
|
| 98 |
+
Name: cookieSessionID,
|
| 99 |
+
Value: sessionID,
|
| 100 |
+
MaxAge: cookieMaxAge,
|
| 101 |
+
})
|
| 102 |
+
} else if err != nil {
|
| 103 |
+
return
|
| 104 |
+
} else {
|
| 105 |
+
sessionID = c.Value
|
| 106 |
+
}
|
| 107 |
+
ctx := context.WithValue(r.Context(), ctxKeySessionID{}, sessionID)
|
| 108 |
+
r = r.WithContext(ctx)
|
| 109 |
+
next.ServeHTTP(w, r)
|
| 110 |
+
}
|
| 111 |
+
}
|
benchmark/boutique/codedefect/32/code/frontend/money/money.go
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package money
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"errors"
|
| 19 |
+
|
| 20 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/frontend/genproto"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
const (
|
| 24 |
+
nanosMin = -999999999
|
| 25 |
+
nanosMax = +999999999
|
| 26 |
+
nanosMod = 1000000000
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
var (
|
| 30 |
+
ErrInvalidValue = errors.New("one of the specified money values is invalid")
|
| 31 |
+
ErrMismatchingCurrency = errors.New("mismatching currency codes")
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
// IsValid checks if specified value has a valid units/nanos signs and ranges.
|
| 35 |
+
func IsValid(m pb.Money) bool {
|
| 36 |
+
return signMatches(m) && validNanos(m.GetNanos())
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func signMatches(m pb.Money) bool {
|
| 40 |
+
return m.GetNanos() == 0 || m.GetUnits() == 0 || (m.GetNanos() < 0) == (m.GetUnits() < 0)
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
func validNanos(nanos int32) bool { return nanosMin <= nanos && nanos <= nanosMax }
|
| 44 |
+
|
| 45 |
+
// IsZero returns true if the specified money value is equal to zero.
|
| 46 |
+
func IsZero(m pb.Money) bool { return m.GetUnits() == 0 && m.GetNanos() == 0 }
|
| 47 |
+
|
| 48 |
+
// IsPositive returns true if the specified money value is valid and is
|
| 49 |
+
// positive.
|
| 50 |
+
func IsPositive(m pb.Money) bool {
|
| 51 |
+
return IsValid(m) && m.GetUnits() > 0 || (m.GetUnits() == 0 && m.GetNanos() > 0)
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// IsNegative returns true if the specified money value is valid and is
|
| 55 |
+
// negative.
|
| 56 |
+
func IsNegative(m pb.Money) bool {
|
| 57 |
+
return IsValid(m) && m.GetUnits() < 0 || (m.GetUnits() == 0 && m.GetNanos() < 0)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// AreSameCurrency returns true if values l and r have a currency code and
|
| 61 |
+
// they are the same values.
|
| 62 |
+
func AreSameCurrency(l, r pb.Money) bool {
|
| 63 |
+
return l.GetCurrencyCode() == r.GetCurrencyCode() && l.GetCurrencyCode() != ""
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// AreEquals returns true if values l and r are the equal, including the
|
| 67 |
+
// currency. This does not check validity of the provided values.
|
| 68 |
+
func AreEquals(l, r pb.Money) bool {
|
| 69 |
+
return l.GetCurrencyCode() == r.GetCurrencyCode() &&
|
| 70 |
+
l.GetUnits() == r.GetUnits() && l.GetNanos() == r.GetNanos()
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// Negate returns the same amount with the sign negated.
|
| 74 |
+
func Negate(m pb.Money) pb.Money {
|
| 75 |
+
return pb.Money{
|
| 76 |
+
Units: -m.GetUnits(),
|
| 77 |
+
Nanos: -m.GetNanos(),
|
| 78 |
+
CurrencyCode: m.GetCurrencyCode()}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Must panics if the given error is not nil. This can be used with other
|
| 82 |
+
// functions like: "m := Must(Sum(a,b))".
|
| 83 |
+
func Must(v pb.Money, err error) pb.Money {
|
| 84 |
+
if err != nil {
|
| 85 |
+
panic(err)
|
| 86 |
+
}
|
| 87 |
+
return v
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// Sum adds two values. Returns an error if one of the values are invalid or
|
| 91 |
+
// currency codes are not matching (unless currency code is unspecified for
|
| 92 |
+
// both).
|
| 93 |
+
func Sum(l, r pb.Money) (pb.Money, error) {
|
| 94 |
+
if !IsValid(l) || !IsValid(r) {
|
| 95 |
+
return pb.Money{}, ErrInvalidValue
|
| 96 |
+
} else if l.GetCurrencyCode() != r.GetCurrencyCode() {
|
| 97 |
+
return pb.Money{}, ErrMismatchingCurrency
|
| 98 |
+
}
|
| 99 |
+
units := l.GetUnits() + r.GetUnits()
|
| 100 |
+
nanos := l.GetNanos() + r.GetNanos()
|
| 101 |
+
|
| 102 |
+
if (units == 0 && nanos == 0) || (units > 0 && nanos >= 0) || (units < 0 && nanos <= 0) {
|
| 103 |
+
// same sign <units, nanos>
|
| 104 |
+
units += int64(nanos / nanosMod)
|
| 105 |
+
nanos = nanos % nanosMod
|
| 106 |
+
} else {
|
| 107 |
+
// different sign. nanos guaranteed to not to go over the limit
|
| 108 |
+
if units > 0 {
|
| 109 |
+
units--
|
| 110 |
+
nanos += nanosMod
|
| 111 |
+
} else {
|
| 112 |
+
units++
|
| 113 |
+
nanos -= nanosMod
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return pb.Money{
|
| 118 |
+
Units: units,
|
| 119 |
+
Nanos: nanos,
|
| 120 |
+
CurrencyCode: l.GetCurrencyCode()}, nil
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// MultiplySlow is a slow multiplication operation done through adding the value
|
| 124 |
+
// to itself n-1 times.
|
| 125 |
+
func MultiplySlow(m pb.Money, n uint32) pb.Money {
|
| 126 |
+
out := m
|
| 127 |
+
for n > 1 {
|
| 128 |
+
out = Must(Sum(out, m))
|
| 129 |
+
n--
|
| 130 |
+
}
|
| 131 |
+
return out
|
| 132 |
+
}
|
benchmark/boutique/codedefect/32/code/frontend/packaging_info.go
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"encoding/json"
|
| 19 |
+
"fmt"
|
| 20 |
+
"io/ioutil"
|
| 21 |
+
"net/http"
|
| 22 |
+
"os"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
/*
|
| 26 |
+
As part of an optional Google Cloud demo, you can run an additional "packaging" microservice (HTTP server).
|
| 27 |
+
This file contains code related to the frontend and the "packaging" microservice.
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
var (
|
| 31 |
+
packagingServiceUrl string
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
type PackagingInfo struct {
|
| 35 |
+
Weight float32 `json:"weight"`
|
| 36 |
+
Width float32 `json:"width"`
|
| 37 |
+
Height float32 `json:"height"`
|
| 38 |
+
Depth float32 `json:"depth"`
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// init() is a special function in Golang that will run when this package is imported.
|
| 42 |
+
func init() {
|
| 43 |
+
packagingServiceUrl = os.Getenv("PACKAGING_SERVICE_URL")
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func isPackagingServiceConfigured() bool {
|
| 47 |
+
return packagingServiceUrl != ""
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
func httpGetPackagingInfo(productId string) (*PackagingInfo, error) {
|
| 51 |
+
// Make the GET request
|
| 52 |
+
url := packagingServiceUrl + "/" + productId
|
| 53 |
+
fmt.Println("Requesting packaging info from URL: ", url)
|
| 54 |
+
resp, err := http.Get(url)
|
| 55 |
+
if err != nil {
|
| 56 |
+
return nil, err
|
| 57 |
+
}
|
| 58 |
+
defer resp.Body.Close()
|
| 59 |
+
|
| 60 |
+
// Check the response status code
|
| 61 |
+
if resp.StatusCode != http.StatusOK {
|
| 62 |
+
return nil, fmt.Errorf("Unexpected status code: %d", resp.StatusCode)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// Read the JSON response body
|
| 66 |
+
responseBody, err := ioutil.ReadAll(resp.Body)
|
| 67 |
+
if err != nil {
|
| 68 |
+
return nil, err
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Decode the JSON response into a PackagingInfo struct
|
| 72 |
+
var packagingInfo PackagingInfo
|
| 73 |
+
err = json.Unmarshal(responseBody, &packagingInfo)
|
| 74 |
+
if err != nil {
|
| 75 |
+
return nil, err
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
return &packagingInfo, nil
|
| 79 |
+
}
|
benchmark/boutique/codedefect/32/code/frontend/rpc.go
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"context"
|
| 19 |
+
"time"
|
| 20 |
+
|
| 21 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/frontend/genproto"
|
| 22 |
+
|
| 23 |
+
"github.com/pkg/errors"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
const (
|
| 27 |
+
avoidNoopCurrencyConversionRPC = false
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
func (fe *frontendServer) getCurrencies(ctx context.Context) ([]string, error) {
|
| 31 |
+
currs, err := pb.NewCurrencyServiceClient(fe.currencySvcConn).
|
| 32 |
+
GetSupportedCurrencies(ctx, &pb.Empty{})
|
| 33 |
+
if err != nil {
|
| 34 |
+
return nil, err
|
| 35 |
+
}
|
| 36 |
+
var out []string
|
| 37 |
+
for _, c := range currs.CurrencyCodes {
|
| 38 |
+
if _, ok := whitelistedCurrencies[c]; ok {
|
| 39 |
+
out = append(out, c)
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
return out, nil
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
func (fe *frontendServer) getProducts(ctx context.Context) ([]*pb.Product, error) {
|
| 46 |
+
resp, err := pb.NewProductCatalogServiceClient(fe.productCatalogSvcConn).
|
| 47 |
+
ListProducts(ctx, &pb.Empty{})
|
| 48 |
+
return resp.GetProducts(), err
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
func (fe *frontendServer) getProduct(ctx context.Context, id string) (*pb.Product, error) {
|
| 52 |
+
resp, err := pb.NewProductCatalogServiceClient(fe.productCatalogSvcConn).
|
| 53 |
+
GetProduct(ctx, &pb.GetProductRequest{Id: id})
|
| 54 |
+
return resp, err
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
func (fe *frontendServer) getCart(ctx context.Context, userID string) ([]*pb.CartItem, error) {
|
| 58 |
+
resp, err := pb.NewCartServiceClient(fe.cartSvcConn).GetCart(ctx, &pb.GetCartRequest{UserId: userID})
|
| 59 |
+
return resp.GetItems(), err
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
func (fe *frontendServer) emptyCart(ctx context.Context, userID string) error {
|
| 63 |
+
_, err := pb.NewCartServiceClient(fe.cartSvcConn).EmptyCart(ctx, &pb.EmptyCartRequest{UserId: userID})
|
| 64 |
+
return err
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
func (fe *frontendServer) insertCart(ctx context.Context, userID, productID string, quantity int32) error {
|
| 68 |
+
_, err := pb.NewCartServiceClient(fe.cartSvcConn).AddItem(ctx, &pb.AddItemRequest{
|
| 69 |
+
UserId: userID,
|
| 70 |
+
Item: &pb.CartItem{
|
| 71 |
+
ProductId: productID,
|
| 72 |
+
Quantity: quantity},
|
| 73 |
+
})
|
| 74 |
+
return err
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
func (fe *frontendServer) convertCurrency(ctx context.Context, money *pb.Money, currency string) (*pb.Money, error) {
|
| 78 |
+
if avoidNoopCurrencyConversionRPC && money.GetCurrencyCode() == currency {
|
| 79 |
+
return money, nil
|
| 80 |
+
}
|
| 81 |
+
return pb.NewCurrencyServiceClient(fe.currencySvcConn).
|
| 82 |
+
Convert(ctx, &pb.CurrencyConversionRequest{
|
| 83 |
+
From: money,
|
| 84 |
+
ToCode: currency})
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
func (fe *frontendServer) getShippingQuote(ctx context.Context, items []*pb.CartItem, currency string) (*pb.Money, error) {
|
| 88 |
+
quote, err := pb.NewShippingServiceClient(fe.shippingSvcConn).GetQuote(ctx,
|
| 89 |
+
&pb.GetQuoteRequest{
|
| 90 |
+
Address: nil,
|
| 91 |
+
Items: items})
|
| 92 |
+
if err != nil {
|
| 93 |
+
return nil, err
|
| 94 |
+
}
|
| 95 |
+
localized, err := fe.convertCurrency(ctx, quote.GetCostUsd(), currency)
|
| 96 |
+
return localized, errors.Wrap(err, "failed to convert currency for shipping cost")
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
func (fe *frontendServer) getRecommendations(ctx context.Context, userID string, productIDs []string) ([]*pb.Product, error) {
|
| 100 |
+
resp, err := pb.NewRecommendationServiceClient(fe.recommendationSvcConn).ListRecommendations(ctx,
|
| 101 |
+
&pb.ListRecommendationsRequest{UserId: userID, ProductIds: productIDs})
|
| 102 |
+
if err != nil {
|
| 103 |
+
return nil, err
|
| 104 |
+
}
|
| 105 |
+
out := make([]*pb.Product, len(resp.GetProductIds()))
|
| 106 |
+
for i, v := range resp.GetProductIds() {
|
| 107 |
+
p, err := fe.getProduct(ctx, v)
|
| 108 |
+
if err != nil {
|
| 109 |
+
return nil, errors.Wrapf(err, "failed to get recommended product info (#%s)", v)
|
| 110 |
+
}
|
| 111 |
+
out[i] = p
|
| 112 |
+
}
|
| 113 |
+
if len(out) > 4 {
|
| 114 |
+
out = out[:4] // take only first four to fit the UI
|
| 115 |
+
}
|
| 116 |
+
return out, err
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
func (fe *frontendServer) getAd(ctx context.Context, ctxKeys []string) ([]*pb.Ad, error) {
|
| 120 |
+
ctx, cancel := context.WithTimeout(ctx, time.Millisecond*100)
|
| 121 |
+
defer cancel()
|
| 122 |
+
|
| 123 |
+
resp, err := pb.NewAdServiceClient(fe.adSvcConn).GetAds(ctx, &pb.AdRequest{
|
| 124 |
+
ContextKeys: ctxKeys,
|
| 125 |
+
})
|
| 126 |
+
return resp.GetAds(), errors.Wrap(err, "failed to get ads")
|
| 127 |
+
}
|
benchmark/boutique/codedefect/32/code/frontend/validator/validator.go
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2024 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package validator
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"errors"
|
| 19 |
+
"fmt"
|
| 20 |
+
|
| 21 |
+
"github.com/go-playground/validator/v10"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
var validate *validator.Validate
|
| 25 |
+
|
| 26 |
+
// init() is a special function that will run when this package is imported.
|
| 27 |
+
// It instantiates a SINGLE instance of *validator.Validate with the added
|
| 28 |
+
// benefit of caching struct info and validations.
|
| 29 |
+
func init() {
|
| 30 |
+
validate = validator.New(validator.WithRequiredStructEnabled())
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
type Payload interface {
|
| 34 |
+
Validate() error
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
type AddToCartPayload struct {
|
| 38 |
+
Quantity uint64 `validate:"required,gte=1,lte=10"`
|
| 39 |
+
ProductID string `validate:"required"`
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
type PlaceOrderPayload struct {
|
| 43 |
+
Email string `validate:"required,email"`
|
| 44 |
+
StreetAddress string `validate:"required,max=512"`
|
| 45 |
+
ZipCode int64 `validate:"required"`
|
| 46 |
+
City string `validate:"required,max=128"`
|
| 47 |
+
State string `validate:"required,max=128"`
|
| 48 |
+
Country string `validate:"required,max=128"`
|
| 49 |
+
CcNumber string `validate:"required,credit_card"`
|
| 50 |
+
CcMonth int64 `validate:"required,gte=1,lte=12"`
|
| 51 |
+
CcYear int64 `validate:"required"`
|
| 52 |
+
CcCVV int64 `validate:"required"`
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
type SetCurrencyPayload struct {
|
| 56 |
+
Currency string `validate:"required,iso4217"`
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// Implementations of the 'Payload' interface.
|
| 60 |
+
func (ad *AddToCartPayload) Validate() error {
|
| 61 |
+
return validate.Struct(ad)
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
func (po *PlaceOrderPayload) Validate() error {
|
| 65 |
+
return validate.Struct(po)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
func (sc *SetCurrencyPayload) Validate() error {
|
| 69 |
+
return validate.Struct(sc)
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// Reusable error response function.
|
| 73 |
+
func ValidationErrorResponse(err error) error {
|
| 74 |
+
validationErrs, ok := err.(validator.ValidationErrors)
|
| 75 |
+
if !ok {
|
| 76 |
+
return errors.New("invalid validation error format")
|
| 77 |
+
}
|
| 78 |
+
var msg string
|
| 79 |
+
for _, err := range validationErrs {
|
| 80 |
+
msg += fmt.Sprintf("Field '%s' is invalid: %s\n", err.Field(), err.Tag())
|
| 81 |
+
}
|
| 82 |
+
return fmt.Errorf("%s", msg)
|
| 83 |
+
}
|
benchmark/boutique/codedefect/32/code/paymentservice/charge.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
const cardValidator = require('simple-card-validator');
|
| 16 |
+
const { v4: uuidv4 } = require('uuid');
|
| 17 |
+
const pino = require('pino');
|
| 18 |
+
|
| 19 |
+
const logger = pino({
|
| 20 |
+
name: 'paymentservice-charge',
|
| 21 |
+
messageKey: 'message',
|
| 22 |
+
formatters: {
|
| 23 |
+
level (logLevelString, logLevelNum) {
|
| 24 |
+
return { severity: logLevelString }
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class CreditCardError extends Error {
|
| 31 |
+
constructor (message) {
|
| 32 |
+
super(message);
|
| 33 |
+
this.code = 400; // Invalid argument error
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
class InvalidCreditCard extends CreditCardError {
|
| 38 |
+
constructor (cardType) {
|
| 39 |
+
super(`Credit card info is invalid`);
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
class UnacceptedCreditCard extends CreditCardError {
|
| 44 |
+
constructor (cardType) {
|
| 45 |
+
super(`Sorry, we cannot process ${cardType} credit cards. Only VISA or MasterCard is accepted.`);
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
class ExpiredCreditCard extends CreditCardError {
|
| 50 |
+
constructor (number, month, year) {
|
| 51 |
+
super(`Your credit card (ending ${number.substr(-4)}) expired on ${month}/${year}`);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Verifies the credit card number and (pretend) charges the card.
|
| 57 |
+
*
|
| 58 |
+
* @param {*} request
|
| 59 |
+
* @return transaction_id - a random uuid.
|
| 60 |
+
*/
|
| 61 |
+
module.exports = function charge (request) {
|
| 62 |
+
const { amount, credit_card: creditCard } = request;
|
| 63 |
+
const cardNumber = creditCard.credit_card_number;
|
| 64 |
+
const cardInfo = cardValidator(cardNumber);
|
| 65 |
+
const {
|
| 66 |
+
card_type: cardType,
|
| 67 |
+
valid
|
| 68 |
+
} = cardInfo.getCardDetails();
|
| 69 |
+
|
| 70 |
+
if (!valid) { throw new InvalidCreditCard(); }
|
| 71 |
+
|
| 72 |
+
// Only VISA and mastercard is accepted, other card types (AMEX, dinersclub) will
|
| 73 |
+
// throw UnacceptedCreditCard error.
|
| 74 |
+
if (!(cardType === 'visa' || cardType === 'mastercard')) { throw new UnacceptedCreditCard(cardType); }
|
| 75 |
+
|
| 76 |
+
// Also validate expiration is > today.
|
| 77 |
+
const currentMonth = new Date().getMonth() + 1;
|
| 78 |
+
const currentYear = new Date().getFullYear();
|
| 79 |
+
const { credit_card_expiration_year: year, credit_card_expiration_month: month } = creditCard;
|
| 80 |
+
if ((currentYear * 12 + currentMonth) > (year * 12 + month)) { throw new ExpiredCreditCard(cardNumber.replace('-', ''), month, year); }
|
| 81 |
+
|
| 82 |
+
logger.info(`Transaction processed: ${cardType} ending ${cardNumber.substr(-4)} \
|
| 83 |
+
Amount: ${amount.currency_code}${amount.units}.${amount.nanos}`);
|
| 84 |
+
|
| 85 |
+
return { transaction_id: uuidv4() };
|
| 86 |
+
};
|
benchmark/boutique/codedefect/32/code/paymentservice/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2018 Google LLC
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* https://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
'use strict';
|
| 18 |
+
|
| 19 |
+
const logger = require('./logger')
|
| 20 |
+
|
| 21 |
+
if (process.env.DISABLE_PROFILER) {
|
| 22 |
+
logger.info("Profiler disabled.")
|
| 23 |
+
} else {
|
| 24 |
+
logger.info("Profiler enabled.")
|
| 25 |
+
require('@google-cloud/profiler').start({
|
| 26 |
+
serviceContext: {
|
| 27 |
+
service: 'paymentservice',
|
| 28 |
+
version: '1.0.0'
|
| 29 |
+
}
|
| 30 |
+
});
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if (process.env.ENABLE_TRACING == "1") {
|
| 35 |
+
logger.info("Tracing enabled.")
|
| 36 |
+
|
| 37 |
+
const { resourceFromAttributes } = require('@opentelemetry/resources');
|
| 38 |
+
|
| 39 |
+
const { ATTR_SERVICE_NAME }= require('@opentelemetry/semantic-conventions');
|
| 40 |
+
|
| 41 |
+
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
|
| 42 |
+
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
|
| 43 |
+
const opentelemetry = require('@opentelemetry/sdk-node');
|
| 44 |
+
|
| 45 |
+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-grpc');
|
| 46 |
+
|
| 47 |
+
const collectorUrl = process.env.COLLECTOR_SERVICE_ADDR;
|
| 48 |
+
const traceExporter = new OTLPTraceExporter({url: collectorUrl});
|
| 49 |
+
|
| 50 |
+
const sdk = new opentelemetry.NodeSDK({
|
| 51 |
+
resource: resourceFromAttributes({
|
| 52 |
+
[ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || 'paymentservice',
|
| 53 |
+
}),
|
| 54 |
+
traceExporter: traceExporter,
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
registerInstrumentations({
|
| 58 |
+
instrumentations: [new GrpcInstrumentation()]
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
sdk.start()
|
| 62 |
+
} else {
|
| 63 |
+
logger.info("Tracing disabled.")
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
const path = require('path');
|
| 68 |
+
const HipsterShopServer = require('./server');
|
| 69 |
+
|
| 70 |
+
const PORT = process.env['PORT'];
|
| 71 |
+
const PROTO_PATH = path.join(__dirname, '/proto/');
|
| 72 |
+
|
| 73 |
+
const server = new HipsterShopServer(PROTO_PATH, PORT);
|
| 74 |
+
|
| 75 |
+
server.listen();
|
benchmark/boutique/codedefect/32/code/paymentservice/logger.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2023 Google LLC
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* https://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
const pino = require('pino');
|
| 18 |
+
|
| 19 |
+
module.exports = pino({
|
| 20 |
+
name: 'paymentservice-server',
|
| 21 |
+
messageKey: 'message',
|
| 22 |
+
formatters: {
|
| 23 |
+
level (logLevelString, logLevelNum) {
|
| 24 |
+
return { severity: logLevelString }
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
});
|
benchmark/boutique/codedefect/32/code/paymentservice/server.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
const path = require('path');
|
| 16 |
+
const grpc = require('@grpc/grpc-js');
|
| 17 |
+
const protoLoader = require('@grpc/proto-loader');
|
| 18 |
+
|
| 19 |
+
const charge = require('./charge');
|
| 20 |
+
|
| 21 |
+
const logger = require('./logger')
|
| 22 |
+
|
| 23 |
+
class HipsterShopServer {
|
| 24 |
+
constructor(protoRoot, port = HipsterShopServer.PORT) {
|
| 25 |
+
this.port = port;
|
| 26 |
+
|
| 27 |
+
this.packages = {
|
| 28 |
+
hipsterShop: this.loadProto(path.join(protoRoot, 'demo.proto')),
|
| 29 |
+
health: this.loadProto(path.join(protoRoot, 'grpc/health/v1/health.proto'))
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
this.server = new grpc.Server();
|
| 33 |
+
this.loadAllProtos(protoRoot);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Handler for PaymentService.Charge.
|
| 38 |
+
* @param {*} call { ChargeRequest }
|
| 39 |
+
* @param {*} callback fn(err, ChargeResponse)
|
| 40 |
+
*/
|
| 41 |
+
static ChargeServiceHandler(call, callback) {
|
| 42 |
+
try {
|
| 43 |
+
logger.info(`PaymentService#Charge invoked with request ${JSON.stringify(call.request)}`);
|
| 44 |
+
const response = charge(call.request);
|
| 45 |
+
callback(null, response);
|
| 46 |
+
} catch (err) {
|
| 47 |
+
console.warn(err);
|
| 48 |
+
callback(err);
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
static CheckHandler(call, callback) {
|
| 53 |
+
callback(null, { status: 'SERVING' });
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
listen() {
|
| 58 |
+
const server = this.server
|
| 59 |
+
const port = this.port
|
| 60 |
+
server.bindAsync(
|
| 61 |
+
`[::]:${port}`,
|
| 62 |
+
grpc.ServerCredentials.createInsecure(),
|
| 63 |
+
function () {
|
| 64 |
+
logger.info(`PaymentService gRPC server started on port ${port}`);
|
| 65 |
+
server.start();
|
| 66 |
+
}
|
| 67 |
+
);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
loadProto(path) {
|
| 71 |
+
const packageDefinition = protoLoader.loadSync(
|
| 72 |
+
path,
|
| 73 |
+
{
|
| 74 |
+
keepCase: true,
|
| 75 |
+
longs: String,
|
| 76 |
+
enums: String,
|
| 77 |
+
defaults: true,
|
| 78 |
+
oneofs: true
|
| 79 |
+
}
|
| 80 |
+
);
|
| 81 |
+
return grpc.loadPackageDefinition(packageDefinition);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
loadAllProtos(protoRoot) {
|
| 85 |
+
const hipsterShopPackage = this.packages.hipsterShop.hipstershop;
|
| 86 |
+
const healthPackage = this.packages.health.grpc.health.v1;
|
| 87 |
+
|
| 88 |
+
this.server.addService(
|
| 89 |
+
hipsterShopPackage.PaymentService.service,
|
| 90 |
+
{
|
| 91 |
+
charge: HipsterShopServer.ChargeServiceHandler.bind(this)
|
| 92 |
+
}
|
| 93 |
+
);
|
| 94 |
+
|
| 95 |
+
this.server.addService(
|
| 96 |
+
healthPackage.Health.service,
|
| 97 |
+
{
|
| 98 |
+
check: HipsterShopServer.CheckHandler.bind(this)
|
| 99 |
+
}
|
| 100 |
+
);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
HipsterShopServer.PORT = process.env.PORT;
|
| 105 |
+
|
| 106 |
+
module.exports = HipsterShopServer;
|
benchmark/boutique/codedefect/32/code/productcatalogservice/catalog_loader.go
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2024 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// https://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"bytes"
|
| 19 |
+
"context"
|
| 20 |
+
"fmt"
|
| 21 |
+
"net"
|
| 22 |
+
"os"
|
| 23 |
+
"strings"
|
| 24 |
+
|
| 25 |
+
"cloud.google.com/go/alloydbconn"
|
| 26 |
+
secretmanager "cloud.google.com/go/secretmanager/apiv1"
|
| 27 |
+
"cloud.google.com/go/secretmanager/apiv1/secretmanagerpb"
|
| 28 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto"
|
| 29 |
+
"github.com/golang/protobuf/jsonpb"
|
| 30 |
+
"github.com/jackc/pgx/v5/pgxpool"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
func loadCatalog(catalog *pb.ListProductsResponse) error {
|
| 34 |
+
catalogMutex.Lock()
|
| 35 |
+
defer catalogMutex.Unlock()
|
| 36 |
+
|
| 37 |
+
if os.Getenv("ALLOYDB_CLUSTER_NAME") != "" {
|
| 38 |
+
return loadCatalogFromAlloyDB(catalog)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return loadCatalogFromLocalFile(catalog)
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
func loadCatalogFromLocalFile(catalog *pb.ListProductsResponse) error {
|
| 45 |
+
log.Info("loading catalog from local products.json file...")
|
| 46 |
+
|
| 47 |
+
catalogJSON, err := os.ReadFile("products.json")
|
| 48 |
+
if err != nil {
|
| 49 |
+
log.Warnf("failed to open product catalog json file: %v", err)
|
| 50 |
+
return err
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if err := jsonpb.Unmarshal(bytes.NewReader(catalogJSON), catalog); err != nil {
|
| 54 |
+
log.Warnf("failed to parse the catalog JSON: %v", err)
|
| 55 |
+
return err
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
log.Info("successfully parsed product catalog json")
|
| 59 |
+
return nil
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
func getSecretPayload(project, secret, version string) (string, error) {
|
| 63 |
+
ctx := context.Background()
|
| 64 |
+
client, err := secretmanager.NewClient(ctx)
|
| 65 |
+
if err != nil {
|
| 66 |
+
log.Warnf("failed to create SecretManager client: %v", err)
|
| 67 |
+
return "", err
|
| 68 |
+
}
|
| 69 |
+
defer client.Close()
|
| 70 |
+
|
| 71 |
+
req := &secretmanagerpb.AccessSecretVersionRequest{
|
| 72 |
+
Name: fmt.Sprintf("projects/%s/secrets/%s/versions/%s", project, secret, version),
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// Call the API.
|
| 76 |
+
result, err := client.AccessSecretVersion(ctx, req)
|
| 77 |
+
if err != nil {
|
| 78 |
+
log.Warnf("failed to access SecretVersion: %v", err)
|
| 79 |
+
return "", err
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return string(result.Payload.Data), nil
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
func loadCatalogFromAlloyDB(catalog *pb.ListProductsResponse) error {
|
| 86 |
+
log.Info("loading catalog from AlloyDB...")
|
| 87 |
+
|
| 88 |
+
projectID := os.Getenv("PROJECT_ID")
|
| 89 |
+
region := os.Getenv("REGION")
|
| 90 |
+
pgClusterName := os.Getenv("ALLOYDB_CLUSTER_NAME")
|
| 91 |
+
pgInstanceName := os.Getenv("ALLOYDB_INSTANCE_NAME")
|
| 92 |
+
pgDatabaseName := os.Getenv("ALLOYDB_DATABASE_NAME")
|
| 93 |
+
pgTableName := os.Getenv("ALLOYDB_TABLE_NAME")
|
| 94 |
+
pgSecretName := os.Getenv("ALLOYDB_SECRET_NAME")
|
| 95 |
+
|
| 96 |
+
pgPassword, err := getSecretPayload(projectID, pgSecretName, "latest")
|
| 97 |
+
if err != nil {
|
| 98 |
+
return err
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
dialer, err := alloydbconn.NewDialer(context.Background())
|
| 102 |
+
if err != nil {
|
| 103 |
+
log.Warnf("failed to set-up dialer connection: %v", err)
|
| 104 |
+
return err
|
| 105 |
+
}
|
| 106 |
+
cleanup := func() error { return dialer.Close() }
|
| 107 |
+
defer cleanup()
|
| 108 |
+
|
| 109 |
+
dsn := fmt.Sprintf(
|
| 110 |
+
"user=%s password=%s dbname=%s sslmode=disable",
|
| 111 |
+
"postgres", pgPassword, pgDatabaseName,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
config, err := pgxpool.ParseConfig(dsn)
|
| 115 |
+
if err != nil {
|
| 116 |
+
log.Warnf("failed to parse DSN config: %v", err)
|
| 117 |
+
return err
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
pgInstanceURI := fmt.Sprintf("projects/%s/locations/%s/clusters/%s/instances/%s", projectID, region, pgClusterName, pgInstanceName)
|
| 121 |
+
config.ConnConfig.DialFunc = func(ctx context.Context, _ string, _ string) (net.Conn, error) {
|
| 122 |
+
return dialer.Dial(ctx, pgInstanceURI)
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
pool, err := pgxpool.NewWithConfig(context.Background(), config)
|
| 126 |
+
if err != nil {
|
| 127 |
+
log.Warnf("failed to set-up pgx pool: %v", err)
|
| 128 |
+
return err
|
| 129 |
+
}
|
| 130 |
+
defer pool.Close()
|
| 131 |
+
|
| 132 |
+
query := "SELECT id, name, description, picture, price_usd_currency_code, price_usd_units, price_usd_nanos, categories FROM " + pgTableName
|
| 133 |
+
rows, err := pool.Query(context.Background(), query)
|
| 134 |
+
if err != nil {
|
| 135 |
+
log.Warnf("failed to query database: %v", err)
|
| 136 |
+
return err
|
| 137 |
+
}
|
| 138 |
+
defer rows.Close()
|
| 139 |
+
|
| 140 |
+
catalog.Products = catalog.Products[:0]
|
| 141 |
+
for rows.Next() {
|
| 142 |
+
product := &pb.Product{}
|
| 143 |
+
product.PriceUsd = &pb.Money{}
|
| 144 |
+
|
| 145 |
+
var categories string
|
| 146 |
+
err = rows.Scan(&product.Id, &product.Name, &product.Description,
|
| 147 |
+
&product.Picture, &product.PriceUsd.CurrencyCode, &product.PriceUsd.Units,
|
| 148 |
+
&product.PriceUsd.Nanos, &categories)
|
| 149 |
+
if err != nil {
|
| 150 |
+
log.Warnf("failed to scan query result row: %v", err)
|
| 151 |
+
return err
|
| 152 |
+
}
|
| 153 |
+
categories = strings.ToLower(categories)
|
| 154 |
+
product.Categories = strings.Split(categories, ",")
|
| 155 |
+
|
| 156 |
+
catalog.Products = append(catalog.Products, product)
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
log.Info("successfully parsed product catalog from AlloyDB")
|
| 160 |
+
return nil
|
| 161 |
+
}
|
benchmark/boutique/codedefect/32/code/productcatalogservice/product_catalog.go
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"context"
|
| 19 |
+
"strings"
|
| 20 |
+
"time"
|
| 21 |
+
|
| 22 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto"
|
| 23 |
+
"google.golang.org/grpc/codes"
|
| 24 |
+
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
| 25 |
+
"google.golang.org/grpc/status"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
type productCatalog struct {
|
| 29 |
+
pb.UnimplementedProductCatalogServiceServer
|
| 30 |
+
catalog pb.ListProductsResponse
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
func (p *productCatalog) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
| 34 |
+
return &healthpb.HealthCheckResponse{Status: healthpb.HealthCheckResponse_SERVING}, nil
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
func (p *productCatalog) Watch(req *healthpb.HealthCheckRequest, ws healthpb.Health_WatchServer) error {
|
| 38 |
+
return status.Errorf(codes.Unimplemented, "health check via Watch not implemented")
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
func (p *productCatalog) ListProducts(context.Context, *pb.Empty) (*pb.ListProductsResponse, error) {
|
| 42 |
+
time.Sleep(extraLatency)
|
| 43 |
+
|
| 44 |
+
return &pb.ListProductsResponse{Products: p.parseCatalog()}, nil
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
func (p *productCatalog) GetProduct(ctx context.Context, req *pb.GetProductRequest) (*pb.Product, error) {
|
| 48 |
+
time.Sleep(extraLatency)
|
| 49 |
+
|
| 50 |
+
catalog := p.parseCatalog()
|
| 51 |
+
for _, product := range catalog {
|
| 52 |
+
if req.Id == product.Id {
|
| 53 |
+
return product, nil
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
return nil, status.Errorf(codes.NotFound, "no product with ID %s", req.Id)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
func (p *productCatalog) SearchProducts(ctx context.Context, req *pb.SearchProductsRequest) (*pb.SearchProductsResponse, error) {
|
| 61 |
+
time.Sleep(extraLatency)
|
| 62 |
+
|
| 63 |
+
var ps []*pb.Product
|
| 64 |
+
for _, product := range p.parseCatalog() {
|
| 65 |
+
if strings.Contains(strings.ToLower(product.Name), strings.ToLower(req.Query)) ||
|
| 66 |
+
strings.Contains(strings.ToLower(product.Description), strings.ToLower(req.Query)) {
|
| 67 |
+
ps = append(ps, product)
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
return &pb.SearchProductsResponse{Results: ps}, nil
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
func (p *productCatalog) parseCatalog() []*pb.Product {
|
| 75 |
+
if reloadCatalog || len(p.catalog.Products) == 0 {
|
| 76 |
+
err := loadCatalog(&p.catalog)
|
| 77 |
+
if err != nil {
|
| 78 |
+
return []*pb.Product{}
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return p.catalog.Products
|
| 83 |
+
}
|
benchmark/boutique/codedefect/32/code/productcatalogservice/server.go
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"context"
|
| 19 |
+
"flag"
|
| 20 |
+
"fmt"
|
| 21 |
+
"net"
|
| 22 |
+
"os"
|
| 23 |
+
"os/signal"
|
| 24 |
+
"sync"
|
| 25 |
+
"syscall"
|
| 26 |
+
"time"
|
| 27 |
+
|
| 28 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/productcatalogservice/genproto"
|
| 29 |
+
"google.golang.org/grpc/credentials/insecure"
|
| 30 |
+
"google.golang.org/grpc/health"
|
| 31 |
+
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
| 32 |
+
|
| 33 |
+
"cloud.google.com/go/profiler"
|
| 34 |
+
"github.com/pkg/errors"
|
| 35 |
+
"github.com/sirupsen/logrus"
|
| 36 |
+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
| 37 |
+
"go.opentelemetry.io/otel"
|
| 38 |
+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
| 39 |
+
"go.opentelemetry.io/otel/propagation"
|
| 40 |
+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
| 41 |
+
"google.golang.org/grpc"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
var (
|
| 45 |
+
catalogMutex *sync.Mutex
|
| 46 |
+
log *logrus.Logger
|
| 47 |
+
extraLatency time.Duration
|
| 48 |
+
|
| 49 |
+
port = "3550"
|
| 50 |
+
|
| 51 |
+
reloadCatalog bool
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
func init() {
|
| 55 |
+
log = logrus.New()
|
| 56 |
+
log.Formatter = &logrus.JSONFormatter{
|
| 57 |
+
FieldMap: logrus.FieldMap{
|
| 58 |
+
logrus.FieldKeyTime: "timestamp",
|
| 59 |
+
logrus.FieldKeyLevel: "severity",
|
| 60 |
+
logrus.FieldKeyMsg: "message",
|
| 61 |
+
},
|
| 62 |
+
TimestampFormat: time.RFC3339Nano,
|
| 63 |
+
}
|
| 64 |
+
log.Out = os.Stdout
|
| 65 |
+
catalogMutex = &sync.Mutex{}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
func main() {
|
| 69 |
+
if os.Getenv("ENABLE_TRACING") == "1" {
|
| 70 |
+
err := initTracing()
|
| 71 |
+
if err != nil {
|
| 72 |
+
log.Warnf("warn: failed to start tracer: %+v", err)
|
| 73 |
+
}
|
| 74 |
+
} else {
|
| 75 |
+
log.Info("Tracing disabled.")
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if os.Getenv("DISABLE_PROFILER") == "" {
|
| 79 |
+
log.Info("Profiling enabled.")
|
| 80 |
+
go initProfiling("productcatalogservice", "1.0.0")
|
| 81 |
+
} else {
|
| 82 |
+
log.Info("Profiling disabled.")
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
flag.Parse()
|
| 86 |
+
|
| 87 |
+
// set injected latency
|
| 88 |
+
if s := os.Getenv("EXTRA_LATENCY"); s != "" {
|
| 89 |
+
v, err := time.ParseDuration(s)
|
| 90 |
+
if err != nil {
|
| 91 |
+
log.Fatalf("failed to parse EXTRA_LATENCY (%s) as time.Duration: %+v", v, err)
|
| 92 |
+
}
|
| 93 |
+
extraLatency = v
|
| 94 |
+
log.Infof("extra latency enabled (duration: %v)", extraLatency)
|
| 95 |
+
} else {
|
| 96 |
+
extraLatency = time.Duration(0)
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
sigs := make(chan os.Signal, 1)
|
| 100 |
+
signal.Notify(sigs, syscall.SIGUSR1, syscall.SIGUSR2)
|
| 101 |
+
go func() {
|
| 102 |
+
for {
|
| 103 |
+
sig := <-sigs
|
| 104 |
+
log.Printf("Received signal: %s", sig)
|
| 105 |
+
if sig == syscall.SIGUSR1 {
|
| 106 |
+
reloadCatalog = true
|
| 107 |
+
log.Infof("Enable catalog reloading")
|
| 108 |
+
} else {
|
| 109 |
+
reloadCatalog = false
|
| 110 |
+
log.Infof("Disable catalog reloading")
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}()
|
| 114 |
+
|
| 115 |
+
if os.Getenv("PORT") != "" {
|
| 116 |
+
port = os.Getenv("PORT")
|
| 117 |
+
}
|
| 118 |
+
log.Infof("starting grpc server at :%s", port)
|
| 119 |
+
run(port)
|
| 120 |
+
select {}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
func run(port string) string {
|
| 124 |
+
listener, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
|
| 125 |
+
if err != nil {
|
| 126 |
+
log.Fatal(err)
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Propagate trace context
|
| 130 |
+
otel.SetTextMapPropagator(
|
| 131 |
+
propagation.NewCompositeTextMapPropagator(
|
| 132 |
+
propagation.TraceContext{}, propagation.Baggage{}))
|
| 133 |
+
var srv *grpc.Server
|
| 134 |
+
srv = grpc.NewServer(
|
| 135 |
+
grpc.StatsHandler(otelgrpc.NewServerHandler()))
|
| 136 |
+
|
| 137 |
+
svc := &productCatalog{}
|
| 138 |
+
err = loadCatalog(&svc.catalog)
|
| 139 |
+
if err != nil {
|
| 140 |
+
log.Fatalf("could not parse product catalog: %v", err)
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
pb.RegisterProductCatalogServiceServer(srv, svc)
|
| 144 |
+
healthcheck := health.NewServer()
|
| 145 |
+
healthpb.RegisterHealthServer(srv, healthcheck)
|
| 146 |
+
go srv.Serve(listener)
|
| 147 |
+
|
| 148 |
+
return listener.Addr().String()
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
func initStats() {
|
| 152 |
+
// TODO(drewbr) Implement OpenTelemetry stats
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
func initTracing() error {
|
| 156 |
+
var (
|
| 157 |
+
collectorAddr string
|
| 158 |
+
collectorConn *grpc.ClientConn
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
ctx := context.Background()
|
| 162 |
+
|
| 163 |
+
mustMapEnv(&collectorAddr, "COLLECTOR_SERVICE_ADDR")
|
| 164 |
+
mustConnGRPC(ctx, &collectorConn, collectorAddr)
|
| 165 |
+
|
| 166 |
+
exporter, err := otlptracegrpc.New(
|
| 167 |
+
ctx,
|
| 168 |
+
otlptracegrpc.WithGRPCConn(collectorConn))
|
| 169 |
+
if err != nil {
|
| 170 |
+
log.Warnf("warn: Failed to create trace exporter: %v", err)
|
| 171 |
+
}
|
| 172 |
+
tp := sdktrace.NewTracerProvider(
|
| 173 |
+
sdktrace.WithBatcher(exporter),
|
| 174 |
+
sdktrace.WithSampler(sdktrace.AlwaysSample()))
|
| 175 |
+
otel.SetTracerProvider(tp)
|
| 176 |
+
return err
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
func initProfiling(service, version string) {
|
| 180 |
+
for i := 1; i <= 3; i++ {
|
| 181 |
+
if err := profiler.Start(profiler.Config{
|
| 182 |
+
Service: service,
|
| 183 |
+
ServiceVersion: version,
|
| 184 |
+
// ProjectID must be set if not running on GCP.
|
| 185 |
+
// ProjectID: "my-project",
|
| 186 |
+
}); err != nil {
|
| 187 |
+
log.Warnf("failed to start profiler: %+v", err)
|
| 188 |
+
} else {
|
| 189 |
+
log.Info("started Stackdriver profiler")
|
| 190 |
+
return
|
| 191 |
+
}
|
| 192 |
+
d := time.Second * 10 * time.Duration(i)
|
| 193 |
+
log.Infof("sleeping %v to retry initializing Stackdriver profiler", d)
|
| 194 |
+
time.Sleep(d)
|
| 195 |
+
}
|
| 196 |
+
log.Warn("could not initialize Stackdriver profiler after retrying, giving up")
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
func mustMapEnv(target *string, envKey string) {
|
| 200 |
+
v := os.Getenv(envKey)
|
| 201 |
+
if v == "" {
|
| 202 |
+
panic(fmt.Sprintf("environment variable %q not set", envKey))
|
| 203 |
+
}
|
| 204 |
+
*target = v
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
func mustConnGRPC(ctx context.Context, conn **grpc.ClientConn, addr string) {
|
| 208 |
+
var err error
|
| 209 |
+
_, cancel := context.WithTimeout(ctx, time.Second*3)
|
| 210 |
+
defer cancel()
|
| 211 |
+
*conn, err = grpc.NewClient(addr,
|
| 212 |
+
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
| 213 |
+
grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
|
| 214 |
+
if err != nil {
|
| 215 |
+
panic(errors.Wrapf(err, "grpc: failed to connect %s", addr))
|
| 216 |
+
}
|
| 217 |
+
}
|
benchmark/boutique/codedefect/32/code/recommendationservice/client.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2018 Google LLC
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
|
| 17 |
+
import sys
|
| 18 |
+
import grpc
|
| 19 |
+
import demo_pb2
|
| 20 |
+
import demo_pb2_grpc
|
| 21 |
+
|
| 22 |
+
from logger import getJSONLogger
|
| 23 |
+
logger = getJSONLogger('recommendationservice-server')
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
# get port
|
| 27 |
+
if len(sys.argv) > 1:
|
| 28 |
+
port = sys.argv[1]
|
| 29 |
+
else:
|
| 30 |
+
port = "8080"
|
| 31 |
+
|
| 32 |
+
# set up server stub
|
| 33 |
+
channel = grpc.insecure_channel('localhost:'+port)
|
| 34 |
+
stub = demo_pb2_grpc.RecommendationServiceStub(channel)
|
| 35 |
+
# form request
|
| 36 |
+
request = demo_pb2.ListRecommendationsRequest(user_id="test", product_ids=["test"])
|
| 37 |
+
# make call to server
|
| 38 |
+
response = stub.ListRecommendations(request)
|
| 39 |
+
logger.info(response)
|
benchmark/boutique/codedefect/32/code/recommendationservice/logger.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2018 Google LLC
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
|
| 17 |
+
import logging
|
| 18 |
+
import sys
|
| 19 |
+
from pythonjsonlogger import jsonlogger
|
| 20 |
+
|
| 21 |
+
# TODO(yoshifumi) this class is duplicated since other Python services are
|
| 22 |
+
# not sharing the modules for logging.
|
| 23 |
+
class CustomJsonFormatter(jsonlogger.JsonFormatter):
|
| 24 |
+
def add_fields(self, log_record, record, message_dict):
|
| 25 |
+
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
|
| 26 |
+
if not log_record.get('timestamp'):
|
| 27 |
+
log_record['timestamp'] = record.created
|
| 28 |
+
if log_record.get('severity'):
|
| 29 |
+
log_record['severity'] = log_record['severity'].upper()
|
| 30 |
+
else:
|
| 31 |
+
log_record['severity'] = record.levelname
|
| 32 |
+
|
| 33 |
+
def getJSONLogger(name):
|
| 34 |
+
logger = logging.getLogger(name)
|
| 35 |
+
handler = logging.StreamHandler(sys.stdout)
|
| 36 |
+
formatter = CustomJsonFormatter('%(timestamp)s %(severity)s %(name)s %(message)s')
|
| 37 |
+
handler.setFormatter(formatter)
|
| 38 |
+
logger.addHandler(handler)
|
| 39 |
+
logger.setLevel(logging.INFO)
|
| 40 |
+
logger.propagate = False
|
| 41 |
+
return logger
|
benchmark/boutique/codedefect/32/code/recommendationservice/recommendation_server.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2018 Google LLC
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
|
| 17 |
+
import os
|
| 18 |
+
import random
|
| 19 |
+
import time
|
| 20 |
+
import traceback
|
| 21 |
+
from concurrent import futures
|
| 22 |
+
|
| 23 |
+
# @TODO: Temporarily removed in https://github.com/GoogleCloudPlatform/microservices-demo/pull/3196
|
| 24 |
+
# import googlecloudprofiler
|
| 25 |
+
|
| 26 |
+
from google.auth.exceptions import DefaultCredentialsError
|
| 27 |
+
import grpc
|
| 28 |
+
|
| 29 |
+
import demo_pb2
|
| 30 |
+
import demo_pb2_grpc
|
| 31 |
+
from grpc_health.v1 import health_pb2
|
| 32 |
+
from grpc_health.v1 import health_pb2_grpc
|
| 33 |
+
|
| 34 |
+
from opentelemetry import trace
|
| 35 |
+
from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient, GrpcInstrumentorServer
|
| 36 |
+
from opentelemetry.sdk.trace import TracerProvider
|
| 37 |
+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
| 38 |
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
| 39 |
+
|
| 40 |
+
from logger import getJSONLogger
|
| 41 |
+
logger = getJSONLogger('recommendationservice-server')
|
| 42 |
+
|
| 43 |
+
def initStackdriverProfiling():
|
| 44 |
+
project_id = None
|
| 45 |
+
try:
|
| 46 |
+
project_id = os.environ["GCP_PROJECT_ID"]
|
| 47 |
+
except KeyError:
|
| 48 |
+
# Environment variable not set
|
| 49 |
+
pass
|
| 50 |
+
|
| 51 |
+
# @TODO: Temporarily removed in https://github.com/GoogleCloudPlatform/microservices-demo/pull/3196
|
| 52 |
+
# for retry in range(1,4):
|
| 53 |
+
# try:
|
| 54 |
+
# if project_id:
|
| 55 |
+
# googlecloudprofiler.start(service='recommendation_server', service_version='1.0.0', verbose=0, project_id=project_id)
|
| 56 |
+
# else:
|
| 57 |
+
# googlecloudprofiler.start(service='recommendation_server', service_version='1.0.0', verbose=0)
|
| 58 |
+
# logger.info("Successfully started Stackdriver Profiler.")
|
| 59 |
+
# return
|
| 60 |
+
# except (BaseException) as exc:
|
| 61 |
+
# logger.info("Unable to start Stackdriver Profiler Python agent. " + str(exc))
|
| 62 |
+
# if (retry < 4):
|
| 63 |
+
# logger.info("Sleeping %d seconds to retry Stackdriver Profiler agent initialization"%(retry*10))
|
| 64 |
+
# time.sleep (1)
|
| 65 |
+
# else:
|
| 66 |
+
# logger.warning("Could not initialize Stackdriver Profiler after retrying, giving up")
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
| 70 |
+
def ListRecommendations(self, request, context):
|
| 71 |
+
max_responses = 5
|
| 72 |
+
# fetch list of products from product catalog stub
|
| 73 |
+
cat_response = product_catalog_stub.ListProducts(demo_pb2.Empty())
|
| 74 |
+
product_ids = [x.id for x in cat_response.products]
|
| 75 |
+
filtered_products = list(set(product_ids)-set(request.product_ids))
|
| 76 |
+
num_products = len(filtered_products)
|
| 77 |
+
num_return = min(max_responses, num_products)
|
| 78 |
+
# sample list of indicies to return
|
| 79 |
+
indices = random.sample(range(num_products), num_return)
|
| 80 |
+
# fetch product ids from indices
|
| 81 |
+
prod_list = [filtered_products[i] for i in indices]
|
| 82 |
+
logger.info("[Recv ListRecommendations] product_ids={}".format(prod_list))
|
| 83 |
+
# build and return response
|
| 84 |
+
response = demo_pb2.ListRecommendationsResponse()
|
| 85 |
+
response.product_ids.extend(prod_list)
|
| 86 |
+
return response
|
| 87 |
+
|
| 88 |
+
def Check(self, request, context):
|
| 89 |
+
return health_pb2.HealthCheckResponse(
|
| 90 |
+
status=health_pb2.HealthCheckResponse.SERVING)
|
| 91 |
+
|
| 92 |
+
def Watch(self, request, context):
|
| 93 |
+
return health_pb2.HealthCheckResponse(
|
| 94 |
+
status=health_pb2.HealthCheckResponse.UNIMPLEMENTED)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
logger.info("initializing recommendationservice")
|
| 99 |
+
|
| 100 |
+
try:
|
| 101 |
+
if "DISABLE_PROFILER" in os.environ:
|
| 102 |
+
raise KeyError()
|
| 103 |
+
else:
|
| 104 |
+
logger.info("Profiler enabled.")
|
| 105 |
+
initStackdriverProfiling()
|
| 106 |
+
except KeyError:
|
| 107 |
+
logger.info("Profiler disabled.")
|
| 108 |
+
|
| 109 |
+
try:
|
| 110 |
+
grpc_client_instrumentor = GrpcInstrumentorClient()
|
| 111 |
+
grpc_client_instrumentor.instrument()
|
| 112 |
+
grpc_server_instrumentor = GrpcInstrumentorServer()
|
| 113 |
+
grpc_server_instrumentor.instrument()
|
| 114 |
+
if os.environ["ENABLE_TRACING"] == "1":
|
| 115 |
+
trace.set_tracer_provider(TracerProvider())
|
| 116 |
+
otel_endpoint = os.getenv("COLLECTOR_SERVICE_ADDR", "localhost:4317")
|
| 117 |
+
trace.get_tracer_provider().add_span_processor(
|
| 118 |
+
BatchSpanProcessor(
|
| 119 |
+
OTLPSpanExporter(
|
| 120 |
+
endpoint = otel_endpoint,
|
| 121 |
+
insecure = True
|
| 122 |
+
)
|
| 123 |
+
)
|
| 124 |
+
)
|
| 125 |
+
except (KeyError, DefaultCredentialsError):
|
| 126 |
+
logger.info("Tracing disabled.")
|
| 127 |
+
except Exception as e:
|
| 128 |
+
logger.warn(f"Exception on Cloud Trace setup: {traceback.format_exc()}, tracing disabled.")
|
| 129 |
+
|
| 130 |
+
port = os.environ.get('PORT', "8080")
|
| 131 |
+
catalog_addr = os.environ.get('PRODUCT_CATALOG_SERVICE_ADDR', '')
|
| 132 |
+
if catalog_addr == "":
|
| 133 |
+
raise Exception('PRODUCT_CATALOG_SERVICE_ADDR environment variable not set')
|
| 134 |
+
logger.info("product catalog address: " + catalog_addr)
|
| 135 |
+
channel = grpc.insecure_channel(catalog_addr)
|
| 136 |
+
product_catalog_stub = demo_pb2_grpc.ProductCatalogServiceStub(channel)
|
| 137 |
+
|
| 138 |
+
# create gRPC server
|
| 139 |
+
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
| 140 |
+
|
| 141 |
+
# add class to gRPC server
|
| 142 |
+
service = RecommendationService()
|
| 143 |
+
demo_pb2_grpc.add_RecommendationServiceServicer_to_server(service, server)
|
| 144 |
+
health_pb2_grpc.add_HealthServicer_to_server(service, server)
|
| 145 |
+
|
| 146 |
+
# start server
|
| 147 |
+
logger.info("listening on port: " + port)
|
| 148 |
+
server.add_insecure_port('[::]:'+port)
|
| 149 |
+
server.start()
|
| 150 |
+
|
| 151 |
+
# keep alive
|
| 152 |
+
try:
|
| 153 |
+
while True:
|
| 154 |
+
time.sleep(10000)
|
| 155 |
+
except KeyboardInterrupt:
|
| 156 |
+
server.stop(0)
|
benchmark/boutique/codedefect/32/code/shippingservice/main.go
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"fmt"
|
| 19 |
+
"net"
|
| 20 |
+
"os"
|
| 21 |
+
"time"
|
| 22 |
+
|
| 23 |
+
"cloud.google.com/go/profiler"
|
| 24 |
+
"github.com/sirupsen/logrus"
|
| 25 |
+
"golang.org/x/net/context"
|
| 26 |
+
"google.golang.org/grpc"
|
| 27 |
+
"google.golang.org/grpc/codes"
|
| 28 |
+
"google.golang.org/grpc/health"
|
| 29 |
+
"google.golang.org/grpc/reflection"
|
| 30 |
+
"google.golang.org/grpc/status"
|
| 31 |
+
|
| 32 |
+
pb "github.com/GoogleCloudPlatform/microservices-demo/src/shippingservice/genproto"
|
| 33 |
+
healthpb "google.golang.org/grpc/health/grpc_health_v1"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
const (
|
| 37 |
+
defaultPort = "50051"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
var log *logrus.Logger
|
| 41 |
+
|
| 42 |
+
func init() {
|
| 43 |
+
log = logrus.New()
|
| 44 |
+
log.Level = logrus.DebugLevel
|
| 45 |
+
log.Formatter = &logrus.JSONFormatter{
|
| 46 |
+
FieldMap: logrus.FieldMap{
|
| 47 |
+
logrus.FieldKeyTime: "timestamp",
|
| 48 |
+
logrus.FieldKeyLevel: "severity",
|
| 49 |
+
logrus.FieldKeyMsg: "message",
|
| 50 |
+
},
|
| 51 |
+
TimestampFormat: time.RFC3339Nano,
|
| 52 |
+
}
|
| 53 |
+
log.Out = os.Stdout
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
func main() {
|
| 57 |
+
if os.Getenv("DISABLE_TRACING") == "" {
|
| 58 |
+
log.Info("Tracing enabled, but temporarily unavailable")
|
| 59 |
+
log.Info("See https://github.com/GoogleCloudPlatform/microservices-demo/issues/422 for more info.")
|
| 60 |
+
go initTracing()
|
| 61 |
+
} else {
|
| 62 |
+
log.Info("Tracing disabled.")
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if os.Getenv("DISABLE_PROFILER") == "" {
|
| 66 |
+
log.Info("Profiling enabled.")
|
| 67 |
+
go initProfiling("shippingservice", "1.0.0")
|
| 68 |
+
} else {
|
| 69 |
+
log.Info("Profiling disabled.")
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
port := defaultPort
|
| 73 |
+
if value, ok := os.LookupEnv("PORT"); ok {
|
| 74 |
+
port = value
|
| 75 |
+
}
|
| 76 |
+
port = fmt.Sprintf(":%s", port)
|
| 77 |
+
|
| 78 |
+
lis, err := net.Listen("tcp", port)
|
| 79 |
+
if err != nil {
|
| 80 |
+
log.Fatalf("failed to listen: %v", err)
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
var srv *grpc.Server
|
| 84 |
+
if os.Getenv("DISABLE_STATS") == "" {
|
| 85 |
+
log.Info("Stats enabled, but temporarily unavailable")
|
| 86 |
+
srv = grpc.NewServer()
|
| 87 |
+
} else {
|
| 88 |
+
log.Info("Stats disabled.")
|
| 89 |
+
srv = grpc.NewServer()
|
| 90 |
+
}
|
| 91 |
+
svc := &server{}
|
| 92 |
+
pb.RegisterShippingServiceServer(srv, svc)
|
| 93 |
+
healthcheck := health.NewServer()
|
| 94 |
+
healthpb.RegisterHealthServer(srv, healthcheck)
|
| 95 |
+
log.Infof("Shipping Service listening on port %s", port)
|
| 96 |
+
|
| 97 |
+
// Register reflection service on gRPC server.
|
| 98 |
+
reflection.Register(srv)
|
| 99 |
+
if err := srv.Serve(lis); err != nil {
|
| 100 |
+
log.Fatalf("failed to serve: %v", err)
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// server controls RPC service responses.
|
| 105 |
+
type server struct {
|
| 106 |
+
pb.UnimplementedShippingServiceServer
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// Check is for health checking.
|
| 110 |
+
func (s *server) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
|
| 111 |
+
return &healthpb.HealthCheckResponse{Status: healthpb.HealthCheckResponse_SERVING}, nil
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
func (s *server) Watch(req *healthpb.HealthCheckRequest, ws healthpb.Health_WatchServer) error {
|
| 115 |
+
return status.Errorf(codes.Unimplemented, "health check via Watch not implemented")
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// GetQuote produces a shipping quote (cost) in USD.
|
| 119 |
+
func (s *server) GetQuote(ctx context.Context, in *pb.GetQuoteRequest) (*pb.GetQuoteResponse, error) {
|
| 120 |
+
log.Info("[GetQuote] received request")
|
| 121 |
+
defer log.Info("[GetQuote] completed request")
|
| 122 |
+
|
| 123 |
+
// 1. Generate a quote based on the total number of items to be shipped.
|
| 124 |
+
count := 0
|
| 125 |
+
for _, item := range in.Items {
|
| 126 |
+
count += int(item.Quantity)
|
| 127 |
+
}
|
| 128 |
+
quote := CreateQuoteFromCount(count)
|
| 129 |
+
|
| 130 |
+
// 2. Generate a response.
|
| 131 |
+
return &pb.GetQuoteResponse{
|
| 132 |
+
CostUsd: &pb.Money{
|
| 133 |
+
CurrencyCode: "USD",
|
| 134 |
+
Units: int64(quote.Dollars),
|
| 135 |
+
Nanos: int32(quote.Cents * 10000000)},
|
| 136 |
+
}, nil
|
| 137 |
+
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
// ShipOrder mocks that the requested items will be shipped.
|
| 141 |
+
// It supplies a tracking ID for notional lookup of shipment delivery status.
|
| 142 |
+
func (s *server) ShipOrder(ctx context.Context, in *pb.ShipOrderRequest) (*pb.ShipOrderResponse, error) {
|
| 143 |
+
log.Info("[ShipOrder] received request")
|
| 144 |
+
defer log.Info("[ShipOrder] completed request")
|
| 145 |
+
// 1. Create a Tracking ID
|
| 146 |
+
baseAddress := fmt.Sprintf("%s, %s, %s", in.Address.StreetAddress, in.Address.City, in.Address.State)
|
| 147 |
+
id := CreateTrackingId(baseAddress)
|
| 148 |
+
|
| 149 |
+
// 2. Generate a response.
|
| 150 |
+
return &pb.ShipOrderResponse{
|
| 151 |
+
TrackingId: id,
|
| 152 |
+
}, nil
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
func initStats() {
|
| 156 |
+
//TODO(arbrown) Implement OpenTelemetry stats
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
func initTracing() {
|
| 160 |
+
// TODO(arbrown) Implement OpenTelemetry tracing
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
func initProfiling(service, version string) {
|
| 164 |
+
// TODO(ahmetb) this method is duplicated in other microservices using Go
|
| 165 |
+
// since they are not sharing packages.
|
| 166 |
+
for i := 1; i <= 3; i++ {
|
| 167 |
+
if err := profiler.Start(profiler.Config{
|
| 168 |
+
Service: service,
|
| 169 |
+
ServiceVersion: version,
|
| 170 |
+
// ProjectID must be set if not running on GCP.
|
| 171 |
+
// ProjectID: "my-project",
|
| 172 |
+
}); err != nil {
|
| 173 |
+
log.Warnf("failed to start profiler: %+v", err)
|
| 174 |
+
} else {
|
| 175 |
+
log.Info("started Stackdriver profiler")
|
| 176 |
+
return
|
| 177 |
+
}
|
| 178 |
+
d := time.Second * 10 * time.Duration(i)
|
| 179 |
+
log.Infof("sleeping %v to retry initializing Stackdriver profiler", d)
|
| 180 |
+
time.Sleep(d)
|
| 181 |
+
}
|
| 182 |
+
log.Warn("could not initialize Stackdriver profiler after retrying, giving up")
|
| 183 |
+
}
|
benchmark/boutique/codedefect/32/code/shippingservice/quote.go
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"fmt"
|
| 19 |
+
"math"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
// Quote represents a currency value.
|
| 23 |
+
type Quote struct {
|
| 24 |
+
Dollars uint32
|
| 25 |
+
Cents uint32
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// String representation of the Quote.
|
| 29 |
+
func (q Quote) String() string {
|
| 30 |
+
return fmt.Sprintf("$%d.%d", q.Dollars, q.Cents)
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// CreateQuoteFromCount takes a number of items and returns a shipping quote.
|
| 34 |
+
func CreateQuoteFromCount(count int) Quote {
|
| 35 |
+
if count == 0 {
|
| 36 |
+
return CreateQuoteFromFloat(0)
|
| 37 |
+
}
|
| 38 |
+
return CreateQuoteFromFloat(8.99)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// CreateQuoteFromFloat takes a price represented as a float and creates a Price struct.
|
| 42 |
+
func CreateQuoteFromFloat(value float64) Quote {
|
| 43 |
+
units, fraction := math.Modf(value)
|
| 44 |
+
return Quote{
|
| 45 |
+
uint32(units),
|
| 46 |
+
uint32(math.Trunc(fraction * 100)),
|
| 47 |
+
}
|
| 48 |
+
}
|
benchmark/boutique/codedefect/32/code/shippingservice/tracker.go
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"fmt"
|
| 19 |
+
"math/rand"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
// CreateTrackingId generates a tracking ID.
|
| 23 |
+
func CreateTrackingId(salt string) string {
|
| 24 |
+
return fmt.Sprintf("%c%c-%d%s-%d%s",
|
| 25 |
+
getRandomLetterCode(),
|
| 26 |
+
getRandomLetterCode(),
|
| 27 |
+
len(salt),
|
| 28 |
+
getRandomNumber(3),
|
| 29 |
+
len(salt)/2,
|
| 30 |
+
getRandomNumber(7),
|
| 31 |
+
)
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
// getRandomLetterCode generates a code point value for a capital letter.
|
| 35 |
+
func getRandomLetterCode() uint32 {
|
| 36 |
+
return 65 + uint32(rand.Intn(25))
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// getRandomNumber generates a string representation of a number with the requested number of digits.
|
| 40 |
+
func getRandomNumber(digits int) string {
|
| 41 |
+
str := ""
|
| 42 |
+
for i := 0; i < digits; i++ {
|
| 43 |
+
str = fmt.Sprintf("%s%d", str, rand.Intn(10))
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return str
|
| 47 |
+
}
|
benchmark/boutique/codedefect/32/metadata.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"namespace": "boutique",
|
| 3 |
+
"query": "Service Availability Disruption.",
|
| 4 |
+
"difficulty": "hard",
|
| 5 |
+
"result": {
|
| 6 |
+
"fault_taxonomy": "Application_Code_Defect",
|
| 7 |
+
"fault_object": "app/frontend",
|
| 8 |
+
"root_cause": "code_wrong_argument_order"
|
| 9 |
+
}
|
| 10 |
+
}
|
benchmark/boutique/codedefect/32/raw_data/alert.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"status": "has_anomalies",
|
| 3 |
+
"alert_count": 3,
|
| 4 |
+
"alerts": [
|
| 5 |
+
{
|
| 6 |
+
"request_method": "GET",
|
| 7 |
+
"business_action": "View product detail",
|
| 8 |
+
"entry_service": "frontend",
|
| 9 |
+
"url": "/product/{id}",
|
| 10 |
+
"occurrences": 19,
|
| 11 |
+
"raw_error": "HTTPError('503 Server Error: Service Unavailable')"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"request_method": "GET",
|
| 15 |
+
"business_action": "View cart",
|
| 16 |
+
"entry_service": "frontend",
|
| 17 |
+
"url": "/cart",
|
| 18 |
+
"occurrences": 9,
|
| 19 |
+
"raw_error": "HTTPError('503 Server Error: Service Unavailable')"
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"request_method": "POST",
|
| 23 |
+
"business_action": "Add product to cart",
|
| 24 |
+
"entry_service": "frontend",
|
| 25 |
+
"url": "/cart",
|
| 26 |
+
"occurrences": 2,
|
| 27 |
+
"raw_error": "HTTPError('503 Server Error: Service Unavailable')"
|
| 28 |
+
}
|
| 29 |
+
]
|
| 30 |
+
}
|
benchmark/boutique/codedefect/32/raw_data/k8s_states.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
benchmark/boutique/codedefect/32/raw_data/logs.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
benchmark/boutique/codedefect/32/raw_data/metrics.csv
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
time,frontend-cpu,frontend-mem,frontend-cpu_cfs,frontend-rps,frontend-success_rate,frontend-network_receive,frontend-network_transmit,frontend-p50latency,frontend-p90latency,frontend-fs_write_bytes,checkoutservice-cpu,checkoutservice-mem,checkoutservice-cpu_cfs,checkoutservice-rps,checkoutservice-success_rate,checkoutservice-network_receive,checkoutservice-network_transmit,checkoutservice-p50latency,checkoutservice-p90latency,checkoutservice-fs_write_bytes,productcatalogservice-cpu,productcatalogservice-mem,productcatalogservice-cpu_cfs,productcatalogservice-rps,productcatalogservice-success_rate,productcatalogservice-network_receive,productcatalogservice-network_transmit,productcatalogservice-p50latency,productcatalogservice-p90latency,productcatalogservice-fs_write_bytes,cartservice-cpu,cartservice-mem,cartservice-cpu_cfs,cartservice-rps,cartservice-success_rate,cartservice-network_receive,cartservice-network_transmit,cartservice-p50latency,cartservice-p90latency,cartservice-fs_write_bytes,currencyservice-cpu,currencyservice-mem,currencyservice-cpu_cfs,currencyservice-rps,currencyservice-success_rate,currencyservice-network_receive,currencyservice-network_transmit,currencyservice-p50latency,currencyservice-p90latency,currencyservice-fs_write_bytes,paymentservice-cpu,paymentservice-mem,paymentservice-cpu_cfs,paymentservice-rps,paymentservice-success_rate,paymentservice-network_receive,paymentservice-network_transmit,paymentservice-p50latency,paymentservice-p90latency,paymentservice-fs_write_bytes,shippingservice-cpu,shippingservice-mem,shippingservice-cpu_cfs,shippingservice-rps,shippingservice-success_rate,shippingservice-network_receive,shippingservice-network_transmit,shippingservice-p50latency,shippingservice-p90latency,shippingservice-fs_write_bytes,emailservice-cpu,emailservice-mem,emailservice-cpu_cfs,emailservice-rps,emailservice-success_rate,emailservice-network_receive,emailservice-network_transmit,emailservice-p50latency,emailservice-p90latency,emailservice-fs_write_bytes,recommendationservice-cpu,recommendationservice-mem,recommendationservice-cpu_cfs,recommendationservice-rps,recommendationservice-success_rate,recommendationservice-network_receive,recommendationservice-network_transmit,recommendationservice-p50latency,recommendationservice-p90latency,recommendationservice-fs_write_bytes,adservice-cpu,adservice-mem,adservice-cpu_cfs,adservice-rps,adservice-success_rate,adservice-network_receive,adservice-network_transmit,adservice-p50latency,adservice-p90latency,adservice-fs_write_bytes,redis-cart-cpu,redis-cart-mem,redis-cart-cpu_cfs,redis-cart-rps,redis-cart-success_rate,redis-cart-network_receive,redis-cart-network_transmit,redis-cart-p50latency,redis-cart-p90latency,redis-cart-fs_write_bytes,master-cpu,master-mem,master-tcp_retans,worker-01-cpu,worker-01-mem,worker-01-tcp_retans,worker-02-cpu,worker-02-mem,worker-02-tcp_retans,worker-03-cpu,worker-03-mem,worker-03-tcp_retans
|
| 2 |
+
2026-05-19 12:47:48,0.001,18636800.0,0.0,0.264,1.0,8.245,8.108,20.706,237.085,0,0.0,55595008.0,0.0,0,0,2.359,1.776,0,0,0,0.0,15085568.0,0.0,1.691,1.0,4.682,3.173,0.27,0.485,0,0.02,78106624.0,0.097,0.0,0.0,3.49,2.879,3.792,81.898,0,0.003,49750016.0,0.007,0.467,1.0,4.227,3.529,2.995,4.753,0,0.0,31277056.0,0.0,0,0,2.959,2.459,0,0,0,0.0,11833344.0,0.0,0.0,0.0,3.507,2.513,2.725,5.844,0,0.001,89513984.0,0.0,0,0,2.98,2.321,0,0,0,0.001,86687744.0,0.0,0.0,0.0,4.386,3.549,3.277,29.439,0,0.003,160964608.0,0.001,0.061,1.0,4.845,3.475,4.415,21.379,0,0.004,13582336.0,0.0,0,0,4.117,3.003,0,0,0.0,3.91,35.864,0.0,3.506,31.066,0.067,3.486,30.362,0.067,3.036,35.589,0.4
|
| 3 |
+
2026-05-19 12:47:53,0.001,18636800.0,0.0,0.314,1.0,12.053,12.314,19.775,192.085,0,0.0,46637056.0,0.0,0,0,2.463,1.916,0,0,0,0.001,15085568.0,0.0,2.03,1.0,4.682,3.173,0.279,1.206,0,0.031,78106624.0,0.148,0.287,1.0,3.914,3.387,3.546,60.045,0,0.004,49750016.0,0.01,0.567,1.0,4.824,4.058,2.969,4.722,0,0.0,31277056.0,0.0,0,0,2.288,1.868,0,0,0,0.0,11882496.0,0.0,0.0,0.0,3.384,2.336,2.682,5.011,0,0.001,89513984.0,0.0,0,0,3.033,2.422,0,0,0,0.002,86798336.0,0.0,0.2,1.0,4.386,3.549,3.119,4.814,0,0.003,161050624.0,0.0,0.073,1.0,3.382,2.451,4.33,21.245,0,0.004,13594624.0,0.0,0,0,4.117,3.003,0,0,0.0,3.801,35.871,0.0,3.506,31.066,0.067,3.568,30.362,0.067,3.036,35.589,0.4
|
| 4 |
+
2026-05-19 12:47:58,0.002,18636800.0,0.0,0.364,1.0,14.722,15.732,19.166,147.085,0,0.0,46637056.0,0.0,0,0,2.463,1.916,0,0,0,0.001,15302656.0,0.0,2.937,1.0,6.404,4.595,0.274,0.492,0,0.031,78106624.0,0.148,0.348,1.0,3.914,3.387,3.469,51.473,0,0.004,49750016.0,0.01,0.667,1.0,6.169,5.148,2.951,4.699,0,0.0,31277056.0,0.0,0,0,2.288,1.868,0,0,0,0.0,11882496.0,0.0,0.15,1.0,3.384,2.336,0.459,4.46,0,0.001,89513984.0,0.0,0,0,3.033,2.422,0,0,0,0.002,86798336.0,0.0,0.239,1.0,4.386,3.549,3.1,4.781,0,0.003,161050624.0,0.0,0.146,1.0,4.095,2.768,3.678,19.073,0,0.004,13594624.0,0.0,0,0,4.508,3.376,0,0,0.0,3.801,35.871,0.0,3.539,31.201,0.067,3.568,30.362,0.067,3.083,35.638,0.067
|
| 5 |
+
2026-05-19 12:48:03,0.002,19214336.0,0.0,0.548,1.0,14.722,15.732,19.152,96.267,0,0.0,37982208.0,0.0,0,0,2.652,2.084,0,0,0,0.001,15302656.0,0.0,3.368,1.0,8.011,5.794,0.274,0.494,0,0.026,79081472.0,0.109,0.41,1.0,4.573,3.909,3.622,52.492,0,0.004,50540544.0,0.007,1.551,1.0,6.169,5.148,2.678,4.685,0,0.0,31277056.0,0.0,0,0,2.288,1.868,0,0,0,0.0,11882496.0,0.0,0.178,1.0,3.523,2.442,0.448,4.389,0,0.001,89513984.0,0.0,0,0,2.835,2.306,0,0,0,0.002,86806528.0,0.0,0.278,1.0,4.928,3.935,3.105,4.79,0,0.003,161050624.0,0.0,0.166,1.0,4.095,2.768,3.594,20.348,0,0.004,13594624.0,0.0,0,0,4.508,3.376,0,0,0.0,3.801,35.871,0.0,3.539,31.201,0.067,3.686,30.422,0.4,3.022,35.638,0.067
|
| 6 |
+
2026-05-19 12:48:08,0.002,19214336.0,0.0,0.615,1.0,14.722,15.732,18.802,91.479,0,0.0,38043648.0,0.0,0,0,2.753,2.207,0,0,0,0.001,15302656.0,0.0,3.798,1.0,8.005,5.919,0.277,0.498,0,0.026,79081472.0,0.109,0.599,1.0,6.059,5.288,3.553,55.755,0,0.003,50540544.0,0.0,1.76,1.0,6.169,5.148,2.656,4.663,0,0.0,31596544.0,0.0,0,0,2.623,2.274,0,0,0,0.0,12775424.0,0.0,0.206,1.0,3.523,2.442,0.441,4.334,0,0.001,89513984.0,0.0,0,0,2.339,1.902,0,0,0,0.002,86806528.0,0.0,0.453,1.0,5.153,4.136,3.119,4.815,0,0.004,161718272.0,0.0,0.185,1.0,4.095,2.768,3.561,19.817,0,0.004,13594624.0,0.0,0,0,4.519,3.191,0,0,0.0,4.336,35.883,0.0,3.539,31.201,0.067,3.774,30.422,0.4,3.022,35.638,0.067
|
| 7 |
+
2026-05-19 12:48:13,0.002,19214336.0,0.0,0.686,1.0,14.15,15.714,18.623,87.515,0,0.0,38043648.0,0.0,0,0,2.753,2.207,0,0,0,0.001,15302656.0,0.0,4.169,1.0,8.005,5.919,0.276,0.498,0,0.03,82759680.0,0.115,0.677,1.0,5.714,4.973,3.508,48.349,0,0.003,50540544.0,0.0,1.968,1.0,7.692,6.351,2.638,4.646,0,0.0,31596544.0,0.0,0,0,2.623,2.274,0,0,0,0.0,12775424.0,0.0,0.257,1.0,3.888,2.621,0.414,4.226,0,0.001,89518080.0,0.0,0,0,2.615,2.15,0,0,0,0.002,86806528.0,0.0,0.509,1.0,5.153,4.136,3.106,4.791,0,0.004,161718272.0,0.0,0.2,1.0,3.87,2.377,3.416,18.371,0,0.004,13594624.0,0.0,0,0,4.533,3.202,0,0,0.0,4.336,35.883,0.0,3.628,31.135,0.067,3.774,30.422,0.4,2.947,35.663,0.067
|
| 8 |
+
2026-05-19 12:48:18,0.002,19550208.0,0.0,0.807,1.0,19.342,20.885,19.934,82.8,0,0.0,38043648.0,0.0,0,0,2.753,2.207,0,0,0,0.001,16105472.0,0.0,4.593,1.0,8.154,6.314,0.275,0.496,0,0.03,82759680.0,0.115,0.755,1.0,5.714,4.973,3.423,40.488,0,0.003,50581504.0,0.0,2.066,1.0,7.846,6.804,2.505,4.607,0,0.0,31596544.0,0.0,0,0,2.623,2.274,0,0,0,0.0,12775424.0,0.0,0.287,1.0,3.888,2.621,0.376,4.042,0,0.001,89518080.0,0.0,0,0,2.648,2.221,0,0,0,0.002,86806528.0,0.0,0.564,1.0,5.491,4.476,3.097,4.774,0,0.004,161718272.0,0.0,0.219,1.0,4.517,2.963,3.405,17.97,0,0.004,13594624.0,0.0,0,0,4.963,3.512,0,0,0.0,4.336,35.883,0.0,3.628,31.135,0.067,3.636,30.424,0.133,3.026,35.663,0.067
|
| 9 |
+
2026-05-19 12:48:23,0.003,19550208.0,0.0,0.867,1.0,19.342,20.885,19.236,67.611,0,0.0,38043648.0,0.0,0,0,2.52,2.074,0,0,0,0.001,16105472.0,0.0,5.017,1.0,7.726,5.947,0.274,0.493,0,0.03,82759680.0,0.115,0.78,1.0,3.434,2.995,3.369,42.878,0,0.003,50581504.0,0.0,2.262,1.0,7.846,6.804,2.491,4.595,0,0.0,31739904.0,0.0,0,0,2.325,1.99,0,0,0,0.0,12816384.0,0.0,0.355,1.0,3.888,2.621,0.378,4.031,0,0.001,89518080.0,0.0,0,0,2.648,2.221,0,0,0,0.002,86810624.0,0.0,0.583,1.0,5.491,4.476,3.104,4.787,0,0.004,161718272.0,0.0,0.222,1.0,4.517,2.963,3.33,14.856,0,0.004,13594624.0,0.0,0,0,4.963,3.512,0,0,0.0,4.2,35.894,0.0,3.628,31.135,0.067,3.482,30.424,0.133,3.026,35.663,0.067
|
| 10 |
+
2026-05-19 12:48:28,0.003,19550208.0,0.0,0.867,1.0,19.342,20.885,17.779,43.966,0,0.0,38043648.0,0.0,0,0,2.52,2.074,0,0,0,0.001,16105472.0,0.0,12.037,1.0,7.726,5.947,0.267,0.481,0,0.015,83881984.0,0.033,0.8,1.0,3.831,3.34,3.203,13.618,0,0.004,50581504.0,0.0,2.356,1.0,7.486,6.632,2.401,4.48,0,0.0,31739904.0,0.0,0,0,2.325,1.99,0,0,0,0.0,12816384.0,0.0,0.333,1.0,3.562,2.573,0.381,3.836,0,0.001,89513984.0,0.0,0,0,2.616,2.219,0,0,0,0.002,86810624.0,0.0,0.6,1.0,5.491,4.476,3.001,4.602,0,0.005,162447360.0,0.005,0.785,1.0,4.865,3.254,3.1,4.781,0,0.004,13729792.0,0.0,0,0,4.434,3.243,0,0,0.0,4.2,35.894,0.0,3.725,31.16,0.0,3.482,30.424,0.133,3.143,35.709,0.067
|
| 11 |
+
2026-05-19 12:48:33,0.008,20172800.0,0.002,3.168,1.0,19.342,20.885,34.77,107.321,0,0.0,38834176.0,0.0,0,0,2.52,2.074,0,0,0,0.001,16105472.0,0.0,13.205,1.0,8.549,6.584,0.36,3.701,0,0.015,83881984.0,0.033,0.8,1.0,12.252,12.252,3.235,12.225,0,0.007,51392512.0,0.01,7.883,1.0,12.081,11.436,3.027,8.35,0,0.0,31739904.0,0.0,0,0,2.325,1.99,0,0,0,0.0,12816384.0,0.0,0.333,1.0,5.162,3.552,0.494,4.266,0,0.001,89513984.0,0.0,0,0,2.616,2.219,0,0,0,0.002,86810624.0,0.0,0.6,1.0,3.975,3.35,4.315,17.512,0,0.005,162447360.0,0.005,0.865,1.0,4.781,3.439,3.775,46.588,0,0.004,13729792.0,0.0,0,0,7.147,5.335,0,0,0.0,4.2,35.894,0.0,3.725,31.16,0.0,3.66,30.515,0.0,3.09,35.709,0.067
|
| 12 |
+
2026-05-19 12:48:38,0.009,20172800.0,0.002,3.466,1.0,69.787,72.308,35.17,105.98,0,0.0,28536832.0,0.0,0,0,2.665,2.106,0,0,0,0.004,16871424.0,0.0,14.022,1.0,8.549,6.584,0.381,3.849,0,0.015,83881984.0,0.033,5.428,1.0,12.252,12.252,3.008,26.712,0,0.007,51392512.0,0.01,8.681,1.0,12.081,11.436,3.036,8.424,0,0.0,31739904.0,0.0,0,0,2.384,2.068,0,0,0,0.001,13254656.0,0.0,0.333,1.0,5.162,3.552,1.031,4.276,0,0.001,89513984.0,0.0,0,0,2.38,2.036,0,0,0,0.002,86810624.0,0.0,3.221,1.0,11.93,12.582,4.289,16.211,0,0.005,162447360.0,0.007,0.945,1.0,4.781,3.439,3.79,47.234,0,0.004,13729792.0,0.0,0,0,7.147,5.335,0,0,0.0,4.562,35.906,0.0,3.725,31.16,0.0,3.929,30.515,0.0,3.09,35.709,0.067
|
| 13 |
+
2026-05-19 12:48:43,0.009,20172800.0,0.002,3.578,1.0,73.064,77.869,34.511,98.704,0,0.0,28536832.0,0.0,0,0,2.665,2.106,0,0,0,0.005,16871424.0,0.0,36.507,1.0,46.171,36.819,0.309,2.912,0,0.024,87740416.0,0.081,5.98,1.0,12.252,12.252,2.966,20.575,0,0.013,54669312.0,0.008,9.48,1.0,12.081,11.436,3.021,8.549,0,0.0,31293440.0,0.0,0,0,2.384,2.068,0,0,0,0.001,13254656.0,0.0,2.531,1.0,5.87,4.018,0.326,3.289,0,0.001,89513984.0,0.0,0,0,2.627,2.058,0,0,0,0.01,87379968.0,0.002,3.532,1.0,11.93,12.582,4.278,15.932,0,0.005,162447360.0,0.007,2.006,1.0,6.261,4.262,3.534,39.712,0,0.004,13737984.0,0.0,0,0,14.461,10.643,0,0,0.0,4.562,35.906,0.0,4.531,31.216,0.0,3.929,30.515,0.0,3.003,35.699,0.0
|
| 14 |
+
2026-05-19 12:48:48,0.019,20430848.0,0.003,7.605,1.0,73.064,77.869,18.349,71.852,0,0.0,28610560.0,0.0,0,0,2.665,2.106,0,0,0,0.005,16871424.0,0.0,40.164,1.0,46.171,36.819,0.289,2.066,0,0.028,87740416.0,0.095,6.532,1.0,12.104,12.446,3.044,15.338,0,0.017,54669312.0,0.011,18.51,1.0,35.687,35.912,2.2,4.788,0,0.0,31293440.0,0.0,0,0,2.384,2.068,0,0,0,0.001,13254656.0,0.0,2.77,1.0,9.512,5.878,0.335,3.455,0,0.001,89518080.0,0.0,0,0,2.627,2.058,0,0,0,0.01,87379968.0,0.002,3.733,1.0,13.485,14.862,3.639,9.914,0,0.004,162447360.0,0.006,2.211,1.0,6.261,4.262,3.324,20.998,0,0.004,13737984.0,0.0,0,0,14.461,10.643,0,0,0.0,4.562,35.906,0.0,4.531,31.216,0.0,4.175,30.358,0.067,3.06,35.699,0.0
|
| 15 |
+
2026-05-19 12:48:53,0.021,20430848.0,0.003,8.331,1.0,141.376,153.078,18.34,71.614,0,0.0,28610560.0,0.0,0,0,2.383,1.856,0,0,0,0.005,16871424.0,0.0,43.822,1.0,62.731,50.563,0.291,2.152,0,0.028,87740416.0,0.095,9.597,1.0,27.439,27.383,2.686,4.92,0,0.017,54669312.0,0.011,20.363,1.0,35.687,35.912,2.192,4.789,0,0.0,31293440.0,0.0,0,0,2.369,1.866,0,0,0,0.002,13717504.0,0.0,2.867,1.0,9.512,5.878,0.336,3.469,0,0.001,89518080.0,0.0,0,0,2.858,2.159,0,0,0,0.015,87392256.0,0.002,6.638,1.0,22.011,23.883,3.401,8.421,0,0.019,165339136.0,0.018,2.417,1.0,6.261,4.262,3.322,20.965,0,0.004,13737984.0,0.0,0,0,14.461,10.643,0,0,0.0,4.061,35.864,0.0,4.531,31.216,0.0,4.469,30.358,0.067,3.06,35.699,0.0
|
| 16 |
+
2026-05-19 12:48:58,0.025,20799488.0,0.003,8.711,1.0,170.411,182.158,18.245,69.054,0,0.0,28610560.0,0.0,0,0,2.383,1.856,0,0,0,0.005,16871424.0,0.0,63.933,1.0,74.561,60.105,0.284,1.691,0,0.024,89018368.0,0.069,10.571,1.0,27.439,27.383,2.648,4.88,0,0.014,54669312.0,0.01,22.217,1.0,51.167,50.299,2.153,4.792,0,0.0,31293440.0,0.0,0,0,2.369,1.866,0,0,0,0.002,13717504.0,0.0,4.373,1.0,9.512,5.878,0.311,2.969,0,0.001,89513984.0,0.0,0,0,2.803,2.187,0,0,0,0.015,87392256.0,0.002,7.281,1.0,22.011,23.883,3.408,8.438,0,0.019,165339136.0,0.018,3.359,1.0,5.175,3.425,3.232,7.289,0,0.005,13750272.0,0.0,0,0,15.05,11.125,0,0,0.0,4.061,35.864,0.0,5.317,31.306,0.0,4.469,30.358,0.067,3.199,35.252,0.0
|
| 17 |
+
2026-05-19 12:49:03,0.03,20799488.0,0.003,12.404,1.0,186.988,200.134,16.375,47.13,0,0.0,28610560.0,0.0,0,0,2.383,1.856,0,0,0,0.014,17137664.0,0.0,70.437,1.0,74.561,60.105,0.276,0.497,0,0.025,89018368.0,0.073,11.545,1.0,33.284,33.377,2.708,4.816,0,0.031,57520128.0,0.021,31.334,1.0,64.671,65.175,1.731,4.569,0,0.0,31551488.0,0.0,0,0,2.369,1.866,0,0,0,0.002,13717504.0,0.0,4.788,1.0,13.135,7.714,0.31,2.945,0,0.001,89513984.0,0.0,0,0,2.803,2.187,0,0,0,0.021,87392256.0,0.003,7.711,1.0,28.535,31.317,3.3,6.923,0,0.019,165339136.0,0.018,3.709,1.0,5.642,3.734,3.175,4.914,0,0.005,13750272.0,0.0,0,0,26.326,19.244,0,0,0.0,4.061,35.864,0.0,5.317,31.306,0.0,4.794,30.428,0.0,3.187,35.252,0.0
|
| 18 |
+
2026-05-19 12:49:08,0.033,20799488.0,0.004,13.595,1.0,228.498,246.271,16.36,47.008,0,0.0,28610560.0,0.0,0,0,2.614,2.011,0,0,0,0.015,17137664.0,0.0,76.94,1.0,106.355,86.13,0.276,0.498,0,0.025,89018368.0,0.073,14.076,1.0,28.412,28.492,2.551,4.747,0,0.031,57520128.0,0.021,34.53,1.0,64.671,65.175,1.719,4.568,0,0.0,31551488.0,0.0,0,0,2.708,2.162,0,0,0,0.002,13717504.0,0.0,4.978,1.0,13.135,7.714,0.311,2.971,0,0.001,89513984.0,0.0,0,0,2.803,2.187,0,0,0,0.022,87416832.0,0.002,9.812,1.0,30.035,32.809,3.238,5.499,0,0.03,165339136.0,0.023,4.059,1.0,10.549,6.458,3.174,4.912,0,0.005,13750272.0,0.0,0,0,26.326,19.244,0,0,0.0,4.115,35.891,0.0,5.317,31.306,0.0,5.151,30.428,0.0,3.187,35.252,0.0
|
| 19 |
+
2026-05-19 12:49:13,0.028,20799488.0,0.003,14.289,1.0,228.498,247.111,16.202,45.667,0,0.0,28610560.0,0.0,0,0,2.578,2.041,0,0,0,0.017,17186816.0,0.0,91.946,1.0,116.237,94.212,0.275,0.494,0,0.026,91197440.0,0.065,15.523,1.0,45.588,45.627,2.521,4.721,0,0.031,57520128.0,0.021,37.726,1.0,64.671,65.175,1.668,4.564,0,0.0,31678464.0,0.0,0,0,2.708,2.162,0,0,0,0.002,14508032.0,0.0,6.291,1.0,13.546,7.661,0.301,2.645,0,0.001,89513984.0,0.0,0,0,2.532,1.961,0,0,0,0.022,87416832.0,0.002,10.771,1.0,30.035,32.809,3.241,5.575,0,0.03,165339136.0,0.023,4.544,1.0,10.549,6.458,3.141,4.853,0,0.005,13623296.0,0.0,0,0,26.326,19.244,0,0,0.0,4.115,35.891,0.0,6.042,31.226,0.0,5.151,30.428,0.0,3.088,35.22,0.0
|
| 20 |
+
2026-05-19 12:49:18,0.025,20799488.0,0.002,16.979,1.0,279.135,299.474,16.032,40.942,0,0.0,18984960.0,0.0,0,0,2.578,2.041,0,0,0,0.02,17186816.0,0.0,100.655,1.0,118.581,96.993,0.27,0.486,0,0.026,91197440.0,0.065,16.969,1.0,45.588,45.627,2.538,4.704,0,0.038,60231680.0,0.01,45.776,1.0,93.83,94.401,1.088,4.383,0,0.0,31678464.0,0.0,0,0,2.708,2.162,0,0,0,0.002,14508032.0,0.0,6.893,1.0,13.639,7.714,0.305,2.81,0,0.001,89513984.0,0.0,0,0,2.532,1.961,0,0,0,0.022,87416832.0,0.002,11.511,1.0,31.698,34.129,3.192,4.946,0,0.022,165339136.0,0.016,4.961,1.0,12.846,7.478,3.118,4.812,0,0.005,13623296.0,0.0,0,0,33.24,24.125,0,0,0.0,4.115,35.891,0.0,6.042,31.226,0.0,5.236,30.386,0.0,3.126,35.22,0.0
|
| 21 |
+
2026-05-19 12:49:23,0.046,20910080.0,0.002,17.222,1.0,290.025,314.403,15.55,31.857,0,0.0,18984960.0,0.0,0,0,2.303,1.893,0,0,0,0.021,17186816.0,0.0,104.511,1.0,85.575,70.875,0.265,0.477,0,0.026,91197440.0,0.065,16.578,1.0,50.136,49.638,2.439,4.588,0,0.038,60231680.0,0.01,49.778,1.0,93.83,94.401,1.029,4.332,0,0.0,31678464.0,0.0,0,0,2.745,2.142,0,0,0,0.003,14508032.0,0.0,7.222,1.0,16.379,9.374,0.299,2.57,0,0.001,89513984.0,0.0,0,0,2.532,1.961,0,0,0,0.023,87416832.0,0.0,12.178,1.0,37.128,39.974,3.065,4.716,0,0.024,167223296.0,0.01,5.0,1.0,12.846,7.478,3.058,4.704,0,0.005,13623296.0,0.0,0,0,25.428,18.455,0,0,0.0,3.914,35.904,0.0,6.042,31.226,0.0,5.2,30.386,0.0,3.126,35.22,0.0
|
| 22 |
+
2026-05-19 12:49:28,0.046,20910080.0,0.002,17.222,1.0,290.025,314.403,15.171,24.624,0,0.0,18984960.0,0.0,0,0,2.293,1.907,0,0,0,0.021,17195008.0,0.0,107.067,1.0,128.108,106.439,0.261,0.469,0,0.013,92381184.0,0.0,16.578,1.0,49.089,48.69,2.341,4.525,0,0.037,61898752.0,0.008,49.778,1.0,93.83,94.401,0.464,4.145,0,0.0,31678464.0,0.0,0,0,2.745,2.142,0,0,0,0.003,14598144.0,0.0,6.933,1.0,16.379,9.374,0.296,2.419,0,0.001,89513984.0,0.0,0,0,2.327,1.962,0,0,0,0.022,87744512.0,0.0,12.178,1.0,36.552,39.227,3.006,4.61,0,0.019,167223296.0,0.0,4.956,1.0,12.448,7.294,3.0,4.6,0,0.004,13623296.0,0.0,0,0,22.658,16.445,0,0,0.0,3.914,35.904,0.0,5.997,31.155,0.0,5.2,30.386,0.0,3.21,35.295,0.0
|
| 23 |
+
2026-05-19 12:49:33,0.047,20910080.0,0.0,17.067,1.0,290.025,314.403,15.096,24.968,0,0.0,18984960.0,0.0,0,0,2.293,1.907,0,0,0,0.021,17195008.0,0.0,107.067,1.0,128.108,106.439,0.26,0.468,0,0.013,92381184.0,0.0,16.578,1.0,39.416,39.317,2.289,4.461,0,0.038,61898752.0,0.01,56.689,1.0,86.742,86.994,0.416,4.01,0,0.0,31678464.0,0.0,0,0,2.697,2.086,0,0,0,0.003,14598144.0,0.0,6.933,1.0,15.906,9.086,0.29,2.108,0,0.001,89513984.0,0.0,0,0,2.327,1.962,0,0,0,0.022,87744512.0,0.0,12.178,1.0,36.552,39.227,3.004,4.607,0,0.019,167714816.0,0.001,4.956,1.0,12.585,7.401,3.0,4.6,0,0.005,13623296.0,0.0,0,0,33.187,24.146,0,0,0.0,3.914,35.904,0.0,5.997,31.155,0.0,5.192,30.47,0.0,3.176,35.295,0.0
|
| 24 |
+
2026-05-19 12:49:38,0.047,21180416.0,0.0,17.067,1.0,310.055,336.603,15.096,24.968,0,0.0,18984960.0,0.0,0,0,2.391,2.012,0,0,0,0.012,17195008.0,0.0,107.067,1.0,129.618,107.931,0.26,0.468,0,0.013,92381184.0,0.0,17.044,1.0,48.004,47.884,2.288,4.46,0,0.038,61898752.0,0.01,56.689,1.0,109.232,109.025,0.392,3.911,0,0.0,32100352.0,0.0,0,0,2.613,2.027,0,0,0,0.002,14598144.0,0.0,6.933,1.0,15.906,9.086,0.29,2.108,0,0.001,89513984.0,0.0,0,0,2.336,1.959,0,0,0,0.022,87744512.0,0.0,12.2,1.0,30.534,32.756,3.002,4.603,0,0.019,167714816.0,0.001,4.956,1.0,12.585,7.401,3.0,4.6,0,0.005,13623296.0,0.0,0,0,33.187,24.146,0,0,0.0,3.907,35.894,0.0,5.997,31.155,0.0,5.154,30.47,0.0,3.176,35.295,0.0
|
| 25 |
+
2026-05-19 12:49:43,0.047,21180416.0,0.0,17.067,1.0,310.055,336.603,15.096,24.968,0,0.0,18984960.0,0.0,0,0,2.24,1.86,0,0,0,0.017,17227776.0,0.0,108.022,1.0,129.65,108.434,0.26,0.468,0,0.012,92381184.0,0.0,17.044,1.0,48.454,48.221,2.288,4.46,0,0.028,64024576.0,0.0,56.689,1.0,109.232,109.025,0.383,3.863,0,0.0,32100352.0,0.0,0,0,2.613,2.027,0,0,0,0.003,15155200.0,0.0,7.044,1.0,15.906,9.086,0.289,2.062,0,0.001,89513984.0,0.0,0,0,2.198,1.848,0,0,0,0.022,87744512.0,0.0,12.2,1.0,29.316,31.449,3.002,4.603,0,0.019,167714816.0,0.001,4.711,1.0,8.496,5.056,3.004,4.608,0,0.005,13623296.0,0.0,0,0,32.688,23.88,0,0,0.0,3.907,35.894,0.0,6.047,31.077,0.0,5.154,30.47,0.0,3.036,35.349,0.0
|
| 26 |
+
2026-05-19 12:49:48,0.048,31862784.0,0.001,16.422,1.0,310.055,336.603,15.819,34.897,0,0.0,19107840.0,0.0,0,0,2.24,1.86,0,0,0,0.021,17227776.0,0.0,108.022,1.0,129.65,108.434,0.26,0.469,0,0.013,95363072.0,0.0,17.044,1.0,48.454,48.221,2.266,4.459,0,0.034,64024576.0,0.0,60.067,1.0,115.515,115.132,0.359,3.683,0,0.0,32100352.0,0.0,0,0,2.237,1.735,0,0,0,0.003,15155200.0,0.0,7.044,1.0,13.517,7.787,0.295,2.377,0,0.001,89513984.0,0.0,0,0,2.198,1.848,0,0,0,0.022,87490560.0,0.0,12.2,1.0,26.317,28.233,3.0,4.6,0,0.019,168124416.0,0.008,4.711,1.0,6.833,4.067,3.009,4.617,0,0.005,13623296.0,0.0,0,0,32.688,23.88,0,0,0.0,3.907,35.894,0.0,6.047,31.077,0.0,5.215,30.296,0.0,3.006,35.349,0.0
|
| 27 |
+
2026-05-19 12:49:53,0.048,31862784.0,0.001,16.422,1.0,276.879,300.445,15.819,34.897,0,0.0,19107840.0,0.0,0,0,2.981,2.339,0,0,0,0.021,17227776.0,0.0,108.022,1.0,122.696,102.544,0.261,0.469,0,0.013,95363072.0,0.0,15.511,1.0,39.227,38.967,2.349,4.476,0,0.034,64024576.0,0.0,60.067,1.0,95.612,95.295,0.348,3.586,0,0.0,32100352.0,0.0,0,0,1.86,1.34,0,0,0,0.003,15155200.0,0.0,7.044,1.0,16.828,9.719,0.295,2.377,0,0.001,89513984.0,0.0,0,0,1.824,1.534,0,0,0,0.022,87490560.0,0.0,11.533,1.0,34.343,36.952,3.002,4.603,0,0.013,168124416.0,0.011,4.711,1.0,7.977,4.748,3.009,4.617,0,0.005,13623296.0,0.0,0,0,32.688,23.88,0,0,0.0,4.042,35.775,0.0,6.047,31.077,0.0,5.257,30.296,0.0,3.006,35.349,0.0
|
| 28 |
+
2026-05-19 12:49:58,0.019,31862784.0,0.0,16.422,1.0,276.879,300.445,15.819,34.897,0,0.0,19259392.0,0.0,0,0,2.981,2.339,0,0,0,0.021,17227776.0,0.0,101.756,1.0,122.696,102.544,0.261,0.47,0,0.013,95363072.0,0.0,15.511,1.0,47.108,46.403,2.349,4.476,0,0.027,64024576.0,0.0,60.067,1.0,85.986,85.701,0.343,3.526,0,0.0,31752192.0,0.0,0,0,3.249,2.396,0,0,0,0.002,15196160.0,0.0,6.778,1.0,16.828,9.719,0.298,2.515,0,0.001,89513984.0,0.0,0,0,2.77,2.399,0,0,0,0.022,87490560.0,0.0,11.533,1.0,34.343,36.952,3.002,4.603,0,0.015,168124416.0,0.012,4.267,1.0,11.763,7.256,3.01,4.618,0,0.005,13623296.0,0.0,0,0,32.688,23.88,0,0,0.0,4.042,35.775,0.0,6.636,31.075,0.0,5.257,30.296,0.0,3.121,35.323,0.0
|
| 29 |
+
2026-05-19 12:50:03,0.019,31862784.0,0.0,12.843,1.0,276.879,300.445,16.052,36.603,0,0.0,19259392.0,0.0,0,0,2.981,2.339,0,0,0,0.02,17244160.0,0.0,101.756,1.0,122.696,102.544,0.261,0.469,0,0.012,95395840.0,0.0,15.511,1.0,47.108,46.403,2.252,4.458,0,0.03,63893504.0,0.003,60.667,1.0,110.549,109.889,0.327,3.307,0,0.0,31752192.0,0.0,0,0,3.249,2.396,0,0,0,0.002,15196160.0,0.0,6.778,1.0,17.077,9.809,0.289,2.041,0,0.001,89513984.0,0.0,0,0,2.77,2.399,0,0,0,0.021,87531520.0,0.0,11.533,1.0,34.343,36.952,3.002,4.604,0,0.013,168124416.0,0.011,4.267,1.0,11.763,7.256,3.012,4.622,0,0.005,13623296.0,0.0,0,0,31.353,23.761,0,0,0.0,4.042,35.775,0.0,6.636,31.075,0.0,5.308,30.447,0.0,3.162,35.323,0.0
|
| 30 |
+
2026-05-19 12:50:08,0.033,30076928.0,0.0,11.521,1.0,271.252,294.646,16.052,36.603,0,0.0,19259392.0,0.0,0,0,2.981,2.339,0,0,0,0.02,17244160.0,0.0,101.756,1.0,100.047,83.632,0.261,0.471,0,0.012,95395840.0,0.0,15.578,1.0,47.108,46.403,2.252,4.458,0,0.03,63893504.0,0.003,60.667,1.0,110.549,109.889,0.322,3.225,0,0.0,31752192.0,0.0,0,0,3.753,2.807,0,0,0,0.002,15196160.0,0.0,6.778,1.0,18.743,9.822,0.287,1.866,0,0.001,89513984.0,0.0,0,0,2.821,2.444,0,0,0,0.017,87531520.0,0.0,10.8,1.0,35.391,36.197,3.002,4.604,0,0.015,168742912.0,0.009,4.267,1.0,11.888,7.493,3.012,4.622,0,0.005,13623296.0,0.0,0,0,31.353,23.761,0,0,0.0,4.111,35.884,4.067,6.636,31.075,0.0,5.333,30.447,0.0,3.162,35.323,0.0
|
| 31 |
+
2026-05-19 12:50:13,0.039,30076928.0,0.0,16.265,1.0,336.359,360.926,16.585,40.084,0,0.0,19259392.0,0.0,0,0,3.302,2.642,0,0,0,0.02,17244160.0,0.0,103.111,1.0,120.781,100.729,0.263,0.473,0,0.012,95420416.0,0.0,15.578,1.0,48.247,47.455,2.378,4.487,0,0.03,63893504.0,0.003,60.667,1.0,110.549,109.889,0.339,3.509,0,0.0,31752192.0,0.0,0,0,5.334,2.805,0,0,0,0.002,15269888.0,0.0,6.756,1.0,18.743,9.822,0.298,2.535,0,0.001,89513984.0,0.0,0,0,2.904,2.573,0,0,0,0.021,87531520.0,0.0,10.8,1.0,35.391,36.197,3.004,4.606,0,0.015,168742912.0,0.009,4.2,1.0,13.984,7.405,3.021,4.637,0,0.003,13623296.0,0.0,0,0,31.353,23.761,0,0,0.0,4.111,35.884,4.067,6.722,31.018,0.0,5.333,30.447,0.0,3.117,35.284,0.0
|
| 32 |
+
2026-05-19 12:50:18,0.04,30523392.0,0.0,16.244,1.0,334.246,357.872,17.145,41.528,0,0.0,19288064.0,0.0,0,0,3.302,2.642,0,0,0,0.02,17244160.0,0.0,103.111,1.0,120.781,100.729,0.263,0.474,0,0.012,95420416.0,0.0,15.578,1.0,48.247,47.455,2.375,4.489,0,0.029,64131072.0,0.003,60.267,1.0,104.685,104.294,0.341,3.531,0,0.0,31870976.0,0.0,0,0,5.334,2.805,0,0,0,0.002,15269888.0,0.0,6.756,1.0,17.978,9.422,0.304,2.782,0,0.001,89513984.0,0.0,0,0,2.904,2.573,0,0,0,0.021,87531520.0,0.0,10.8,1.0,35.629,36.052,3.004,4.606,0,0.016,168988672.0,0.014,4.2,1.0,13.984,7.405,3.026,4.647,0,0.005,13783040.0,0.0,0,0,32.72,24.834,0,0,0.0,4.111,35.884,4.067,6.722,31.018,0.0,5.276,30.474,0.0,3.147,35.284,0.0
|
| 33 |
+
2026-05-19 12:50:23,0.025,30523392.0,0.0,16.266,1.0,303.425,323.661,17.259,41.917,0,0.0,19288064.0,0.0,0,0,3.302,2.642,0,0,0,0.015,17244160.0,0.0,103.111,1.0,120.781,100.729,0.264,0.475,0,0.012,95420416.0,0.0,14.222,1.0,48.247,47.455,2.415,4.494,0,0.029,64131072.0,0.003,60.267,1.0,107.827,106.971,0.342,3.545,0,0.0,31870976.0,0.0,0,0,6.192,3.096,0,0,0,0.002,15269888.0,0.0,6.756,1.0,18.519,9.559,0.304,2.781,0,0.001,89513984.0,0.0,0,0,2.623,2.295,0,0,0,0.021,87576576.0,0.0,10.111,1.0,35.629,36.052,3.004,4.607,0,0.014,168988672.0,0.016,4.2,1.0,13.984,7.405,3.026,4.647,0,0.005,13783040.0,0.0,0,0,32.72,24.834,0,0,0.0,4.133,35.864,0.667,6.722,31.018,0.0,5.238,30.474,0.0,3.147,35.284,0.0
|
| 34 |
+
2026-05-19 12:50:28,0.028,30523392.0,0.0,15.455,1.0,307.466,327.787,17.133,41.202,0,0.0,19374080.0,0.0,0,0,3.335,2.668,0,0,0,0.012,17244160.0,0.0,96.0,1.0,113.603,94.349,0.264,0.475,0,0.008,95420416.0,0.0,14.222,1.0,46.128,45.368,2.4,4.489,0,0.029,64278528.0,0.003,60.267,1.0,107.827,106.971,0.335,3.448,0,0.0,32129024.0,0.0,0,0,6.192,3.096,0,0,0,0.002,15269888.0,0.0,6.489,1.0,18.519,9.559,0.3,2.63,0,0.001,89513984.0,0.0,0,0,2.688,2.384,0,0,0,0.02,87576576.0,0.0,10.111,1.0,26.554,26.015,3.004,4.607,0,0.014,168988672.0,0.016,3.8,1.0,12.578,5.396,3.033,4.66,0,0.005,13783040.0,0.0,0,0,32.247,24.383,0,0,0.0,4.133,35.864,0.667,6.557,31.083,0.0,5.238,30.474,0.0,3.215,35.358,0.0
|
| 35 |
+
2026-05-19 12:50:33,0.033,30638080.0,0.0,10.466,1.0,311.506,331.913,17.56,42.47,0,0.0,19374080.0,0.0,0,0,3.365,2.701,0,0,0,0.019,17276928.0,0.0,96.0,1.0,113.603,94.349,0.263,0.474,0,0.011,95911936.0,0.0,14.222,1.0,46.128,45.368,2.226,4.452,0,0.029,64278528.0,0.003,62.844,1.0,107.827,106.971,0.316,3.118,0,0.0,32129024.0,0.0,0,0,4.4,1.433,0,0,0,0.002,15282176.0,0.0,6.489,1.0,15.088,7.473,0.287,1.91,0,0.001,89513984.0,0.0,0,0,2.688,2.384,0,0,0,0.02,87719936.0,0.0,10.111,1.0,29.616,29.014,3.004,4.608,0,0.01,168988672.0,0.009,3.8,1.0,11.478,5.438,3.035,4.663,0,0.005,13758464.0,0.0,0,0,21.627,16.309,0,0,0.0,4.133,35.864,0.667,6.557,31.083,0.0,5.165,30.48,0.0,3.206,35.358,0.0
|
| 36 |
+
2026-05-19 12:50:38,0.036,30638080.0,0.0,11.683,1.0,250.793,268.368,17.553,42.423,0,0.0,19374080.0,0.0,0,0,3.365,2.701,0,0,0,0.019,17276928.0,0.0,96.0,1.0,120.383,99.883,0.264,0.475,0,0.011,95911936.0,0.0,15.689,1.0,48.348,47.732,2.206,4.448,0,0.029,64278528.0,0.003,62.844,1.0,111.851,110.399,0.32,3.218,0,0.0,32129024.0,0.0,0,0,5.08,2.303,0,0,0,0.002,15282176.0,0.0,6.489,1.0,18.334,9.081,0.289,2.09,0,0.001,89513984.0,0.0,0,0,2.0,1.656,0,0,0,0.02,87719936.0,0.0,10.733,1.0,36.737,35.991,3.004,4.608,0,0.012,169009152.0,0.009,3.8,1.0,14.096,6.679,3.036,4.665,0,0.005,13758464.0,0.0,0,0,24.406,18.405,0,0,0.0,3.943,35.883,0.667,6.557,31.083,0.0,5.104,30.48,0.0,3.206,35.358,0.0
|
| 37 |
+
2026-05-19 12:50:43,0.04,19582976.0,0.0,13.718,1.0,273.945,293.145,17.282,41.654,0,0.0,19918848.0,0.0,0,0,2.668,2.256,0,0,0,0.02,17276928.0,0.0,104.267,1.0,120.383,99.883,0.264,0.475,0,0.011,95911936.0,0.0,15.689,1.0,49.326,48.998,2.277,4.461,0,0.025,64786432.0,0.0,62.844,1.0,117.208,116.02,0.324,3.277,0,0.0,32251904.0,0.0,0,0,5.08,2.303,0,0,0,0.002,15294464.0,0.0,6.978,1.0,18.317,9.344,0.294,2.362,0,0.001,89513984.0,0.0,0,0,2.378,1.969,0,0,0,0.021,87601152.0,0.0,10.733,1.0,30.548,29.928,3.009,4.617,0,0.012,83718144.0,0.009,4.378,1.0,14.096,6.679,3.021,4.645,0,0.005,6770688.0,0.0,0,0,29.189,22.054,0,0,0.0,3.943,35.883,0.667,6.024,31.037,0.0,5.104,30.48,0.0,3.082,35.34,0.0
|
| 38 |
+
2026-05-19 12:50:48,0.029,19582976.0,0.0,15.018,1.0,238.971,260.026,17.278,41.619,0,0.0,16121856.0,0.0,0,0,2.86,2.281,0,0,0,0.02,17276928.0,0.0,104.267,1.0,120.383,99.883,0.264,0.475,0,0.01,95911936.0,0.0,15.689,1.0,49.326,48.998,2.319,4.469,0,0.03,64786432.0,0.0,66.467,1.0,117.208,116.02,0.322,3.236,0,0.0,32251904.0,0.0,0,0,5.08,2.303,0,0,0,0.002,15294464.0,0.0,6.978,1.0,18.317,9.344,0.297,2.487,0,0.001,89513984.0,0.0,0,0,2.048,1.695,0,0,0,0.022,87601152.0,0.0,10.733,1.0,36.888,37.559,3.009,4.617,0,0.013,84045824.0,0.011,4.378,1.0,13.861,7.018,3.021,4.646,0,0.003,6770688.0,0.0,0,0,35.355,26.713,0,0,0.0,3.943,35.883,0.667,6.024,31.037,0.0,5.111,30.302,0.0,3.024,35.34,0.0
|
| 39 |
+
2026-05-19 12:50:53,0.047,19877888.0,0.003,15.6,1.0,264.916,288.257,17.348,41.536,0,0.0,16121856.0,0.0,0,0,2.754,2.079,0,0,0,0.02,17276928.0,0.0,104.267,1.0,83.325,69.05,0.264,0.474,0,0.012,47751168.0,0.0,16.511,1.0,50.677,50.386,2.338,4.471,0,0.03,64786432.0,0.0,66.467,1.0,117.208,116.02,0.325,3.291,0,0.0,15462400.0,0.0,0,0,4.333,2.125,0,0,0,0.002,15294464.0,0.0,6.978,1.0,16.8,9.159,0.298,2.495,0,0.001,89513984.0,0.0,0,0,2.475,2.04,0,0,0,0.022,43921408.0,0.0,11.644,1.0,35.354,37.647,3.008,4.614,0,0.016,84045824.0,0.013,4.378,1.0,13.861,7.018,3.021,4.646,0,0.003,6770688.0,0.0,0,0,35.355,26.713,0,0,0.0,3.768,35.886,0.0,6.024,31.037,0.0,5.192,30.302,0.0,3.024,35.34,0.0
|
| 40 |
+
2026-05-19 12:50:58,0.047,19877888.0,0.003,16.244,1.0,311.334,338.765,16.83,39.856,0,0.0,15953920.0,0.0,0,0,2.754,2.079,0,0,0,0.02,8683520.0,0.0,105.289,1.0,93.559,77.531,0.263,0.473,0,0.012,47751168.0,0.0,16.511,1.0,50.93,50.664,2.363,4.473,0,0.031,66027520.0,0.0,66.467,1.0,120.218,119.081,0.323,3.223,0,0.0,15728640.0,0.0,0,0,2.843,1.888,0,0,0,0.002,15294464.0,0.0,7.133,1.0,16.998,9.363,0.294,2.348,0,0.0,89513984.0,0.0,0,0,2.326,1.878,0,0,0,0.019,43921408.0,0.0,11.644,1.0,35.354,37.647,3.008,4.614,0,0.016,84045824.0,0.013,4.533,1.0,11.955,6.858,3.03,4.66,0,0.003,6770688.0,0.0,0,0,36.18,27.345,0,0,0.0,3.768,35.886,0.0,6.065,31.004,0.067,5.192,30.302,0.0,3.154,35.235,0.0
|
| 41 |
+
2026-05-19 12:51:03,0.047,19877888.0,0.003,16.244,1.0,317.584,346.174,16.83,39.856,0,0.0,5906432.0,0.0,0,0,2.754,2.079,0,0,0,0.023,8716288.0,0.0,105.289,1.0,128.235,106.452,0.263,0.473,0,0.012,47751168.0,0.0,16.511,1.0,50.93,50.664,2.363,4.473,0,0.032,32686080.0,0.0,68.444,1.0,124.824,123.86,0.321,3.198,0,0.0,15728640.0,0.0,0,0,2.843,1.888,0,0,0,0.002,7720960.0,0.0,7.133,1.0,16.998,9.363,0.294,2.348,0,0.001,44658688.0,0.0,0,0,2.326,1.878,0,0,0,0.02,43962368.0,0.0,11.644,1.0,35.619,37.845,3.008,4.614,0,0.017,84471808.0,0.017,4.533,1.0,9.866,5.66,3.03,4.66,0,0.005,6782976.0,0.0,0,0,36.341,27.402,0,0,0.0,3.768,35.886,0.0,6.065,31.004,0.067,5.303,30.334,0.0,3.215,35.235,0.0
|
| 42 |
+
2026-05-19 12:51:08,0.048,20025344.0,0.005,16.244,1.0,317.584,346.174,16.83,39.856,0,0.0,5914624.0,0.0,0,0,2.639,2.1,0,0,0,0.023,8716288.0,0.0,105.289,1.0,128.235,106.452,0.263,0.474,0,0.012,47751168.0,0.0,16.667,1.0,50.836,50.486,2.368,4.474,0,0.032,32686080.0,0.0,68.444,1.0,124.824,123.86,0.321,3.198,0,0.0,15728640.0,0.0,0,0,2.843,1.888,0,0,0,0.002,7720960.0,0.0,7.133,1.0,17.53,9.795,0.294,2.348,0,0.001,44658688.0,0.0,0,0,2.175,1.74,0,0,0,0.023,43962368.0,0.0,11.844,1.0,36.714,39.265,3.008,4.614,0,0.017,84471808.0,0.014,4.533,1.0,11.999,6.89,3.029,4.66,0,0.005,6782976.0,0.0,0,0,36.341,27.402,0,0,0.0,3.789,35.901,0.667,6.065,31.004,0.067,5.314,30.334,0.0,3.215,35.235,0.0
|
| 43 |
+
2026-05-19 12:51:13,0.048,20025344.0,0.005,16.956,1.0,327.591,357.455,16.833,39.857,0,0.0,5914624.0,0.0,0,0,2.828,2.234,0,0,0,0.023,8716288.0,0.0,110.978,1.0,135.659,112.759,0.263,0.474,0,0.014,48889856.0,0.0,16.667,1.0,53.672,53.359,2.374,4.475,0,0.031,34738176.0,0.0,68.444,1.0,122.221,121.41,0.323,3.227,0,0.0,15863808.0,0.0,0,0,1.883,1.27,0,0,0,0.003,7720960.0,0.0,7.289,1.0,14.697,8.212,0.298,2.505,0,0.001,44658688.0,0.0,0,0,2.476,2.024,0,0,0,0.023,43962368.0,0.0,11.844,1.0,36.241,38.481,3.011,4.62,0,0.017,84471808.0,0.014,4.778,1.0,12.584,7.331,3.015,4.634,0,0.005,6782976.0,0.0,0,0,36.341,27.402,0,0,0.0,3.789,35.901,0.667,6.149,30.942,0.0,5.314,30.334,0.0,3.144,35.192,0.0
|
| 44 |
+
2026-05-19 12:51:18,0.05,20025344.0,0.006,16.956,1.0,263.359,287.368,16.833,39.857,0,0.0,5914624.0,0.0,0,0,2.828,2.234,0,0,0,0.023,8716288.0,0.0,110.978,1.0,135.659,112.759,0.263,0.474,0,0.014,48889856.0,0.0,16.667,1.0,53.672,53.359,2.374,4.475,0,0.031,34738176.0,0.0,68.289,1.0,122.221,121.41,0.324,3.244,0,0.0,15863808.0,0.0,0,0,2.097,1.414,0,0,0,0.003,7733248.0,0.0,7.289,1.0,17.187,9.655,0.298,2.505,0,0.001,44658688.0,0.0,0,0,2.476,2.024,0,0,0,0.022,43986944.0,0.0,11.844,1.0,36.241,38.481,3.011,4.62,0,0.014,84647936.0,0.015,4.778,1.0,12.584,7.331,3.015,4.633,0,0.005,6787072.0,0.0,0,0,37.523,28.427,0,0,0.0,3.789,35.901,0.667,6.149,30.942,0.0,5.283,30.373,0.0,3.142,35.192,0.0
|
| 45 |
+
2026-05-19 12:51:23,0.049,20107264.0,0.005,16.956,1.0,314.518,347.482,16.833,39.857,0,0.0,5914624.0,0.0,0,0,2.828,2.234,0,0,0,0.022,8736768.0,0.0,110.978,1.0,130.47,108.425,0.263,0.474,0,0.013,48951296.0,0.0,16.222,1.0,44.217,43.959,2.429,4.486,0,0.031,34738176.0,0.0,68.289,1.0,121.942,121.198,0.324,3.244,0,0.0,15863808.0,0.0,0,0,2.568,1.731,0,0,0,0.003,7733248.0,0.0,7.289,1.0,17.187,9.655,0.298,2.505,0,0.001,44658688.0,0.0,0,0,2.502,2.081,0,0,0,0.023,43986944.0,0.0,11.733,1.0,36.241,38.481,3.009,4.617,0,0.017,84647936.0,0.018,4.778,1.0,12.584,7.331,3.015,4.633,0,0.005,6787072.0,0.0,0,0,37.523,28.427,0,0,0.0,3.888,35.736,0.0,6.149,30.942,0.0,5.3,30.373,0.0,3.142,35.192,0.0
|
| 46 |
+
2026-05-19 12:51:28,0.049,20107264.0,0.005,16.156,1.0,314.518,347.482,16.877,39.794,0,0.0,5914624.0,0.0,0,0,2.106,1.664,0,0,0,0.022,8736768.0,0.0,105.333,1.0,129.833,107.924,0.262,0.472,0,0.013,48951296.0,0.0,16.222,1.0,39.076,38.784,2.418,4.484,0,0.03,36823040.0,0.0,68.289,1.0,121.942,121.198,0.323,3.235,0,0.0,16146432.0,0.0,0,0,2.568,1.731,0,0,0,0.003,7733248.0,0.0,7.044,1.0,16.974,9.549,0.291,2.156,0,0.001,44658688.0,0.0,0,0,2.77,2.157,0,0,0,0.023,43986944.0,0.0,11.733,1.0,28.959,30.567,3.01,4.617,0,0.017,84647936.0,0.018,4.4,1.0,9.463,5.513,3.02,4.636,0,0.005,6787072.0,0.0,0,0,37.069,28.084,0,0,0.0,3.888,35.736,0.0,6.006,31.014,0.0,5.3,30.373,0.0,3.213,35.22,0.0
|
| 47 |
+
2026-05-19 12:51:33,0.041,20525056.0,0.002,16.156,1.0,314.518,347.482,16.877,39.794,0,0.0,5914624.0,0.0,0,0,2.1,1.753,0,0,0,0.014,8740864.0,0.0,105.333,1.0,129.833,107.924,0.262,0.472,0,0.011,48922624.0,0.0,16.222,1.0,52.662,51.461,2.418,4.484,0,0.03,36823040.0,0.0,65.844,1.0,119.25,118.432,0.325,3.264,0,0.0,16146432.0,0.0,0,0,2.594,1.901,0,0,0,0.003,7733248.0,0.0,7.044,1.0,16.675,9.362,0.291,2.156,0,0.001,44662784.0,0.0,0,0,2.77,2.157,0,0,0,0.022,43991040.0,0.0,11.733,1.0,34.618,36.54,3.01,4.617,0,0.014,84647936.0,0.015,4.4,1.0,8.327,4.788,3.02,4.636,0,0.005,6787072.0,0.0,0,0,36.033,27.447,0,0,0.0,3.888,35.736,0.0,6.006,31.014,0.0,5.275,30.375,0.0,3.197,35.22,0.0
|
| 48 |
+
2026-05-19 12:51:38,0.048,20525056.0,0.003,16.156,1.0,306.91,340.955,16.877,39.794,0,0.0,5914624.0,0.0,0,0,2.1,1.753,0,0,0,0.015,8740864.0,0.0,105.333,1.0,94.484,78.641,0.263,0.473,0,0.012,48922624.0,0.0,15.844,1.0,51.856,50.359,2.421,4.484,0,0.03,36823040.0,0.0,65.844,1.0,119.25,118.432,0.325,3.264,0,0.0,16146432.0,0.0,0,0,2.79,2.029,0,0,0,0.003,7745536.0,0.0,7.044,1.0,16.675,9.362,0.291,2.156,0,0.001,44662784.0,0.0,0,0,2.814,2.139,0,0,0,0.022,43991040.0,0.0,11.533,1.0,34.618,36.54,3.012,4.621,0,0.015,84987904.0,0.019,4.4,1.0,11.822,6.875,3.02,4.636,0,0.005,6791168.0,0.0,0,0,36.033,27.447,0,0,0.0,3.915,35.665,0.0,6.006,31.014,0.0,5.211,30.375,0.0,3.197,35.22,0.0
|
| 49 |
+
2026-05-19 12:51:43,0.048,20525056.0,0.003,16.311,1.0,306.91,340.955,16.944,39.884,0,0.0,5914624.0,0.0,0,0,2.249,1.877,0,0,0,0.017,8740864.0,0.0,110.044,1.0,123.554,102.836,0.263,0.473,0,0.012,48922624.0,0.0,15.844,1.0,51.856,50.359,2.413,4.483,0,0.03,34742272.0,0.01,65.844,1.0,115.341,114.619,0.324,3.253,0,0.0,16277504.0,0.0,0,0,2.736,2.057,0,0,0,0.003,7745536.0,0.0,7.067,1.0,16.269,9.108,0.292,2.191,0,0.001,44662784.0,0.0,0,0,2.511,1.962,0,0,0,0.018,43991040.0,0.0,11.533,1.0,35.764,38.273,3.012,4.621,0,0.015,84987904.0,0.019,4.6,1.0,11.822,6.875,2.977,4.595,0,0.005,6791168.0,0.0,0,0,34.819,26.624,0,0,0.0,3.915,35.665,0.0,6.076,31.045,0.0,5.211,30.375,0.0,3.058,35.288,0.0
|
| 50 |
+
2026-05-19 12:51:48,0.048,20525056.0,0.003,16.311,1.0,295.6,330.585,16.944,39.884,0,0.0,5951488.0,0.0,0,0,2.164,1.743,0,0,0,0.021,8740864.0,0.0,110.044,1.0,123.554,102.836,0.263,0.473,0,0.012,48922624.0,0.0,15.844,1.0,51.856,50.359,2.413,4.483,0,0.03,34742272.0,0.01,67.311,1.0,118.409,117.836,0.323,3.241,0,0.0,16277504.0,0.0,0,0,2.736,2.057,0,0,0,0.003,7745536.0,0.0,7.067,1.0,12.644,7.079,0.292,2.191,0,0.001,44658688.0,0.0,0,0,2.511,1.962,0,0,0,0.022,43982848.0,0.0,11.533,1.0,31.124,33.493,3.012,4.621,0,0.015,89378816.0,0.016,4.6,1.0,11.662,6.833,2.975,4.595,0,0.005,6791168.0,0.0,0,0,36.586,29.167,0,0,0.0,3.915,35.665,0.0,6.076,31.045,0.0,5.192,30.26,0.0,3.001,35.288,0.0
|
| 51 |
+
2026-05-19 12:51:53,0.049,20291584.0,0.001,16.311,1.0,301.304,334.772,16.944,39.884,0,0.0,5951488.0,0.0,0,0,2.164,1.743,0,0,0,0.017,8740864.0,0.0,110.044,1.0,125.755,104.909,0.263,0.473,0,0.007,48922624.0,0.0,16.733,1.0,54.665,52.131,2.366,4.473,0,0.03,34742272.0,0.01,67.311,1.0,118.409,117.836,0.323,3.241,0,0.0,16277504.0,0.0,0,0,2.074,1.758,0,0,0,0.003,7745536.0,0.0,7.067,1.0,16.145,9.106,0.292,2.191,0,0.001,44658688.0,0.0,0,0,2.614,1.96,0,0,0,0.022,43982848.0,0.0,11.822,1.0,30.959,33.316,3.012,4.621,0,0.015,89378816.0,0.016,4.6,1.0,11.662,6.833,2.975,4.595,0,0.005,6795264.0,0.0,0,0,36.586,29.167,0,0,0.0,3.871,35.691,0.0,6.076,31.045,0.0,5.244,30.26,0.0,3.001,35.288,0.0
|
| 52 |
+
2026-05-19 12:51:58,0.049,20291584.0,0.001,16.622,1.0,301.304,334.772,17.166,40.758,0,0.0,5951488.0,0.0,0,0,2.29,1.862,0,0,0,0.015,8740864.0,0.0,109.6,1.0,125.755,104.909,0.263,0.474,0,0.008,48922624.0,0.0,16.733,1.0,54.665,52.131,2.389,4.478,0,0.031,34742272.0,0.015,67.311,1.0,119.414,118.788,0.331,3.369,0,0.0,16277504.0,0.0,0,0,2.513,2.135,0,0,0,0.003,7757824.0,0.0,7.111,1.0,16.005,9.097,0.301,2.63,0,0.001,44658688.0,0.0,0,0,2.799,2.141,0,0,0,0.022,43982848.0,0.0,11.822,1.0,27.996,30.127,3.011,4.62,0,0.015,89378816.0,0.016,4.867,1.0,11.818,6.96,3.0,4.646,0,0.005,6795264.0,0.0,0,0,30.597,25.078,0,0,0.0,3.871,35.691,0.0,6.213,31.083,0.0,5.244,30.26,0.0,3.053,35.187,0.0
|
| 53 |
+
2026-05-19 12:52:03,0.049,20332544.0,0.001,16.622,1.0,305.191,337.793,17.166,40.758,0,0.0,5951488.0,0.0,0,0,2.29,1.862,0,0,0,0.022,8749056.0,0.0,109.6,1.0,129.044,107.917,0.263,0.474,0,0.012,48922624.0,0.0,16.733,1.0,54.665,52.131,2.389,4.478,0,0.03,35229696.0,0.009,66.089,1.0,119.414,118.788,0.329,3.345,0,0.0,16277504.0,0.0,0,0,2.513,2.135,0,0,0,0.003,7757824.0,0.0,7.111,1.0,16.005,9.097,0.301,2.63,0,0.0,44658688.0,0.0,0,0,2.799,2.141,0,0,0,0.023,43986944.0,0.0,11.822,1.0,25.667,28.022,3.011,4.62,0,0.016,89378816.0,0.018,4.867,1.0,11.818,6.96,2.997,4.645,0,0.005,6795264.0,0.0,0,0,36.983,30.312,0,0,0.0,3.871,35.691,0.0,6.213,31.083,0.0,5.307,30.45,0.0,3.006,35.187,0.0
|
| 54 |
+
2026-05-19 12:52:08,0.05,20332544.0,0.001,16.622,1.0,305.397,338.464,17.166,40.758,0,0.0,5951488.0,0.0,0,0,2.047,1.697,0,0,0,0.022,8749056.0,0.0,109.6,1.0,106.046,88.684,0.263,0.474,0,0.012,48922624.0,0.0,16.844,1.0,44.144,41.709,2.36,4.472,0,0.03,35229696.0,0.009,66.089,1.0,94.546,94.05,0.329,3.345,0,0.0,15884288.0,0.0,0,0,2.513,2.135,0,0,0,0.003,7770112.0,0.0,7.111,1.0,16.244,9.225,0.301,2.63,0,0.0,44658688.0,0.0,0,0,2.799,2.141,0,0,0,0.023,43986944.0,0.0,12.0,1.0,35.279,38.042,3.011,4.62,0,0.017,85229568.0,0.023,4.867,1.0,8.659,5.138,2.995,4.645,0,0.004,6795264.0,0.0,0,0,28.772,23.582,0,0,0.0,3.846,35.751,0.0,6.213,31.083,0.0,5.293,30.45,0.0,3.006,35.187,0.0
|
benchmark/boutique/codedefect/32/tool_cache.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
benchmark/boutique/codedefect/33/code/adservice/src/main/java/hipstershop/AdService.java
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2018, Google LLC.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
package hipstershop;
|
| 18 |
+
|
| 19 |
+
import com.google.common.collect.ImmutableListMultimap;
|
| 20 |
+
import com.google.common.collect.ImmutableMap;
|
| 21 |
+
import com.google.common.collect.Iterables;
|
| 22 |
+
import hipstershop.Demo.Ad;
|
| 23 |
+
import hipstershop.Demo.AdRequest;
|
| 24 |
+
import hipstershop.Demo.AdResponse;
|
| 25 |
+
import io.grpc.Server;
|
| 26 |
+
import io.grpc.ServerBuilder;
|
| 27 |
+
import io.grpc.StatusRuntimeException;
|
| 28 |
+
import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
|
| 29 |
+
import io.grpc.services.*;
|
| 30 |
+
import io.grpc.stub.StreamObserver;
|
| 31 |
+
import java.io.IOException;
|
| 32 |
+
import java.util.ArrayList;
|
| 33 |
+
import java.util.Collection;
|
| 34 |
+
import java.util.List;
|
| 35 |
+
import java.util.Random;
|
| 36 |
+
import java.util.concurrent.TimeUnit;
|
| 37 |
+
import org.apache.logging.log4j.Level;
|
| 38 |
+
import org.apache.logging.log4j.LogManager;
|
| 39 |
+
import org.apache.logging.log4j.Logger;
|
| 40 |
+
|
| 41 |
+
public final class AdService {
|
| 42 |
+
|
| 43 |
+
private static final Logger logger = LogManager.getLogger(AdService.class);
|
| 44 |
+
|
| 45 |
+
@SuppressWarnings("FieldCanBeLocal")
|
| 46 |
+
private static int MAX_ADS_TO_SERVE = 2;
|
| 47 |
+
|
| 48 |
+
private Server server;
|
| 49 |
+
private HealthStatusManager healthMgr;
|
| 50 |
+
|
| 51 |
+
private static final AdService service = new AdService();
|
| 52 |
+
|
| 53 |
+
private void start() throws IOException {
|
| 54 |
+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "9555"));
|
| 55 |
+
healthMgr = new HealthStatusManager();
|
| 56 |
+
|
| 57 |
+
server =
|
| 58 |
+
ServerBuilder.forPort(port)
|
| 59 |
+
.addService(new AdServiceImpl())
|
| 60 |
+
.addService(healthMgr.getHealthService())
|
| 61 |
+
.build()
|
| 62 |
+
.start();
|
| 63 |
+
logger.info("Ad Service started, listening on " + port);
|
| 64 |
+
Runtime.getRuntime()
|
| 65 |
+
.addShutdownHook(
|
| 66 |
+
new Thread(
|
| 67 |
+
() -> {
|
| 68 |
+
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
|
| 69 |
+
System.err.println(
|
| 70 |
+
"*** shutting down gRPC ads server since JVM is shutting down");
|
| 71 |
+
AdService.this.stop();
|
| 72 |
+
System.err.println("*** server shut down");
|
| 73 |
+
}));
|
| 74 |
+
healthMgr.setStatus("", ServingStatus.SERVING);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
private void stop() {
|
| 78 |
+
if (server != null) {
|
| 79 |
+
healthMgr.clearStatus("");
|
| 80 |
+
server.shutdown();
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
private static class AdServiceImpl extends hipstershop.AdServiceGrpc.AdServiceImplBase {
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Retrieves ads based on context provided in the request {@code AdRequest}.
|
| 88 |
+
*
|
| 89 |
+
* @param req the request containing context.
|
| 90 |
+
* @param responseObserver the stream observer which gets notified with the value of {@code
|
| 91 |
+
* AdResponse}
|
| 92 |
+
*/
|
| 93 |
+
@Override
|
| 94 |
+
public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {
|
| 95 |
+
AdService service = AdService.getInstance();
|
| 96 |
+
try {
|
| 97 |
+
List<Ad> allAds = new ArrayList<>();
|
| 98 |
+
logger.info("received ad request (context_words=" + req.getContextKeysList() + ")");
|
| 99 |
+
if (req.getContextKeysCount() > 0) {
|
| 100 |
+
for (int i = 0; i < req.getContextKeysCount(); i++) {
|
| 101 |
+
Collection<Ad> ads = service.getAdsByCategory(req.getContextKeys(i));
|
| 102 |
+
allAds.addAll(ads);
|
| 103 |
+
}
|
| 104 |
+
} else {
|
| 105 |
+
allAds = service.getRandomAds();
|
| 106 |
+
}
|
| 107 |
+
if (allAds.isEmpty()) {
|
| 108 |
+
// Serve random ads.
|
| 109 |
+
allAds = service.getRandomAds();
|
| 110 |
+
}
|
| 111 |
+
AdResponse reply = AdResponse.newBuilder().addAllAds(allAds).build();
|
| 112 |
+
responseObserver.onNext(reply);
|
| 113 |
+
responseObserver.onCompleted();
|
| 114 |
+
} catch (StatusRuntimeException e) {
|
| 115 |
+
logger.log(Level.WARN, "GetAds Failed with status {}", e.getStatus());
|
| 116 |
+
responseObserver.onError(e);
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
private static final ImmutableListMultimap<String, Ad> adsMap = createAdsMap();
|
| 122 |
+
|
| 123 |
+
private Collection<Ad> getAdsByCategory(String category) {
|
| 124 |
+
return adsMap.get(category);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
private static final Random random = new Random();
|
| 128 |
+
|
| 129 |
+
private List<Ad> getRandomAds() {
|
| 130 |
+
List<Ad> ads = new ArrayList<>(MAX_ADS_TO_SERVE);
|
| 131 |
+
Collection<Ad> allAds = adsMap.values();
|
| 132 |
+
for (int i = 0; i < MAX_ADS_TO_SERVE; i++) {
|
| 133 |
+
ads.add(Iterables.get(allAds, random.nextInt(allAds.size())));
|
| 134 |
+
}
|
| 135 |
+
return ads;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
private static AdService getInstance() {
|
| 139 |
+
return service;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
/** Await termination on the main thread since the grpc library uses daemon threads. */
|
| 143 |
+
private void blockUntilShutdown() throws InterruptedException {
|
| 144 |
+
if (server != null) {
|
| 145 |
+
server.awaitTermination();
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
private static ImmutableListMultimap<String, Ad> createAdsMap() {
|
| 150 |
+
Ad hairdryer =
|
| 151 |
+
Ad.newBuilder()
|
| 152 |
+
.setRedirectUrl("/product/2ZYFJ3GM2N")
|
| 153 |
+
.setText("Hairdryer for sale. 50% off.")
|
| 154 |
+
.build();
|
| 155 |
+
Ad tankTop =
|
| 156 |
+
Ad.newBuilder()
|
| 157 |
+
.setRedirectUrl("/product/66VCHSJNUP")
|
| 158 |
+
.setText("Tank top for sale. 20% off.")
|
| 159 |
+
.build();
|
| 160 |
+
Ad candleHolder =
|
| 161 |
+
Ad.newBuilder()
|
| 162 |
+
.setRedirectUrl("/product/0PUK6V6EV0")
|
| 163 |
+
.setText("Candle holder for sale. 30% off.")
|
| 164 |
+
.build();
|
| 165 |
+
Ad bambooGlassJar =
|
| 166 |
+
Ad.newBuilder()
|
| 167 |
+
.setRedirectUrl("/product/9SIQT8TOJO")
|
| 168 |
+
.setText("Bamboo glass jar for sale. 10% off.")
|
| 169 |
+
.build();
|
| 170 |
+
Ad watch =
|
| 171 |
+
Ad.newBuilder()
|
| 172 |
+
.setRedirectUrl("/product/1YMWWN1N4O")
|
| 173 |
+
.setText("Watch for sale. Buy one, get second kit for free")
|
| 174 |
+
.build();
|
| 175 |
+
Ad mug =
|
| 176 |
+
Ad.newBuilder()
|
| 177 |
+
.setRedirectUrl("/product/6E92ZMYYFZ")
|
| 178 |
+
.setText("Mug for sale. Buy two, get third one for free")
|
| 179 |
+
.build();
|
| 180 |
+
Ad loafers =
|
| 181 |
+
Ad.newBuilder()
|
| 182 |
+
.setRedirectUrl("/product/L9ECAV7KIM")
|
| 183 |
+
.setText("Loafers for sale. Buy one, get second one for free")
|
| 184 |
+
.build();
|
| 185 |
+
return ImmutableListMultimap.<String, Ad>builder()
|
| 186 |
+
.putAll("clothing", tankTop)
|
| 187 |
+
.putAll("accessories", watch)
|
| 188 |
+
.putAll("footwear", loafers)
|
| 189 |
+
.putAll("hair", hairdryer)
|
| 190 |
+
.putAll("decor", candleHolder)
|
| 191 |
+
.putAll("kitchen", bambooGlassJar, mug)
|
| 192 |
+
.build();
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
private static void initStats() {
|
| 196 |
+
if (System.getenv("DISABLE_STATS") != null) {
|
| 197 |
+
logger.info("Stats disabled.");
|
| 198 |
+
return;
|
| 199 |
+
}
|
| 200 |
+
logger.info("Stats enabled, but temporarily unavailable");
|
| 201 |
+
|
| 202 |
+
long sleepTime = 10; /* seconds */
|
| 203 |
+
int maxAttempts = 5;
|
| 204 |
+
|
| 205 |
+
// TODO(arbrown) Implement OpenTelemetry stats
|
| 206 |
+
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
private static void initTracing() {
|
| 210 |
+
if (System.getenv("DISABLE_TRACING") != null) {
|
| 211 |
+
logger.info("Tracing disabled.");
|
| 212 |
+
return;
|
| 213 |
+
}
|
| 214 |
+
logger.info("Tracing enabled but temporarily unavailable");
|
| 215 |
+
logger.info("See https://github.com/GoogleCloudPlatform/microservices-demo/issues/422 for more info.");
|
| 216 |
+
|
| 217 |
+
// TODO(arbrown) Implement OpenTelemetry tracing
|
| 218 |
+
|
| 219 |
+
logger.info("Tracing enabled - Stackdriver exporter initialized.");
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/** Main launches the server from the command line. */
|
| 223 |
+
public static void main(String[] args) throws IOException, InterruptedException {
|
| 224 |
+
|
| 225 |
+
new Thread(
|
| 226 |
+
() -> {
|
| 227 |
+
initStats();
|
| 228 |
+
initTracing();
|
| 229 |
+
})
|
| 230 |
+
.start();
|
| 231 |
+
|
| 232 |
+
// Start the RPC server. You shouldn't see any output from gRPC before this.
|
| 233 |
+
logger.info("AdService starting.");
|
| 234 |
+
final AdService service = AdService.getInstance();
|
| 235 |
+
service.start();
|
| 236 |
+
service.blockUntilShutdown();
|
| 237 |
+
}
|
| 238 |
+
}
|
benchmark/boutique/codedefect/33/code/adservice/src/main/java/hipstershop/AdServiceClient.java
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2018, Google LLC.
|
| 3 |
+
*
|
| 4 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
* you may not use this file except in compliance with the License.
|
| 6 |
+
* You may obtain a copy of the License at
|
| 7 |
+
*
|
| 8 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
* See the License for the specific language governing permissions and
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
package hipstershop;
|
| 18 |
+
|
| 19 |
+
import hipstershop.Demo.Ad;
|
| 20 |
+
import hipstershop.Demo.AdRequest;
|
| 21 |
+
import hipstershop.Demo.AdResponse;
|
| 22 |
+
import io.grpc.ManagedChannel;
|
| 23 |
+
import io.grpc.ManagedChannelBuilder;
|
| 24 |
+
import io.grpc.StatusRuntimeException;
|
| 25 |
+
import java.util.concurrent.TimeUnit;
|
| 26 |
+
import javax.annotation.Nullable;
|
| 27 |
+
import org.apache.logging.log4j.Level;
|
| 28 |
+
import org.apache.logging.log4j.LogManager;
|
| 29 |
+
import org.apache.logging.log4j.Logger;
|
| 30 |
+
|
| 31 |
+
/** A simple client that requests ads from the Ads Service. */
|
| 32 |
+
public class AdServiceClient {
|
| 33 |
+
|
| 34 |
+
private static final Logger logger = LogManager.getLogger(AdServiceClient.class);
|
| 35 |
+
|
| 36 |
+
private final ManagedChannel channel;
|
| 37 |
+
private final hipstershop.AdServiceGrpc.AdServiceBlockingStub blockingStub;
|
| 38 |
+
|
| 39 |
+
/** Construct client connecting to Ad Service at {@code host:port}. */
|
| 40 |
+
private AdServiceClient(String host, int port) {
|
| 41 |
+
this(
|
| 42 |
+
ManagedChannelBuilder.forAddress(host, port)
|
| 43 |
+
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
|
| 44 |
+
// needing certificates.
|
| 45 |
+
.usePlaintext()
|
| 46 |
+
.build());
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/** Construct client for accessing RouteGuide server using the existing channel. */
|
| 50 |
+
private AdServiceClient(ManagedChannel channel) {
|
| 51 |
+
this.channel = channel;
|
| 52 |
+
blockingStub = hipstershop.AdServiceGrpc.newBlockingStub(channel);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
private void shutdown() throws InterruptedException {
|
| 56 |
+
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/** Get Ads from Server. */
|
| 60 |
+
public void getAds(String contextKey) {
|
| 61 |
+
logger.info("Get Ads with context " + contextKey + " ...");
|
| 62 |
+
AdRequest request = AdRequest.newBuilder().addContextKeys(contextKey).build();
|
| 63 |
+
AdResponse response;
|
| 64 |
+
|
| 65 |
+
try {
|
| 66 |
+
response = blockingStub.getAds(request);
|
| 67 |
+
} catch (StatusRuntimeException e) {
|
| 68 |
+
logger.log(Level.WARN, "RPC failed: " + e.getStatus());
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
for (Ad ads : response.getAdsList()) {
|
| 72 |
+
logger.info("Ads: " + ads.getText());
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
private static int getPortOrDefaultFromArgs(String[] args) {
|
| 77 |
+
int portNumber = 9555;
|
| 78 |
+
if (2 < args.length) {
|
| 79 |
+
try {
|
| 80 |
+
portNumber = Integer.parseInt(args[2]);
|
| 81 |
+
} catch (NumberFormatException e) {
|
| 82 |
+
logger.warn(String.format("Port %s is invalid, use default port %d.", args[2], 9555));
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
return portNumber;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
private static String getStringOrDefaultFromArgs(
|
| 89 |
+
String[] args, int index, @Nullable String defaultString) {
|
| 90 |
+
String s = defaultString;
|
| 91 |
+
if (index < args.length) {
|
| 92 |
+
s = args[index];
|
| 93 |
+
}
|
| 94 |
+
return s;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Ads Service Client main. If provided, the first element of {@code args} is the context key to
|
| 99 |
+
* get the ads from the Ads Service
|
| 100 |
+
*/
|
| 101 |
+
public static void main(String[] args) throws InterruptedException {
|
| 102 |
+
// Add final keyword to pass checkStyle.
|
| 103 |
+
final String contextKeys = getStringOrDefaultFromArgs(args, 0, "camera");
|
| 104 |
+
final String host = getStringOrDefaultFromArgs(args, 1, "localhost");
|
| 105 |
+
final int serverPort = getPortOrDefaultFromArgs(args);
|
| 106 |
+
|
| 107 |
+
AdServiceClient client = new AdServiceClient(host, serverPort);
|
| 108 |
+
try {
|
| 109 |
+
client.getAds(contextKeys);
|
| 110 |
+
} finally {
|
| 111 |
+
client.shutdown();
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
logger.info("Exiting AdServiceClient...");
|
| 115 |
+
}
|
| 116 |
+
}
|
benchmark/boutique/codedefect/33/code/cartservice/src/Program.cs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
using Microsoft.AspNetCore.Hosting;
|
| 16 |
+
using Microsoft.Extensions.Hosting;
|
| 17 |
+
using cartservice;
|
| 18 |
+
|
| 19 |
+
CreateHostBuilder(args).Build().Run();
|
| 20 |
+
|
| 21 |
+
static IHostBuilder CreateHostBuilder(string[] args) =>
|
| 22 |
+
Host.CreateDefaultBuilder(args)
|
| 23 |
+
.ConfigureWebHostDefaults(webBuilder =>
|
| 24 |
+
{
|
| 25 |
+
webBuilder.UseStartup<Startup>();
|
| 26 |
+
});
|
benchmark/boutique/codedefect/33/code/cartservice/src/Startup.cs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using Microsoft.AspNetCore.Builder;
|
| 3 |
+
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
| 4 |
+
using Microsoft.AspNetCore.Hosting;
|
| 5 |
+
using Microsoft.AspNetCore.Http;
|
| 6 |
+
using Microsoft.Extensions.Configuration;
|
| 7 |
+
using Microsoft.Extensions.DependencyInjection;
|
| 8 |
+
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
| 9 |
+
using Microsoft.Extensions.Hosting;
|
| 10 |
+
using cartservice.cartstore;
|
| 11 |
+
using cartservice.services;
|
| 12 |
+
using Microsoft.Extensions.Caching.StackExchangeRedis;
|
| 13 |
+
|
| 14 |
+
namespace cartservice
|
| 15 |
+
{
|
| 16 |
+
public class Startup
|
| 17 |
+
{
|
| 18 |
+
public Startup(IConfiguration configuration)
|
| 19 |
+
{
|
| 20 |
+
Configuration = configuration;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
public IConfiguration Configuration { get; }
|
| 24 |
+
|
| 25 |
+
// This method gets called by the runtime. Use this method to add services to the container.
|
| 26 |
+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
| 27 |
+
public void ConfigureServices(IServiceCollection services)
|
| 28 |
+
{
|
| 29 |
+
string redisAddress = Configuration["REDIS_ADDR"];
|
| 30 |
+
string spannerProjectId = Configuration["SPANNER_PROJECT"];
|
| 31 |
+
string spannerConnectionString = Configuration["SPANNER_CONNECTION_STRING"];
|
| 32 |
+
string alloyDBConnectionString = Configuration["ALLOYDB_PRIMARY_IP"];
|
| 33 |
+
|
| 34 |
+
if (!string.IsNullOrEmpty(redisAddress))
|
| 35 |
+
{
|
| 36 |
+
services.AddStackExchangeRedisCache(options =>
|
| 37 |
+
{
|
| 38 |
+
options.Configuration = redisAddress;
|
| 39 |
+
});
|
| 40 |
+
services.AddSingleton<ICartStore, RedisCartStore>();
|
| 41 |
+
}
|
| 42 |
+
else if (!string.IsNullOrEmpty(spannerProjectId) || !string.IsNullOrEmpty(spannerConnectionString))
|
| 43 |
+
{
|
| 44 |
+
services.AddSingleton<ICartStore, SpannerCartStore>();
|
| 45 |
+
}
|
| 46 |
+
else if (!string.IsNullOrEmpty(alloyDBConnectionString))
|
| 47 |
+
{
|
| 48 |
+
Console.WriteLine("Creating AlloyDB cart store");
|
| 49 |
+
services.AddSingleton<ICartStore, AlloyDBCartStore>();
|
| 50 |
+
}
|
| 51 |
+
else
|
| 52 |
+
{
|
| 53 |
+
Console.WriteLine("Redis cache host(hostname+port) was not specified. Starting a cart service using in memory store");
|
| 54 |
+
services.AddDistributedMemoryCache();
|
| 55 |
+
services.AddSingleton<ICartStore, RedisCartStore>();
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
services.AddGrpc();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
| 63 |
+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
| 64 |
+
{
|
| 65 |
+
if (env.IsDevelopment())
|
| 66 |
+
{
|
| 67 |
+
app.UseDeveloperExceptionPage();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
app.UseRouting();
|
| 71 |
+
|
| 72 |
+
app.UseEndpoints(endpoints =>
|
| 73 |
+
{
|
| 74 |
+
endpoints.MapGrpcService<CartService>();
|
| 75 |
+
endpoints.MapGrpcService<cartservice.services.HealthCheckService>();
|
| 76 |
+
|
| 77 |
+
endpoints.MapGet("/", async context =>
|
| 78 |
+
{
|
| 79 |
+
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
|
| 80 |
+
});
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|