allenwang37 commited on
Commit
22ed0ac
·
verified ·
1 Parent(s): 56470e2

Publish Cloud-OpsBench v1.0.0 benchmark artifacts (part 9)

Browse files

Source: https://github.com/LLM4Ops/Cloud-OpsBench/tree/ea05dafbc87b5985df8721622d63d4229c2b4224

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. benchmark/boutique/codedefect/21/raw_data/logs.json +0 -0
  2. benchmark/boutique/codedefect/21/raw_data/metrics.csv +54 -0
  3. benchmark/boutique/codedefect/21/tool_cache.json +0 -0
  4. benchmark/boutique/codedefect/22/code/adservice/src/main/java/hipstershop/AdService.java +238 -0
  5. benchmark/boutique/codedefect/22/code/adservice/src/main/java/hipstershop/AdServiceClient.java +116 -0
  6. benchmark/boutique/codedefect/22/code/cartservice/src/Program.cs +26 -0
  7. benchmark/boutique/codedefect/22/code/cartservice/src/Startup.cs +84 -0
  8. benchmark/boutique/codedefect/22/code/cartservice/src/cartstore/AlloyDBCartStore.cs +177 -0
  9. benchmark/boutique/codedefect/22/code/cartservice/src/cartstore/ICartStore.cs +26 -0
  10. benchmark/boutique/codedefect/22/code/cartservice/src/cartstore/RedisCartStore.cs +118 -0
  11. benchmark/boutique/codedefect/22/code/cartservice/src/cartstore/SpannerCartStore.cs +185 -0
  12. benchmark/boutique/codedefect/22/code/cartservice/src/services/CartService.cs +51 -0
  13. benchmark/boutique/codedefect/22/code/cartservice/src/services/HealthCheckService.cs +41 -0
  14. benchmark/boutique/codedefect/22/code/checkoutservice/main.go +402 -0
  15. benchmark/boutique/codedefect/22/code/checkoutservice/money/money.go +132 -0
  16. benchmark/boutique/codedefect/22/code/currencyservice/client.js +68 -0
  17. benchmark/boutique/codedefect/22/code/currencyservice/server.js +198 -0
  18. benchmark/boutique/codedefect/22/code/emailservice/email_client.py +39 -0
  19. benchmark/boutique/codedefect/22/code/emailservice/email_server.py +200 -0
  20. benchmark/boutique/codedefect/22/code/emailservice/logger.py +41 -0
  21. benchmark/boutique/codedefect/22/code/frontend/deployment_details.go +64 -0
  22. benchmark/boutique/codedefect/22/code/frontend/handlers.go +635 -0
  23. benchmark/boutique/codedefect/22/code/frontend/main.go +235 -0
  24. benchmark/boutique/codedefect/22/code/frontend/middleware.go +111 -0
  25. benchmark/boutique/codedefect/22/code/frontend/money/money.go +132 -0
  26. benchmark/boutique/codedefect/22/code/frontend/packaging_info.go +79 -0
  27. benchmark/boutique/codedefect/22/code/frontend/rpc.go +127 -0
  28. benchmark/boutique/codedefect/22/code/frontend/validator/validator.go +83 -0
  29. benchmark/boutique/codedefect/22/code/paymentservice/charge.js +86 -0
  30. benchmark/boutique/codedefect/22/code/paymentservice/index.js +75 -0
  31. benchmark/boutique/codedefect/22/code/paymentservice/logger.js +27 -0
  32. benchmark/boutique/codedefect/22/code/paymentservice/server.js +106 -0
  33. benchmark/boutique/codedefect/22/code/productcatalogservice/catalog_loader.go +161 -0
  34. benchmark/boutique/codedefect/22/code/productcatalogservice/product_catalog.go +83 -0
  35. benchmark/boutique/codedefect/22/code/productcatalogservice/server.go +217 -0
  36. benchmark/boutique/codedefect/22/code/recommendationservice/client.py +39 -0
  37. benchmark/boutique/codedefect/22/code/recommendationservice/logger.py +41 -0
  38. benchmark/boutique/codedefect/22/code/recommendationservice/recommendation_server.py +156 -0
  39. benchmark/boutique/codedefect/22/code/shippingservice/main.go +183 -0
  40. benchmark/boutique/codedefect/22/code/shippingservice/quote.go +48 -0
  41. benchmark/boutique/codedefect/22/code/shippingservice/tracker.go +47 -0
  42. benchmark/boutique/codedefect/22/metadata.json +10 -0
  43. benchmark/boutique/codedefect/22/raw_data/alert.json +26 -0
  44. benchmark/boutique/codedefect/22/raw_data/k8s_states.json +0 -0
  45. benchmark/boutique/codedefect/22/raw_data/logs.json +0 -0
  46. benchmark/boutique/codedefect/22/raw_data/metrics.csv +54 -0
  47. benchmark/boutique/codedefect/22/tool_cache.json +0 -0
  48. benchmark/boutique/codedefect/23/code/adservice/src/main/java/hipstershop/AdService.java +238 -0
  49. benchmark/boutique/codedefect/23/code/adservice/src/main/java/hipstershop/AdServiceClient.java +116 -0
  50. benchmark/boutique/codedefect/23/code/cartservice/src/Program.cs +26 -0
benchmark/boutique/codedefect/21/raw_data/logs.json ADDED
The diff for this file is too large to render. See raw diff
 
benchmark/boutique/codedefect/21/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:36:37,0.002,28930048.0,0.0,0.235,1.0,10.855,10.931,36.703,1797.8,0,0.001,12103680.0,0.0,0.0,0.0,5.067,4.686,24.761,186.934,0,0.0,15507456.0,0.0,1.527,1.0,5.638,3.581,0.272,0.49,0,0.025,78843904.0,0.124,0.265,1.0,3.522,3.047,3.64,2097.845,0,0.004,55726080.0,0.009,0.434,1.0,4.262,2.81,3.34,6.563,0.0,0.001,31256576.0,0.0,0.0,0.0,2.5,1.816,0.0,0.0,0,0.0,11730944.0,0.0,0.0,0.0,2.696,1.873,0.0,0.0,0,0.001,89370624.0,0.0,0.0,0.0,3.231,2.161,0.0,0.0,0,0.001,86859776.0,0.0,0.215,1.0,4.798,3.593,3.2,4.96,0,0.003,171401216.0,0.001,0.108,1.0,3.377,2.412,12.531,22.506,0.0,0.004,13488128.0,0.0,0,0,4.292,2.952,0,0,0.0,3.899,34.103,0.0,3.464,30.674,0.0,3.514,30.138,0.0,2.949,33.951,0.0
3
+ 2026-05-19 10:36:42,0.002,29155328.0,0.0,0.285,1.0,10.855,10.931,33.919,1297.8,0,0.001,12103680.0,0.0,0.0,0.0,5.976,5.778,23.926,171.934,0,0.0,15507456.0,0.0,1.833,1.0,5.638,3.581,0.271,0.488,0,0.025,78843904.0,0.124,0.326,1.0,3.919,3.39,3.555,1647.845,0,0.003,56172544.0,0.006,0.868,1.0,5.217,3.99,3.102,4.904,0.0,0.001,31256576.0,0.0,0.0,0.0,2.791,2.028,0.0,0.0,0,0.0,11898880.0,0.0,0.0,0.0,2.375,1.65,0.0,0.0,0,0.001,89370624.0,0.0,0.0,0.0,3.231,2.161,0.0,0.0,0,0.002,86917120.0,0.0,0.26,1.0,4.798,3.593,3.16,4.888,0,0.003,171401216.0,0.001,0.125,1.0,2.841,2.029,3.853,19.984,0.0,0.004,13488128.0,0.0,0,0,3.366,2.316,0,0,0.0,3.899,34.103,0.0,3.56,30.66,0.0,3.514,30.138,0.0,2.989,33.829,0.0
4
+ 2026-05-19 10:36:47,0.002,29155328.0,0.0,0.335,1.0,11.682,11.848,32.205,229.78,0,0.001,12357632.0,0.0,0.029,1.0,4.871,4.71,23.943,104.608,0,0.001,15511552.0,0.0,1.729,1.0,5.469,3.575,0.27,0.486,0,0.022,80211968.0,0.099,0.387,1.0,4.766,4.123,3.406,93.769,0,0.003,56172544.0,0.006,0.998,1.0,5.809,4.535,3.12,4.926,0.0,0.001,31256576.0,0.0,0.06,1.0,3.499,2.542,3.0,4.6,0,0.0,11898880.0,0.0,0.15,1.0,4.087,2.679,0.315,3.073,0,0.0,89370624.0,0.0,0.059,1.0,3.463,2.465,3.0,4.6,0,0.002,86917120.0,0.0,0.232,1.0,4.233,3.269,3.144,4.859,0,0.003,171401216.0,0.001,0.142,1.0,3.776,2.689,3.777,19.638,0.0,0.004,13488128.0,0.0,0,0,4.693,3.301,0,0,0.0,3.899,34.103,0.0,3.56,30.66,0.0,3.554,30.007,0.0,3.124,33.829,0.0
5
+ 2026-05-19 10:36:52,0.002,29155328.0,0.0,0.424,1.0,13.564,14.041,22.445,164.269,0,0.001,12357632.0,0.0,0.035,1.0,6.304,6.457,22.463,49.739,0,0.001,15511552.0,0.0,1.973,1.0,6.427,4.218,0.273,0.492,0,0.011,80211968.0,0.021,0.448,1.0,4.766,4.123,3.226,71.865,0,0.004,56172544.0,0.007,1.129,1.0,5.809,4.535,3.113,4.884,0.0,0.0,31256576.0,0.0,0.071,1.0,3.324,2.449,3.0,4.6,0,0.0,12795904.0,0.0,0.178,1.0,4.087,2.679,0.339,3.483,0,0.001,89403392.0,0.0,0.071,1.0,3.485,2.472,3.0,4.6,0,0.002,86917120.0,0.0,0.266,1.0,4.562,3.567,3.136,4.845,0,0.004,171638784.0,0.001,0.158,1.0,3.776,2.689,3.686,19.127,0.0,0.003,13488128.0,0.0,0,0,4.693,3.301,0,0,0.0,3.8,34.126,0.067,3.56,30.66,0.0,3.617,30.007,0.0,3.124,33.829,0.0
6
+ 2026-05-19 10:36:57,0.001,29851648.0,0.0,0.479,1.0,13.564,14.041,22.221,111.769,0,0.001,12357632.0,0.0,0.04,1.0,7.768,7.397,22.295,48.736,0,0.001,15511552.0,0.0,2.218,1.0,5.978,3.937,0.273,0.492,0,0.013,80211968.0,0.024,0.509,1.0,5.042,4.145,3.202,60.531,0,0.003,56508416.0,0.005,1.372,1.0,6.44,5.667,2.702,4.744,0.0,0.0,31256576.0,0.0,0.082,1.0,3.324,2.449,3.0,4.6,0,0.0,12795904.0,0.0,0.206,1.0,4.087,2.679,0.34,3.49,0,0.001,89403392.0,0.0,0.082,1.0,3.485,2.472,3.0,4.6,0,0.002,86966272.0,0.0,0.299,1.0,4.393,3.598,3.119,4.815,0,0.004,171638784.0,0.0,0.2,1.0,4.288,2.957,3.454,16.898,0.0,0.003,13488128.0,0.0,0,0,4.276,3.015,0,0,0.0,3.8,34.126,0.067,3.489,30.633,0.0,3.617,30.007,0.0,3.14,33.847,0.0
7
+ 2026-05-19 10:37:02,0.002,29851648.0,0.0,0.535,1.0,11.601,12.17,22.052,95.035,0,0.0,12652544.0,0.0,0.069,1.0,7.768,7.397,20.426,46.965,0,0.001,15630336.0,0.0,2.268,1.0,6.143,4.237,0.275,0.495,0,0.016,83890176.0,0.037,0.57,1.0,4.913,4.001,3.184,51.953,0,0.003,56508416.0,0.005,1.514,1.0,6.44,5.667,2.695,4.728,0.0,0.001,31207424.0,0.0,0.093,1.0,3.682,2.774,3.0,4.6,0,0.0,12795904.0,0.0,0.21,1.0,4.68,3.253,0.346,3.555,0,0.001,89403392.0,0.0,0.093,1.0,2.861,2.028,3.0,4.6,0,0.002,86966272.0,0.0,0.315,1.0,3.258,2.84,3.112,4.802,0,0.004,171638784.0,0.0,0.219,1.0,3.918,2.833,3.426,16.456,0.0,0.004,13357056.0,0.0,0,0,3.76,2.643,0,0,0.0,3.8,34.126,0.067,3.489,30.633,0.0,3.56,30.112,0.0,3.017,33.847,0.0
8
+ 2026-05-19 10:37:07,0.001,29851648.0,0.0,0.527,1.0,11.415,12.099,21.222,98.557,0,0.0,12652544.0,0.0,0.077,1.0,7.768,7.397,20.245,46.788,0,0.001,15630336.0,0.0,2.492,1.0,6.143,4.237,0.276,0.496,0,0.016,83890176.0,0.037,0.564,1.0,4.913,4.001,3.216,8.33,0,0.002,56537088.0,0.0,1.659,1.0,6.532,5.706,2.663,4.717,0.0,0.001,31207424.0,0.0,0.104,1.0,3.54,2.785,3.0,4.6,0,0.0,12836864.0,0.0,0.235,1.0,4.68,3.253,0.332,3.381,0,0.001,89399296.0,0.0,0.104,1.0,2.905,2.059,3.0,4.6,0,0.002,86966272.0,0.0,0.346,1.0,4.003,3.489,3.111,4.8,0,0.004,171757568.0,0.0,0.222,1.0,3.918,2.833,3.423,16.403,0.0,0.004,13357056.0,0.0,0,0,3.76,2.643,0,0,0.0,3.569,34.141,0.533,3.489,30.633,0.0,3.433,30.112,0.0,3.017,33.847,0.0
9
+ 2026-05-19 10:37:12,0.002,29851648.0,0.0,0.574,1.0,11.415,12.099,21.105,92.336,0,0.0,12652544.0,0.0,0.1,1.0,7.274,6.474,20.619,132.815,0,0.001,15630336.0,0.0,2.678,1.0,10.121,7.437,0.275,0.494,0,0.016,83890176.0,0.037,0.597,1.0,5.973,5.216,3.229,18.341,0,0.002,56537088.0,0.0,2.529,1.0,6.54,5.977,2.643,4.69,0.0,0.001,31207424.0,0.0,0.132,1.0,3.357,2.732,3.291,7.135,0,0.0,12836864.0,0.0,0.298,1.0,4.68,3.253,0.358,3.932,0,0.001,89399296.0,0.0,0.132,1.0,3.16,2.375,3.136,4.845,0,0.002,86966272.0,0.0,0.378,1.0,3.367,2.934,3.098,4.776,0,0.004,171757568.0,0.0,0.7,1.0,3.837,2.878,3.341,14.696,0.0,0.004,13357056.0,0.0,0,0,3.76,2.643,0,0,0.0,3.569,34.141,0.533,3.703,30.671,0.0,3.433,30.112,0.0,2.968,33.922,0.0
10
+ 2026-05-19 10:37:17,0.004,31354880.0,0.0,0.578,1.0,10.19,10.758,20.71,67.058,0,0.001,12652544.0,0.0,0.244,1.0,7.274,6.474,21.975,760.028,0,0.002,16920576.0,0.0,8.66,1.0,10.567,7.913,0.271,0.487,0,0.024,85995520.0,0.076,0.622,1.0,5.973,5.216,3.286,72.244,0,0.002,56537088.0,0.0,2.745,1.0,6.54,5.977,2.566,4.577,0.0,0.001,31297536.0,0.0,0.252,1.0,3.357,2.732,3.161,4.89,0,0.0,12836864.0,0.0,0.926,1.0,5.486,3.644,0.44,4.229,0,0.001,89399296.0,0.0,0.252,1.0,3.16,2.375,3.071,4.728,0,0.004,87281664.0,0.0,1.255,1.0,3.033,2.644,3.36,6.935,0,0.007,173490176.0,0.009,0.769,1.0,4.494,3.241,3.229,10.418,0.0,0.004,13504512.0,0.0,0,0,6.358,4.387,0,0,0.0,3.569,34.141,0.533,3.703,30.671,0.0,3.536,30.073,0.0,3.029,33.922,0.0
11
+ 2026-05-19 10:37:22,0.005,31354880.0,0.0,3.165,1.0,8.437,8.907,27.156,572.889,0,0.001,13627392.0,0.0,0.244,1.0,8.126,8.237,22.482,849.642,0,0.002,16920576.0,0.0,9.449,1.0,10.567,7.913,0.299,2.588,0,0.024,85995520.0,0.076,3.124,1.0,6.803,5.873,3.359,545.379,0,0.002,56537088.0,0.0,2.778,1.0,5.557,5.079,3.112,7.036,0.0,0.001,31297536.0,0.0,0.267,1.0,3.357,2.732,3.06,4.708,0,0.0,12836864.0,0.0,0.991,1.0,5.486,3.644,1.794,4.426,0,0.001,89493504.0,0.0,0.267,1.0,3.532,2.54,3.036,4.666,0,0.004,87281664.0,0.0,1.372,1.0,8.13,8.15,3.467,7.522,0,0.007,173490176.0,0.009,0.822,1.0,4.494,3.241,3.398,8.264,0.0,0.004,13504512.0,0.0,0,0,5.896,4.043,0,0,0.0,3.89,34.149,0.133,3.703,30.671,0.0,3.785,30.073,0.0,3.029,33.922,0.0
12
+ 2026-05-19 10:37:27,0.005,31354880.0,0.0,3.484,1.0,58.28,63.239,27.078,570.973,0,0.001,13627392.0,0.0,0.244,1.0,8.126,8.237,22.0,850.0,0,0.002,16920576.0,0.0,9.533,1.0,9.077,6.798,0.301,2.643,0,0.024,85995520.0,0.076,3.396,1.0,14.618,13.864,3.341,552.872,0,0.016,61108224.0,0.025,12.575,1.0,5.176,4.559,2.578,6.573,0.0,0.001,31297536.0,0.0,0.267,1.0,2.37,1.975,3.0,4.6,0,0.0,12836864.0,0.0,1.0,1.0,6.244,3.92,1.831,4.423,0,0.001,89493504.0,0.0,0.267,1.0,3.532,2.54,3.0,4.6,0,0.004,87281664.0,0.0,1.4,1.0,8.13,8.15,3.48,7.489,0,0.008,173490176.0,0.014,1.884,1.0,3.826,2.787,3.38,7.88,0.0,0.004,13504512.0,0.0,0,0,6.581,4.513,0,0,0.0,3.89,34.149,0.133,4.306,30.702,0.0,3.785,30.073,0.0,3.043,33.974,0.0
13
+ 2026-05-19 10:37:32,0.013,31232000.0,0.0,3.802,1.0,74.639,81.275,26.252,554.834,0,0.001,13627392.0,0.0,0.499,1.0,8.931,9.903,20.113,766.412,0,0.004,17276928.0,0.0,20.777,1.0,8.975,6.825,0.286,1.812,0,0.024,86761472.0,0.073,3.648,1.0,14.618,13.864,3.321,481.819,0,0.016,61108224.0,0.025,13.744,1.0,33.262,32.763,2.581,6.467,0.0,0.001,31432704.0,0.0,0.505,1.0,4.25,3.4,3.077,4.739,0,0.001,13443072.0,0.0,2.167,1.0,7.523,4.723,0.409,4.048,0,0.001,89493504.0,0.0,0.505,1.0,3.532,2.54,3.035,4.663,0,0.007,87306240.0,0.0,2.901,1.0,9.933,9.986,3.299,6.188,0,0.015,175235072.0,0.017,2.079,1.0,7.183,4.717,3.376,7.797,0.0,0.004,13381632.0,0.0,0,0,8.223,5.639,0,0,0.0,3.89,34.149,0.133,4.306,30.702,0.0,3.971,30.138,0.0,2.924,33.974,0.0
14
+ 2026-05-19 10:37:37,0.013,31232000.0,0.0,5.888,1.0,74.639,81.275,18.753,158.62,0,0.001,13627392.0,0.0,0.533,1.0,13.67,16.37,19.191,655.185,0,0.005,17276928.0,0.0,22.77,1.0,9.727,7.397,0.279,1.1,0,0.024,86761472.0,0.073,5.84,1.0,19.716,19.313,2.847,9.258,0,0.016,61108224.0,0.025,14.511,1.0,33.262,32.763,2.589,4.86,0.0,0.001,31432704.0,0.0,0.533,1.0,4.763,3.846,3.004,4.606,0,0.001,13443072.0,0.0,2.332,1.0,7.523,4.723,0.444,4.113,0,0.001,89493504.0,0.0,0.533,1.0,3.535,2.571,3.003,4.606,0,0.007,87306240.0,0.0,3.184,1.0,9.933,9.986,3.197,4.955,0,0.018,175235072.0,0.021,2.273,1.0,7.183,4.717,3.264,6.109,0.0,0.003,13381632.0,0.0,0,0,13.192,8.359,0,0,0.0,3.821,34.163,0.067,4.306,30.702,0.0,4.106,30.138,0.0,2.924,33.974,0.0
15
+ 2026-05-19 10:37:42,0.016,31232000.0,0.0,6.483,1.0,97.8,107.385,18.733,158.548,0,0.001,13627392.0,0.0,0.533,1.0,13.67,16.37,19.051,681.25,0,0.005,17276928.0,0.0,24.067,1.0,38.038,28.215,0.279,1.147,0,0.024,86761472.0,0.073,6.422,1.0,23.998,23.421,2.838,9.168,0,0.018,61108224.0,0.029,22.025,1.0,44.016,43.574,2.109,4.729,0.0,0.001,31432704.0,0.0,0.533,1.0,4.587,3.886,3.0,4.6,0,0.001,13443072.0,0.0,2.4,1.0,6.443,4.045,0.449,4.125,0,0.002,89530368.0,0.0,0.533,1.0,4.372,3.012,3.0,4.6,0,0.009,87306240.0,0.0,3.4,1.0,13.56,13.595,3.198,4.957,0,0.018,175235072.0,0.021,3.168,1.0,7.183,4.717,3.197,4.955,0.0,0.004,13381632.0,0.0,0,0,13.192,8.359,0,0,0.0,3.821,34.163,0.067,4.971,30.736,0.0,4.106,30.138,0.0,2.91,33.974,0.0
16
+ 2026-05-19 10:37:47,0.017,31232000.0,0.0,7.077,1.0,128.309,137.469,18.697,159.753,0,0.001,13627392.0,0.0,0.875,1.0,13.67,16.37,18.631,539.266,0,0.007,17276928.0,0.0,33.792,1.0,46.733,34.734,0.277,0.499,0,0.024,87707648.0,0.058,6.903,1.0,23.998,23.421,2.838,7.824,0,0.025,63844352.0,0.026,24.108,1.0,44.016,43.574,2.114,4.728,0.0,0.002,32321536.0,0.0,0.867,1.0,4.587,3.886,3.019,4.67,0,0.001,13844480.0,0.0,3.445,1.0,10.392,6.042,0.398,3.968,0,0.002,89530368.0,0.0,0.866,1.0,4.372,3.012,2.998,4.632,0,0.011,87330816.0,0.0,4.65,1.0,16.806,16.925,3.163,4.893,0,0.018,175235072.0,0.021,3.498,1.0,10.35,6.355,3.196,4.952,0.0,0.004,13381632.0,0.0,0,0,16.254,10.239,0,0,0.0,3.821,34.163,0.067,4.971,30.736,0.0,4.296,30.167,0.0,3.024,33.974,0.0
17
+ 2026-05-19 10:37:52,0.022,31395840.0,0.0,8.988,1.0,140.603,150.969,17.47,77.294,0,0.002,13963264.0,0.0,0.955,1.0,14.787,18.082,18.476,45.765,0,0.006,17276928.0,0.0,37.089,1.0,52.085,38.677,0.273,0.492,0,0.024,87707648.0,0.058,8.952,1.0,23.998,23.421,2.67,4.859,0,0.025,63844352.0,0.026,25.489,1.0,44.016,43.574,1.981,4.656,0.0,0.002,32321536.0,0.0,0.933,1.0,5.197,4.341,2.992,4.622,0,0.002,13844480.0,0.0,3.738,1.0,10.392,6.042,0.407,3.995,0,0.002,89530368.0,0.0,0.933,1.0,4.507,2.929,2.992,4.621,0,0.011,87330816.0,0.0,5.11,1.0,18.221,18.278,3.129,4.832,0,0.023,176713728.0,0.018,3.828,1.0,10.35,6.355,3.151,4.872,0.0,0.003,13381632.0,0.0,0,0,18.827,11.908,0,0,0.0,3.871,34.136,0.2,4.971,30.736,0.0,4.482,30.167,0.0,3.024,33.974,0.0
18
+ 2026-05-19 10:37:57,0.026,31395840.0,0.0,9.908,1.0,159.397,176.752,17.454,77.034,0,0.002,13963264.0,0.0,0.956,1.0,14.58,18.497,18.363,34.325,0,0.009,17375232.0,0.0,39.711,1.0,62.976,46.533,0.273,0.492,0,0.021,88416256.0,0.045,9.86,1.0,32.655,31.878,2.658,4.852,0,0.032,63844352.0,0.034,33.424,1.0,63.022,62.865,1.586,4.556,0.0,0.002,32321536.0,0.0,0.933,1.0,5.425,4.67,2.975,4.595,0,0.002,13844480.0,0.0,3.867,1.0,10.979,6.39,0.412,4.0,0,0.002,89538560.0,0.0,0.933,1.0,5.373,3.493,2.976,4.595,0,0.011,87330816.0,0.0,5.511,1.0,16.278,16.227,3.129,4.832,0,0.023,176713728.0,0.018,4.369,1.0,10.35,6.355,3.123,4.821,0.0,0.003,13381632.0,0.0,0,0,19.099,11.803,0,0,0.0,3.871,34.136,0.2,5.425,30.824,0.0,4.482,30.167,0.0,3.04,33.885,0.0
19
+ 2026-05-19 10:38:02,0.028,31395840.0,0.0,10.829,1.0,159.397,176.752,17.442,76.816,0,0.003,13963264.0,0.0,1.243,1.0,16.253,20.618,18.199,24.758,0,0.011,17375232.0,0.0,44.711,1.0,62.976,46.533,0.273,0.491,0,0.011,88416256.0,0.0,10.679,1.0,32.655,31.878,2.657,4.839,0,0.032,63844352.0,0.034,36.603,1.0,44.216,44.106,1.587,4.556,0.0,0.002,31784960.0,0.0,1.2,1.0,5.425,4.67,3.013,4.649,0,0.002,13844480.0,0.0,4.697,1.0,10.74,6.093,0.392,3.924,0,0.002,89538560.0,0.0,1.2,1.0,5.373,3.493,2.999,4.623,0,0.013,87330816.0,0.0,6.147,1.0,18.116,18.059,3.109,4.797,0,0.023,176713728.0,0.018,4.776,1.0,10.09,6.031,3.121,4.819,0.0,0.005,13512704.0,0.0,0,0,23.528,14.539,0,0,0.0,3.871,34.136,0.2,5.425,30.824,0.0,4.469,30.066,0.0,2.972,33.885,0.0
20
+ 2026-05-19 10:38:07,0.028,31502336.0,0.0,10.933,1.0,172.203,192.701,17.076,47.109,0,0.003,13946880.0,0.0,1.244,1.0,19.282,24.716,17.853,24.135,0,0.011,17399808.0,0.0,45.797,1.0,62.573,46.143,0.27,0.485,0,0.013,88416256.0,0.001,10.756,1.0,32.655,31.878,2.551,4.643,0,0.032,66260992.0,0.012,38.156,1.0,78.389,77.514,1.306,4.476,0.0,0.002,31784960.0,0.0,1.2,1.0,3.593,3.422,2.983,4.597,0,0.001,14499840.0,0.0,4.711,1.0,10.59,6.008,0.377,3.813,0,0.002,89538560.0,0.0,1.2,1.0,5.154,3.442,2.983,4.597,0,0.013,87330816.0,0.0,6.267,1.0,20.857,20.787,3.036,4.665,0,0.023,177430528.0,0.008,4.889,1.0,9.038,5.402,3.104,4.788,0.0,0.005,13512704.0,0.0,0,0,22.331,13.685,0,0,0.0,3.742,34.059,0.0,5.425,30.824,0.0,4.361,30.066,0.0,2.972,33.885,0.0
21
+ 2026-05-19 10:38:12,0.028,31502336.0,0.0,10.933,1.0,172.203,192.701,16.194,28.579,0,0.003,13946880.0,0.0,1.244,1.0,19.282,24.716,17.5,23.5,0,0.011,17399808.0,0.0,45.8,1.0,43.627,32.165,0.265,0.477,0,0.012,89157632.0,0.0,10.756,1.0,27.853,27.019,2.429,4.49,0,0.032,66260992.0,0.012,38.2,1.0,78.389,77.514,0.486,4.202,0.0,0.002,31784960.0,0.0,1.2,1.0,3.861,3.594,2.981,4.596,0,0.001,14499840.0,0.0,4.711,1.0,12.036,6.875,0.374,3.794,0,0.002,89554944.0,0.0,1.2,1.0,5.228,3.536,2.981,4.596,0,0.013,87330816.0,0.0,6.267,1.0,20.857,20.787,3.011,4.62,0,0.023,177430528.0,0.008,4.956,1.0,12.659,7.599,3.009,4.616,0.0,0.005,13512704.0,0.0,0,0,22.331,13.685,0,0,0.0,3.742,34.059,0.0,5.5,30.796,0.0,4.361,30.066,0.0,2.904,33.953,0.0
22
+ 2026-05-19 10:38:17,0.029,31502336.0,0.0,10.933,1.0,169.002,189.49,15.913,24.609,0,0.003,13946880.0,0.0,1.178,1.0,18.05,23.107,17.5,23.5,0,0.011,17399808.0,0.0,46.0,1.0,48.602,36.138,0.265,0.478,0,0.011,89157632.0,0.0,10.756,1.0,32.327,31.212,2.406,4.481,0,0.032,66260992.0,0.012,38.2,1.0,78.389,77.514,0.46,4.151,0.0,0.002,32477184.0,0.0,1.156,1.0,4.878,4.541,2.985,4.597,0,0.002,14499840.0,0.0,4.556,1.0,12.111,7.016,0.375,3.8,0,0.002,89554944.0,0.0,1.178,1.0,5.228,3.536,2.984,4.597,0,0.013,87359488.0,0.0,6.156,1.0,20.857,20.787,3.007,4.613,0,0.02,177430528.0,0.0,4.956,1.0,12.809,7.663,3.009,4.616,0.0,0.005,13389824.0,0.0,0,0,22.315,13.829,0,0,0.0,3.742,34.059,0.0,5.5,30.796,0.0,4.294,30.127,0.2,2.971,33.953,0.0
23
+ 2026-05-19 10:38:22,0.029,31502336.0,0.0,10.6,1.0,169.002,189.49,15.934,24.457,0,0.001,13946880.0,0.0,1.178,1.0,16.259,20.911,17.5,23.5,0,0.011,17485824.0,0.0,46.0,1.0,53.999,40.15,0.266,0.479,0,0.01,89890816.0,0.0,10.444,1.0,32.327,31.212,2.423,4.485,0,0.032,66260992.0,0.012,38.2,1.0,78.389,77.514,0.429,4.075,0.0,0.002,32477184.0,0.0,1.156,1.0,4.878,4.541,2.983,4.597,0,0.001,14499840.0,0.0,4.556,1.0,12.111,7.016,0.381,3.839,0,0.002,89554944.0,0.0,1.178,1.0,4.828,3.366,2.983,4.597,0,0.013,87359488.0,0.0,6.156,1.0,17.74,17.952,3.011,4.619,0,0.02,177430528.0,0.0,4.956,1.0,12.398,7.422,3.0,4.6,0.0,0.005,13389824.0,0.0,0,0,22.315,13.829,0,0,0.0,3.892,34.059,0.467,5.5,30.796,0.0,4.289,30.127,0.2,2.971,33.953,0.0
24
+ 2026-05-19 10:38:27,0.028,31698944.0,0.0,10.6,1.0,172.915,194.642,15.934,24.457,0,0.002,14061568.0,0.0,1.178,1.0,16.259,20.911,17.5,23.5,0,0.011,17485824.0,0.0,46.0,1.0,64.754,48.147,0.266,0.479,0,0.01,89890816.0,0.0,10.444,1.0,31.785,30.603,2.423,4.485,0,0.025,66371584.0,0.007,36.667,1.0,78.389,77.514,0.415,4.02,0.0,0.002,32477184.0,0.0,1.156,1.0,3.975,3.701,2.981,4.596,0,0.001,14499840.0,0.0,4.556,1.0,10.439,6.067,0.381,3.839,0,0.002,89530368.0,0.0,1.178,1.0,4.735,3.312,2.981,4.596,0,0.013,87359488.0,0.0,6.156,1.0,21.135,21.387,3.011,4.619,0,0.02,179400704.0,0.011,4.8,1.0,12.398,7.422,3.0,4.6,0.0,0.004,13385728.0,0.0,0,0,17.828,11.049,0,0,0.0,3.892,34.059,0.467,5.453,30.857,0.0,4.289,30.127,0.2,3.026,34.014,0.0
25
+ 2026-05-19 10:38:32,0.022,31698944.0,0.0,10.6,1.0,172.915,194.642,15.934,24.457,0,0.002,23732224.0,0.0,1.111,1.0,13.574,17.459,17.5,23.5,0,0.008,17485824.0,0.0,43.711,1.0,54.118,40.239,0.266,0.479,0,0.009,89890816.0,0.0,10.444,1.0,31.165,30.051,2.42,4.484,0,0.025,66371584.0,0.007,36.667,1.0,48.032,46.015,0.405,3.984,0.0,0.002,32407552.0,0.0,1.133,1.0,6.245,5.358,3.0,4.6,0,0.001,14671872.0,0.0,4.4,1.0,12.348,7.249,0.385,3.858,0,0.002,89530368.0,0.0,1.133,1.0,4.735,3.312,3.0,4.6,0,0.012,87343104.0,0.0,5.911,1.0,21.138,21.176,3.007,4.613,0,0.016,179400704.0,0.014,4.8,1.0,12.357,7.452,3.0,4.6,0.0,0.003,13385728.0,0.0,0,0,21.749,13.769,0,0,0.0,3.892,34.059,0.467,5.453,30.857,0.0,4.231,30.144,0.067,2.975,34.014,0.0
26
+ 2026-05-19 10:38:37,0.027,31698944.0,0.0,9.933,1.0,163.3,185.057,16.065,24.398,0,0.003,23732224.0,0.0,1.111,1.0,18.162,23.313,17.5,23.5,0,0.009,17887232.0,0.0,43.711,1.0,63.975,47.516,0.267,0.48,0,0.007,89890816.0,0.0,9.889,1.0,31.165,30.051,2.466,4.498,0,0.025,66371584.0,0.007,36.667,1.0,66.771,63.967,0.38,3.845,0.0,0.002,32407552.0,0.0,1.133,1.0,6.245,5.358,3.0,4.6,0,0.001,14671872.0,0.0,4.4,1.0,12.348,7.249,0.382,3.84,0,0.002,89542656.0,0.0,1.133,1.0,4.735,3.312,3.0,4.6,0,0.012,87343104.0,0.0,5.911,1.0,21.138,21.176,3.004,4.607,0,0.02,179400704.0,0.017,4.8,1.0,12.357,7.452,3.019,4.634,0.0,0.003,13385728.0,0.0,0,0,20.677,13.061,0,0,0.0,4.0,34.136,0.067,5.453,30.857,0.0,4.194,30.144,0.067,2.975,34.014,0.0
27
+ 2026-05-19 10:38:42,0.027,31805440.0,0.0,9.933,1.0,154.53,175.685,16.065,24.398,0,0.002,23732224.0,0.0,1.111,1.0,18.162,23.313,17.5,23.5,0,0.011,17887232.0,0.0,43.711,1.0,62.586,46.518,0.267,0.48,0,0.008,90718208.0,0.0,9.889,1.0,30.283,29.133,2.466,4.498,0,0.024,68714496.0,0.005,33.844,1.0,66.549,63.659,0.382,3.844,0.0,0.002,32407552.0,0.0,1.133,1.0,6.343,5.305,3.0,4.6,0,0.001,14671872.0,0.0,4.4,1.0,12.348,7.249,0.382,3.84,0,0.002,89542656.0,0.0,1.133,1.0,4.617,3.275,3.0,4.6,0,0.012,87343104.0,0.0,5.911,1.0,20.474,20.568,3.004,4.607,0,0.017,178237440.0,0.012,4.8,1.0,12.357,7.452,3.034,4.661,0.0,0.004,13389824.0,0.0,0,0,20.677,13.061,0,0,0.0,4.0,34.136,0.067,6.144,31.171,0.0,4.194,30.144,0.067,3.075,33.335,0.4
28
+ 2026-05-19 10:38:47,0.027,31805440.0,0.0,9.933,1.0,154.53,175.685,16.065,24.398,0,0.024,33456128.0,0.154,0.787,1.0,28.083,33.151,17.5,23.5,0,0.011,17887232.0,0.0,45.911,1.0,62.586,46.518,0.266,0.479,0,0.008,90718208.0,0.0,9.889,1.0,24.819,23.877,2.448,4.494,0,0.02,68714496.0,0.0,33.844,1.0,66.549,63.659,0.38,3.831,0.0,0.002,32600064.0,0.0,1.044,1.0,6.87,5.77,3.0,4.6,0,0.001,14671872.0,0.0,4.2,1.0,12.924,7.886,0.383,3.848,0,0.002,89542656.0,0.0,1.044,1.0,5.452,3.779,3.0,4.6,0,0.01,87343104.0,0.0,6.156,1.0,17.536,17.617,3.004,4.607,0,0.017,178237440.0,0.012,4.8,1.0,9.653,5.96,3.034,4.661,0.0,0.004,13389824.0,0.0,0,0,20.698,13.223,0,0,0.0,4.0,34.136,0.067,6.144,31.171,0.0,4.243,30.136,0.067,3.244,33.335,0.4
29
+ 2026-05-19 10:38:52,0.026,31805440.0,0.0,9.689,1.0,154.53,175.685,16.066,24.455,0,0.03,33456128.0,0.2,0.706,1.0,27.406,31.328,18.108,24.594,0,0.011,17518592.0,0.0,45.911,1.0,62.435,46.546,0.266,0.479,0,0.008,90718208.0,0.0,9.689,1.0,22.295,21.449,2.435,4.492,0,0.019,69251072.0,0.0,33.844,1.0,66.549,63.659,0.376,3.808,0.0,0.002,32600064.0,0.0,1.044,1.0,6.87,5.77,3.0,4.6,0,0.001,14671872.0,0.0,4.2,1.0,12.924,7.886,0.384,3.855,0,0.002,89550848.0,0.0,1.044,1.0,5.848,4.001,3.0,4.6,0,0.012,87379968.0,0.0,6.156,1.0,21.23,21.335,3.004,4.607,0,0.017,178237440.0,0.017,4.8,1.0,10.702,6.608,3.049,4.689,0.0,0.004,13651968.0,0.0,0,0,20.91,13.73,0,0,0.0,4.003,34.063,0.067,6.144,31.171,0.0,4.257,30.136,0.067,3.244,33.335,0.4
30
+ 2026-05-19 10:38:57,0.026,31805440.0,0.0,9.689,1.0,146.683,167.965,16.066,24.455,0,0.037,33456128.0,0.247,0.626,1.0,28.403,31.887,18.142,24.656,0,0.011,17518592.0,0.0,45.911,1.0,62.435,46.546,0.266,0.479,0,0.008,91897856.0,0.0,9.689,1.0,19.231,18.605,2.428,4.49,0,0.019,69251072.0,0.0,32.067,1.0,66.549,63.659,0.377,3.813,0.0,0.002,32600064.0,0.0,1.044,1.0,7.837,6.497,3.0,4.6,0,0.001,14671872.0,0.0,4.2,1.0,13.663,8.525,0.382,3.842,0,0.002,89550848.0,0.0,1.044,1.0,6.047,4.246,3.0,4.6,0,0.012,87379968.0,0.0,6.156,1.0,21.23,21.335,3.004,4.607,0,0.017,178237440.0,0.017,4.467,1.0,12.592,7.775,3.05,4.69,0.0,0.004,13651968.0,0.0,0,0,20.301,13.135,0,0,0.0,4.003,34.063,0.067,6.906,31.012,0.0,4.257,30.136,0.067,3.304,33.425,0.067
31
+ 2026-05-19 10:39:02,0.021,31805440.0,0.0,9.689,1.0,146.683,167.965,16.066,24.455,0,0.074,48119808.0,0.631,0.677,1.0,25.946,29.448,18.133,24.639,0,0.011,17518592.0,0.0,43.778,1.0,62.212,46.328,0.267,0.48,0,0.008,91897856.0,0.0,9.689,1.0,30.449,29.536,2.43,4.491,0,0.019,69251072.0,0.0,32.067,1.0,65.354,62.508,0.378,3.819,0.0,0.002,32538624.0,0.0,1.111,1.0,6.74,5.732,3.0,4.6,0,0.002,15003648.0,0.0,4.244,1.0,12.848,7.897,0.388,3.878,0,0.002,89550848.0,0.0,1.067,1.0,6.047,4.246,2.975,4.595,0,0.012,87379968.0,0.0,5.844,1.0,21.23,21.335,3.004,4.607,0,0.017,180056064.0,0.015,4.467,1.0,10.48,6.471,3.05,4.69,0.0,0.004,13651968.0,0.0,0,0,20.301,13.135,0,0,0.0,4.003,34.063,0.067,6.906,31.012,0.0,4.254,30.176,0.0,3.232,33.425,0.067
32
+ 2026-05-19 10:39:07,0.019,31805440.0,0.0,9.733,1.0,146.683,167.965,16.279,24.93,0,0.085,48119808.0,0.731,1.013,1.0,28.754,32.493,23.408,7535.563,0,0.01,17530880.0,0.0,43.778,1.0,61.65,45.691,0.266,0.479,0,0.008,91897856.0,0.0,9.822,1.0,30.449,29.536,2.493,4.507,0,0.018,69251072.0,0.0,32.067,1.0,48.273,46.098,0.373,3.789,0.0,0.002,32538624.0,0.0,1.111,1.0,6.74,5.732,3.0,4.6,0,0.002,15003648.0,0.0,4.244,1.0,12.848,7.897,0.412,3.981,0,0.001,89550848.0,0.0,1.067,1.0,5.09,3.565,2.995,4.624,0,0.012,87392256.0,0.0,5.844,1.0,20.957,20.713,3.004,4.607,0,0.014,180056064.0,0.007,4.467,1.0,11.99,7.355,3.051,4.692,0.0,0.004,13651968.0,0.0,0,0,13.68,8.768,0,0,0.0,4.049,34.087,0.133,6.906,31.012,0.0,4.19,30.176,0.0,3.232,33.425,0.067
33
+ 2026-05-19 10:39:12,0.026,32493568.0,0.0,9.733,1.0,146.683,167.965,16.279,24.93,0,0.096,48119808.0,0.831,1.019,1.0,28.973,32.269,24.666,7808.268,0,0.01,17530880.0,0.0,43.778,1.0,61.65,45.691,0.266,0.479,0,0.008,92942336.0,0.0,9.822,1.0,30.449,29.536,2.493,4.507,0,0.018,69107712.0,0.0,32.2,1.0,53.878,51.66,0.372,3.781,0.0,0.002,33099776.0,0.0,1.111,1.0,4.479,3.968,3.0,4.6,0,0.002,15003648.0,0.0,4.244,1.0,12.981,8.093,0.415,3.995,0,0.002,89563136.0,0.0,1.067,1.0,5.637,3.948,2.995,4.624,0,0.012,87392256.0,0.0,5.844,1.0,20.514,20.475,3.004,4.607,0,0.014,180056064.0,0.007,4.289,1.0,12.23,7.54,3.052,4.693,0.0,0.004,13385728.0,0.0,0,0,11.975,7.675,0,0,0.0,4.049,34.087,0.133,7.638,31.031,0.067,4.19,30.176,0.0,3.133,33.434,0.067
34
+ 2026-05-19 10:39:17,0.026,32493568.0,0.0,9.733,1.0,111.074,126.643,16.279,24.93,0,0.12,51650560.0,1.078,0.648,1.0,18.445,20.126,2444.305,8383.217,0,0.01,17543168.0,0.0,45.067,1.0,42.325,31.375,0.266,0.479,0,0.008,92942336.0,0.0,9.822,1.0,30.73,29.845,2.465,4.502,0,0.018,69107712.0,0.0,32.2,1.0,64.388,61.737,0.368,3.753,0.0,0.002,33099776.0,0.0,1.044,1.0,4.954,4.389,2.973,4.595,0,0.002,15003648.0,0.0,4.4,1.0,12.324,7.463,0.406,3.959,0,0.002,89563136.0,0.0,1.044,1.0,6.556,4.592,2.966,4.626,0,0.012,87392256.0,0.0,5.889,1.0,20.514,20.475,3.004,4.607,0,0.014,178900992.0,0.005,4.289,1.0,12.089,7.372,3.052,4.693,0.0,0.004,13385728.0,0.0,0,0,20.591,12.987,0,0,0.0,4.049,34.087,0.133,7.638,31.031,0.067,4.147,30.208,0.0,3.186,33.434,0.067
35
+ 2026-05-19 10:39:22,0.026,22020096.0,0.0,9.556,1.0,149.568,170.308,16.263,35.357,0,0.132,51650560.0,1.194,0.719,1.0,20.306,22.157,4489.705,8842.17,0,0.009,17543168.0,0.0,45.067,1.0,59.5,44.512,0.266,0.479,0,0.007,92942336.0,0.0,9.511,1.0,30.73,29.845,2.529,4.509,0,0.018,69107712.0,0.0,32.2,1.0,64.388,61.737,0.372,3.796,0.0,0.002,33099776.0,0.0,1.044,1.0,5.693,5.079,2.994,4.628,0,0.002,15003648.0,0.0,4.4,1.0,12.324,7.463,0.435,4.059,0,0.002,89550848.0,0.0,1.044,1.0,5.315,3.723,2.967,4.625,0,0.012,87412736.0,0.0,5.889,1.0,20.168,20.431,3.011,4.621,0,0.014,178900992.0,0.005,4.289,1.0,11.867,7.252,3.031,4.656,0.0,0.004,13385728.0,0.0,0,0,20.591,12.987,0,0,0.0,4.003,34.044,0.133,7.638,31.031,0.067,4.167,30.208,0.0,3.186,33.434,0.067
36
+ 2026-05-19 10:39:27,0.025,22020096.0,0.0,9.556,1.0,149.568,170.308,16.263,35.357,0,0.145,51650560.0,1.31,0.819,1.0,20.689,23.262,4543.334,8860.344,0,0.01,17543168.0,0.0,45.067,1.0,59.5,44.512,0.266,0.479,0,0.008,93425664.0,0.0,9.511,1.0,30.73,29.845,2.536,4.511,0,0.018,32894976.0,0.003,31.222,1.0,63.406,60.696,0.383,3.875,0.0,0.002,32776192.0,0.0,1.044,1.0,5.693,5.079,2.994,4.627,0,0.002,15003648.0,0.0,4.4,1.0,12.324,7.463,0.443,4.082,0,0.002,89550848.0,0.0,1.044,1.0,3.225,2.35,2.969,4.623,0,0.012,87412736.0,0.0,5.889,1.0,20.168,20.431,3.011,4.621,0,0.014,178900992.0,0.006,4.022,1.0,11.292,6.768,3.016,4.629,0.0,0.004,6832128.0,0.0,0,0,19.78,12.416,0,0,0.0,4.003,34.044,0.133,7.706,31.055,0.0,4.167,30.208,0.0,3.182,33.53,0.067
37
+ 2026-05-19 10:39:32,0.025,22020096.0,0.0,9.556,1.0,149.568,170.308,16.263,35.357,0,0.137,51650560.0,1.24,0.919,1.0,17.316,20.957,4590.899,8876.124,0,0.01,17555456.0,0.0,42.044,1.0,59.952,44.853,0.267,0.48,0,0.008,44851200.0,0.0,9.511,1.0,28.408,27.834,2.542,4.512,0,0.018,32894976.0,0.003,31.222,1.0,62.817,60.197,0.384,3.88,0.0,0.002,16498688.0,0.0,1.111,1.0,4.768,4.383,2.994,4.626,0,0.001,15003648.0,0.0,4.444,1.0,10.879,6.383,0.455,4.112,0,0.002,89550848.0,0.0,1.111,1.0,5.375,3.863,2.925,4.613,0,0.01,87461888.0,0.0,5.6,1.0,16.07,16.422,3.027,4.649,0,0.014,178900992.0,0.006,4.022,1.0,10.47,6.085,3.016,4.629,0.0,0.004,6832128.0,0.0,0,0,19.504,12.026,0,0,0.0,4.003,34.044,0.133,7.706,31.055,0.0,4.101,30.21,0.0,3.042,33.53,0.067
38
+ 2026-05-19 10:39:37,0.025,22036480.0,0.0,9.733,1.0,150.754,171.516,16.296,2566.667,0,0.181,36704256.0,1.654,1.002,1.0,17.316,20.957,5313.669,9062.734,0,0.01,17555456.0,0.0,42.044,1.0,59.441,44.644,0.267,0.48,0,0.008,44851200.0,0.0,9.689,1.0,28.408,27.834,2.528,4.509,0,0.018,32894976.0,0.003,31.222,1.0,62.817,60.197,0.377,3.848,0.0,0.002,16498688.0,0.0,1.111,1.0,3.904,3.588,2.994,4.626,0,0.001,15007744.0,0.0,4.444,1.0,10.879,6.383,0.455,4.112,0,0.002,44875776.0,0.0,1.111,1.0,5.375,3.863,2.928,4.612,0,0.012,43589632.0,0.0,5.6,1.0,19.601,20.097,3.044,4.679,0,0.015,84885504.0,0.01,4.022,1.0,10.47,6.085,3.005,4.61,0.0,0.004,6832128.0,0.0,0,0,19.504,12.026,0,0,0.0,3.783,34.06,0.0,7.706,31.055,0.0,4.008,30.21,0.0,3.042,33.53,0.067
39
+ 2026-05-19 10:39:42,0.017,22036480.0,0.0,9.733,1.0,146.702,167.27,16.296,2566.667,0,0.184,36704256.0,1.721,1.1,1.0,14.78,17.888,5311.633,9062.327,0,0.01,8544256.0,0.0,42.044,1.0,59.441,44.644,0.267,0.48,0,0.008,47063040.0,0.0,9.689,1.0,28.408,27.834,2.534,4.51,0,0.018,32526336.0,0.003,30.778,1.0,54.197,51.945,0.378,3.853,0.0,0.001,16498688.0,0.0,1.111,1.0,3.507,3.223,2.995,4.625,0,0.001,15007744.0,0.0,4.444,1.0,10.879,6.383,0.463,4.13,0,0.002,44916736.0,0.0,1.111,1.0,5.375,3.863,2.931,4.612,0,0.012,43589632.0,0.0,5.6,1.0,19.601,20.097,3.044,4.679,0,0.015,84885504.0,0.009,4.267,1.0,8.887,5.165,3.011,4.62,0.0,0.004,6696960.0,0.0,0,0,16.221,10.002,0,0,0.0,3.783,34.06,0.0,7.492,31.037,0.0,4.008,30.21,0.0,2.956,33.503,0.0
40
+ 2026-05-19 10:39:47,0.019,10936320.0,0.0,9.733,1.0,146.702,167.27,16.296,2566.667,0,0.18,36704256.0,1.692,1.178,1.0,16.796,21.714,5446.429,9089.286,0,0.01,8556544.0,0.0,42.867,1.0,57.242,42.946,0.266,0.479,0,0.008,47063040.0,0.0,9.689,1.0,28.53,27.873,2.534,4.507,0,0.018,32526336.0,0.003,30.778,1.0,63.303,60.672,0.378,3.853,0.0,0.001,16498688.0,0.0,0.978,1.0,3.407,3.07,2.978,4.596,0,0.001,7340032.0,0.0,4.0,1.0,10.523,6.082,0.458,4.118,0,0.002,44916736.0,0.0,0.956,1.0,5.074,3.584,2.935,4.587,0,0.01,43589632.0,0.0,5.644,1.0,19.601,20.097,3.045,4.681,0,0.015,84885504.0,0.009,4.267,1.0,11.471,6.599,3.011,4.62,0.0,0.004,6696960.0,0.0,0,0,19.723,12.194,0,0,0.0,3.783,34.06,0.0,7.492,31.037,0.0,3.994,30.244,0.0,3.032,33.503,0.0
41
+ 2026-05-19 10:39:52,0.021,10928128.0,0.0,9.867,1.0,146.702,167.27,16.205,2694.444,0,0.18,36704256.0,1.692,1.133,1.0,16.796,21.714,5336.538,9221.154,0,0.01,8556544.0,0.0,42.867,1.0,56.164,42.285,0.268,0.482,0,0.008,47063040.0,0.0,9.578,1.0,28.53,27.873,2.48,4.501,0,0.018,32526336.0,0.005,30.778,1.0,63.303,60.672,0.378,3.856,0.0,0.002,16846848.0,0.0,0.978,1.0,5.432,4.812,2.978,4.596,0,0.001,7340032.0,0.0,4.0,1.0,10.523,6.082,0.455,4.111,0,0.002,44929024.0,0.0,0.956,1.0,5.074,3.584,2.934,4.587,0,0.009,43589632.0,0.0,5.644,1.0,16.115,16.486,3.058,4.704,0,0.015,84885504.0,0.009,4.267,1.0,11.471,6.599,3.011,4.619,0.0,0.004,6696960.0,0.0,0,0,19.723,12.194,0,0,0.0,3.646,34.073,0.0,7.492,31.037,0.0,4.049,30.244,0.0,3.032,33.503,0.0
42
+ 2026-05-19 10:39:57,0.024,10928128.0,0.0,9.867,1.0,102.63,117.482,16.205,2694.444,0,0.172,27254784.0,1.553,1.133,1.0,16.796,21.714,5336.538,9221.154,0,0.01,8953856.0,0.0,42.867,1.0,56.164,42.285,0.268,0.482,0,0.007,46858240.0,0.0,9.578,1.0,28.53,27.873,2.48,4.501,0,0.014,32526336.0,0.004,33.489,1.0,64.517,61.7,0.371,3.808,0.0,0.002,16846848.0,0.0,0.978,1.0,5.432,4.812,2.978,4.596,0,0.001,7340032.0,0.0,4.0,1.0,10.523,6.082,0.455,4.111,0,0.002,44929024.0,0.0,0.956,1.0,5.05,3.58,2.934,4.587,0,0.012,43753472.0,0.0,5.644,1.0,19.082,19.521,3.058,4.704,0,0.015,85225472.0,0.013,4.556,1.0,11.798,6.771,3.006,4.618,0.0,0.004,6696960.0,0.0,0,0,16.373,10.103,0,0,0.0,3.646,34.073,0.0,7.424,30.87,0.133,4.049,30.244,0.0,3.125,33.586,0.0
43
+ 2026-05-19 10:40:02,0.024,10928128.0,0.0,9.867,1.0,79.233,90.7,16.205,2694.444,0,0.169,27254784.0,1.488,1.133,1.0,15.324,19.787,5336.538,9221.154,0,0.01,8953856.0,0.0,43.489,1.0,32.125,24.025,0.267,0.481,0,0.007,46858240.0,0.0,9.578,1.0,19.348,18.77,2.48,4.501,0,0.018,34574336.0,0.003,33.489,1.0,64.311,61.266,0.371,3.808,0.0,0.002,16846848.0,0.0,1.0,1.0,5.244,4.599,2.979,4.596,0,0.001,7340032.0,0.0,4.044,1.0,10.314,6.219,0.471,4.148,0,0.002,44929024.0,0.0,1.0,1.0,5.05,3.58,2.89,4.578,0,0.012,43753472.0,0.0,5.733,1.0,19.082,19.521,3.069,4.723,0,0.017,85225472.0,0.019,4.556,1.0,11.798,6.771,3.006,4.618,0.0,0.004,6696960.0,0.0,0,0,19.622,12.107,0,0,0.0,3.646,34.073,0.0,7.424,30.87,0.133,4.032,30.202,0.0,3.029,33.586,0.0
44
+ 2026-05-19 10:40:07,0.025,11083776.0,0.0,9.511,1.0,147.59,168.603,16.031,520.0,0,0.169,27254784.0,1.488,0.933,1.0,15.324,19.787,4772.727,9157.895,0,0.01,8953856.0,0.0,43.489,1.0,59.287,44.727,0.268,0.482,0,0.007,46858240.0,0.0,9.267,1.0,21.895,21.241,2.402,4.485,0,0.018,34574336.0,0.003,33.489,1.0,62.124,59.332,0.361,3.713,0.0,0.002,17379328.0,0.0,1.0,1.0,5.244,4.599,2.977,4.595,0,0.001,7409664.0,0.0,4.044,1.0,10.314,6.219,0.434,4.057,0,0.002,44933120.0,0.0,1.0,1.0,2.939,2.141,2.875,4.575,0,0.011,43626496.0,0.0,5.733,1.0,19.033,19.632,3.068,4.723,0,0.017,85225472.0,0.019,4.556,1.0,11.869,6.792,3.021,4.645,0.0,0.004,6696960.0,0.0,0,0,19.622,12.107,0,0,0.0,3.629,34.049,0.0,7.424,30.87,0.133,3.914,30.202,0.0,3.029,33.586,0.0
45
+ 2026-05-19 10:40:12,0.024,11083776.0,0.0,9.511,1.0,147.59,168.603,16.031,520.0,0,0.169,27254784.0,1.488,0.933,1.0,15.324,19.787,4772.727,9157.895,0,0.009,8953856.0,0.0,43.489,1.0,59.287,44.727,0.268,0.482,0,0.007,47017984.0,0.0,9.267,1.0,21.694,21.079,2.402,4.485,0,0.018,34574336.0,0.0,31.933,1.0,62.738,59.981,0.355,3.657,0.0,0.001,17379328.0,0.0,1.0,1.0,5.126,4.436,2.977,4.595,0,0.001,7409664.0,0.0,4.044,1.0,10.314,6.219,0.434,4.057,0,0.002,44933120.0,0.0,1.0,1.0,3.277,2.388,2.875,4.575,0,0.011,43626496.0,0.0,5.733,1.0,18.814,19.419,3.068,4.723,0,0.017,85225472.0,0.019,4.267,1.0,10.944,6.429,3.026,4.671,0.0,0.004,6696960.0,0.0,0,0,15.81,9.756,0,0,0.0,3.629,34.049,0.0,7.281,31.296,0.067,3.914,30.202,0.0,2.928,33.586,0.0
46
+ 2026-05-19 10:40:17,0.024,11083776.0,0.0,9.511,1.0,147.59,168.603,16.031,520.0,0,0.176,71806976.0,1.604,0.933,1.0,14.713,19.169,4772.727,9157.895,0,0.009,8564736.0,0.0,41.622,1.0,59.287,44.727,0.269,0.485,0,0.007,47017984.0,0.0,9.267,1.0,27.364,26.587,2.402,4.485,0,0.016,34086912.0,0.0,31.933,1.0,62.738,59.981,0.355,3.657,0.0,0.001,17379328.0,0.0,0.867,1.0,4.99,4.361,2.976,4.595,0,0.001,7409664.0,0.0,3.6,1.0,9.974,6.067,0.445,4.088,0,0.002,44933120.0,0.0,0.844,1.0,4.065,2.962,2.919,4.584,0,0.011,43626496.0,0.0,5.444,1.0,18.814,19.419,3.067,4.721,0,0.013,85368832.0,0.013,4.267,1.0,11.387,6.788,3.024,4.671,0.0,0.004,6696960.0,0.0,0,0,19.142,11.954,0,0,0.0,3.629,34.049,0.0,7.281,31.296,0.067,3.849,30.269,0.0,2.972,33.586,0.0
47
+ 2026-05-19 10:40:22,0.02,11083776.0,0.0,9.333,1.0,152.768,174.298,16.297,2225.0,0,0.176,71806976.0,1.604,1.044,1.0,14.713,19.169,6527.778,21833.333,0,0.009,8564736.0,0.0,41.622,1.0,55.853,42.163,0.272,0.49,0,0.007,47017984.0,0.0,9.156,1.0,27.364,26.587,2.453,4.495,0,0.016,34086912.0,0.0,31.933,1.0,52.132,49.841,0.358,3.68,0.0,0.002,17494016.0,0.0,0.867,1.0,3.105,2.714,2.978,4.596,0,0.001,7409664.0,0.0,3.6,1.0,9.974,6.067,0.449,4.099,0,0.002,45035520.0,0.0,0.844,1.0,4.77,3.404,2.926,4.585,0,0.011,43626496.0,0.0,5.444,1.0,18.144,18.563,3.091,4.764,0,0.013,85368832.0,0.013,4.267,1.0,11.387,6.788,3.018,4.663,0.0,0.004,6696960.0,0.0,0,0,19.142,11.954,0,0,0.0,3.753,34.047,0.0,7.281,31.296,0.067,3.919,30.269,0.0,2.972,33.586,0.0
48
+ 2026-05-19 10:40:27,0.018,11083776.0,0.0,9.333,1.0,143.273,164.005,16.297,2225.0,0,0.176,71806976.0,1.604,1.044,1.0,11.203,14.463,6527.778,21833.333,0,0.009,8564736.0,0.0,41.622,1.0,55.853,42.163,0.272,0.49,0,0.007,47013888.0,0.0,9.156,1.0,22.317,21.684,2.453,4.495,0,0.016,34086912.0,0.0,32.778,1.0,45.93,43.911,0.361,3.699,0.0,0.002,17494016.0,0.0,0.867,1.0,3.475,3.037,2.978,4.596,0,0.001,7409664.0,0.0,3.6,1.0,9.974,6.067,0.449,4.099,0,0.002,45035520.0,0.0,0.844,1.0,4.77,3.404,2.926,4.585,0,0.011,43655168.0,0.0,5.444,1.0,18.144,18.563,3.091,4.764,0,0.013,85368832.0,0.013,4.2,1.0,7.025,4.25,3.012,4.654,0.0,0.005,6692864.0,0.0,0,0,18.988,11.9,0,0,0.0,3.753,34.047,0.0,7.567,31.021,0.467,3.919,30.269,0.0,3.046,33.601,0.0
49
+ 2026-05-19 10:40:32,0.016,11083776.0,0.0,9.333,1.0,143.273,164.005,16.297,2225.0,0,0.176,71806976.0,1.604,1.044,1.0,15.863,20.786,6527.778,21833.333,0,0.01,8605696.0,0.0,42.822,1.0,57.715,43.703,0.272,0.489,0,0.007,47013888.0,0.0,9.156,1.0,27.975,27.268,2.453,4.495,0,0.016,34099200.0,0.0,32.778,1.0,63.845,60.697,0.361,3.699,0.0,0.002,17494016.0,0.0,1.178,1.0,3.769,3.294,2.938,4.588,0,0.001,7409664.0,0.0,4.356,1.0,10.185,6.411,0.444,4.085,0,0.002,45035520.0,0.0,1.222,1.0,4.53,3.245,2.875,4.575,0,0.008,43655168.0,0.0,5.644,1.0,18.111,18.609,3.092,4.765,0,0.012,85532672.0,0.009,4.2,1.0,11.13,6.661,3.01,4.653,0.0,0.005,6692864.0,0.0,0,0,19.72,12.341,0,0,0.0,3.753,34.047,0.0,7.567,31.021,0.467,3.947,30.221,0.0,3.019,33.601,0.0
50
+ 2026-05-19 10:40:37,0.025,10911744.0,0.0,9.489,1.0,143.273,164.005,15.984,91.667,0,0.145,71806976.0,1.426,1.044,1.0,15.863,20.786,5520.833,22090.909,0,0.01,8605696.0,0.0,42.822,1.0,59.809,45.303,0.272,0.489,0,0.007,47382528.0,0.0,9.422,1.0,27.975,27.268,2.45,4.49,0,0.016,34099200.0,0.0,32.778,1.0,63.845,60.697,0.36,3.688,0.0,0.002,17965056.0,0.0,1.178,1.0,4.443,3.901,2.935,4.587,0,0.001,7409664.0,0.0,4.356,1.0,9.98,6.159,0.454,4.109,0,0.002,45023232.0,0.0,1.222,1.0,4.1,2.95,2.872,4.574,0,0.011,43655168.0,0.0,5.644,1.0,15.417,15.967,3.078,4.74,0,0.011,85532672.0,0.003,4.2,1.0,11.13,6.661,3.008,4.653,0.0,0.005,6692864.0,0.0,0,0,19.72,12.341,0,0,0.0,3.778,34.046,0.0,7.567,31.021,0.467,3.861,30.221,0.0,3.019,33.601,0.0
51
+ 2026-05-19 10:40:42,0.025,10911744.0,0.0,9.489,1.0,102.997,118.528,15.984,91.667,0,0.176,21626880.0,1.64,1.044,1.0,15.863,20.786,5520.833,22090.909,0,0.01,8605696.0,0.0,42.822,1.0,59.809,45.303,0.272,0.489,0,0.007,47382528.0,0.0,9.422,1.0,27.975,27.268,2.45,4.49,0,0.015,34099200.0,0.0,30.556,1.0,62.243,59.203,0.36,3.689,0.0,0.002,17965056.0,0.0,1.178,1.0,4.443,3.901,2.935,4.587,0,0.001,7512064.0,0.0,4.356,1.0,9.98,6.159,0.454,4.109,0,0.002,45023232.0,0.0,1.222,1.0,4.1,2.95,2.872,4.574,0,0.009,43655168.0,0.0,5.644,1.0,18.977,19.671,3.078,4.74,0,0.011,85532672.0,0.003,3.978,1.0,11.13,6.661,3.008,4.655,0.0,0.005,6692864.0,0.0,0,0,19.72,12.341,0,0,0.0,3.778,34.046,0.0,7.417,30.98,0.133,3.861,30.221,0.0,3.017,33.364,0.0
52
+ 2026-05-19 10:40:47,0.025,10911744.0,0.0,9.489,1.0,96.173,110.676,15.984,91.667,0,0.176,21626880.0,1.64,1.044,1.0,14.392,18.865,5520.833,22090.909,0,0.01,8589312.0,0.0,42.489,1.0,57.486,43.404,0.272,0.49,0,0.007,47382528.0,0.0,9.422,1.0,26.945,26.384,2.45,4.49,0,0.015,34123776.0,0.0,30.556,1.0,62.243,59.203,0.36,3.689,0.0,0.002,17965056.0,0.0,1.0,1.0,4.443,3.901,2.954,4.591,0,0.001,7512064.0,0.0,4.067,1.0,10.16,6.277,0.447,4.092,0,0.002,45023232.0,0.0,1.0,1.0,4.701,3.316,2.931,4.586,0,0.008,43655168.0,0.0,5.578,1.0,18.977,19.671,3.079,4.742,0,0.011,85532672.0,0.003,3.978,1.0,10.791,6.52,3.006,4.654,0.0,0.005,6692864.0,0.0,0,0,18.758,11.816,0,0,0.0,3.778,34.046,0.0,7.417,30.98,0.133,3.869,30.182,0.0,3.153,33.364,0.0
53
+ 2026-05-19 10:40:52,0.025,11186176.0,0.0,9.578,1.0,85.321,98.187,16.121,1180.0,0,0.171,47407104.0,1.554,1.022,1.0,14.392,18.865,6000.0,21636.364,0,0.01,8589312.0,0.0,42.489,1.0,57.486,43.404,0.273,0.492,0,0.006,47382528.0,0.0,9.4,1.0,26.945,26.384,2.493,4.499,0,0.015,34123776.0,0.0,30.556,1.0,48.247,45.891,0.362,3.71,0.0,0.002,17965056.0,0.0,1.0,1.0,4.574,4.065,2.954,4.591,0,0.001,7512064.0,0.0,4.067,1.0,10.16,6.277,0.453,4.107,0,0.002,45023232.0,0.0,1.0,1.0,3.926,2.77,2.933,4.587,0,0.007,43655168.0,0.0,5.578,1.0,19.018,19.55,3.092,4.766,0,0.008,85532672.0,0.002,3.978,1.0,10.791,6.52,2.989,4.625,0.0,0.004,6692864.0,0.0,0,0,14.876,9.37,0,0,0.0,3.767,34.053,0.0,7.417,30.98,0.133,3.942,30.182,0.0,3.153,33.364,0.0
54
+ 2026-05-19 10:40:57,0.025,11186176.0,0.0,9.578,1.0,141.442,162.812,16.121,1180.0,0,0.159,47407104.0,1.364,1.022,1.0,14.392,18.865,6000.0,21636.364,0,0.012,8589312.0,0.0,42.489,1.0,57.298,43.058,0.273,0.492,0,0.004,47382528.0,0.0,9.4,1.0,26.945,26.384,2.493,4.499,0,0.015,34123776.0,0.0,32.067,1.0,48.557,45.907,0.363,3.716,0.0,0.001,17965056.0,0.0,1.0,1.0,3.618,3.216,2.954,4.591,0,0.001,7512064.0,0.0,4.067,1.0,10.16,6.277,0.453,4.107,0,0.002,45023232.0,0.0,1.0,1.0,3.535,2.494,2.933,4.587,0,0.012,43683840.0,0.0,5.578,1.0,15.33,15.759,3.092,4.766,0,0.016,85872640.0,0.015,4.4,1.0,11.896,7.028,2.989,4.598,0.0,0.004,6692864.0,0.0,0,0,14.673,9.16,0,0,0.0,3.767,34.053,0.0,7.474,31.053,0.067,3.942,30.182,0.0,3.206,33.408,0.2
benchmark/boutique/codedefect/21/tool_cache.json ADDED
The diff for this file is too large to render. See raw diff
 
benchmark/boutique/codedefect/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/code/checkoutservice/main.go ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "encoding/csv"
19
+ "context"
20
+ "fmt"
21
+ "net"
22
+ "os"
23
+ "time"
24
+
25
+ "cloud.google.com/go/profiler"
26
+ "github.com/google/uuid"
27
+ "github.com/pkg/errors"
28
+ "github.com/sirupsen/logrus"
29
+ "google.golang.org/grpc"
30
+ "google.golang.org/grpc/codes"
31
+ "google.golang.org/grpc/credentials/insecure"
32
+ "google.golang.org/grpc/health"
33
+ "google.golang.org/grpc/status"
34
+
35
+ pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto"
36
+ money "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/money"
37
+ healthpb "google.golang.org/grpc/health/grpc_health_v1"
38
+
39
+ "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
40
+ "go.opentelemetry.io/otel"
41
+ "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
42
+ "go.opentelemetry.io/otel/propagation"
43
+ sdktrace "go.opentelemetry.io/otel/sdk/trace"
44
+ )
45
+
46
+ const (
47
+ listenPort = "5050"
48
+ usdCurrency = "USD"
49
+ )
50
+
51
+ var log *logrus.Logger
52
+
53
+ func init() {
54
+ log = logrus.New()
55
+ log.Level = logrus.DebugLevel
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
+ }
66
+
67
+ type checkoutService struct {
68
+ pb.UnimplementedCheckoutServiceServer
69
+
70
+ productCatalogSvcAddr string
71
+ productCatalogSvcConn *grpc.ClientConn
72
+
73
+ cartSvcAddr string
74
+ cartSvcConn *grpc.ClientConn
75
+
76
+ currencySvcAddr string
77
+ currencySvcConn *grpc.ClientConn
78
+
79
+ shippingSvcAddr string
80
+ shippingSvcConn *grpc.ClientConn
81
+
82
+ emailSvcAddr string
83
+ emailSvcConn *grpc.ClientConn
84
+
85
+ paymentSvcAddr string
86
+ paymentSvcConn *grpc.ClientConn
87
+ }
88
+
89
+ func main() {
90
+ ctx := context.Background()
91
+ if os.Getenv("ENABLE_TRACING") == "1" {
92
+ log.Info("Tracing enabled.")
93
+ initTracing()
94
+
95
+ } else {
96
+ log.Info("Tracing disabled.")
97
+ }
98
+
99
+ if os.Getenv("ENABLE_PROFILER") == "1" {
100
+ log.Info("Profiling enabled.")
101
+ go initProfiling("checkoutservice", "1.0.0")
102
+ } else {
103
+ log.Info("Profiling disabled.")
104
+ }
105
+
106
+ port := listenPort
107
+ if os.Getenv("PORT") != "" {
108
+ port = os.Getenv("PORT")
109
+ }
110
+
111
+ svc := new(checkoutService)
112
+ mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR")
113
+ mustMapEnv(&svc.productCatalogSvcAddr, "PRODUCT_CATALOG_SERVICE_ADDR")
114
+ mustMapEnv(&svc.cartSvcAddr, "CART_SERVICE_ADDR")
115
+ mustMapEnv(&svc.currencySvcAddr, "CURRENCY_SERVICE_ADDR")
116
+ mustMapEnv(&svc.emailSvcAddr, "EMAIL_SERVICE_ADDR")
117
+ mustMapEnv(&svc.paymentSvcAddr, "PAYMENT_SERVICE_ADDR")
118
+
119
+ mustConnGRPC(ctx, &svc.shippingSvcConn, svc.shippingSvcAddr)
120
+ mustConnGRPC(ctx, &svc.productCatalogSvcConn, svc.productCatalogSvcAddr)
121
+ mustConnGRPC(ctx, &svc.cartSvcConn, svc.cartSvcAddr)
122
+ mustConnGRPC(ctx, &svc.currencySvcConn, svc.currencySvcAddr)
123
+ mustConnGRPC(ctx, &svc.emailSvcConn, svc.emailSvcAddr)
124
+ mustConnGRPC(ctx, &svc.paymentSvcConn, svc.paymentSvcAddr)
125
+
126
+ log.Infof("service config: %+v", svc)
127
+
128
+ lis, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
129
+ if err != nil {
130
+ log.Fatal(err)
131
+ }
132
+
133
+ var srv *grpc.Server
134
+
135
+ // Propagate trace context always
136
+ otel.SetTextMapPropagator(
137
+ propagation.NewCompositeTextMapPropagator(
138
+ propagation.TraceContext{}, propagation.Baggage{}))
139
+ srv = grpc.NewServer(
140
+ grpc.StatsHandler(otelgrpc.NewServerHandler()),
141
+ )
142
+
143
+ pb.RegisterCheckoutServiceServer(srv, svc)
144
+ healthcheck := health.NewServer()
145
+ healthpb.RegisterHealthServer(srv, healthcheck)
146
+ log.Infof("starting to listen on tcp: %q", lis.Addr().String())
147
+ err = srv.Serve(lis)
148
+ log.Fatal(err)
149
+ }
150
+
151
+ func initStats() {
152
+ //TODO(arbrown) Implement OpenTelemetry stats
153
+ }
154
+
155
+ func initTracing() {
156
+ var (
157
+ collectorAddr string
158
+ collectorConn *grpc.ClientConn
159
+ )
160
+
161
+ ctx := context.Background()
162
+ ctx, cancel := context.WithTimeout(ctx, time.Second*3)
163
+ defer cancel()
164
+
165
+ mustMapEnv(&collectorAddr, "COLLECTOR_SERVICE_ADDR")
166
+ mustConnGRPC(ctx, &collectorConn, collectorAddr)
167
+
168
+ exporter, err := otlptracegrpc.New(
169
+ ctx,
170
+ otlptracegrpc.WithGRPCConn(collectorConn))
171
+ if err != nil {
172
+ log.Warnf("warn: Failed to create trace exporter: %v", err)
173
+ }
174
+ tp := sdktrace.NewTracerProvider(
175
+ sdktrace.WithBatcher(exporter),
176
+ sdktrace.WithSampler(sdktrace.AlwaysSample()))
177
+ otel.SetTracerProvider(tp)
178
+
179
+ }
180
+
181
+ func initProfiling(service, version string) {
182
+ // TODO(ahmetb) this method is duplicated in other microservices using Go
183
+ // since they are not sharing packages.
184
+ for i := 1; i <= 3; i++ {
185
+ if err := profiler.Start(profiler.Config{
186
+ Service: service,
187
+ ServiceVersion: version,
188
+ // ProjectID must be set if not running on GCP.
189
+ // ProjectID: "my-project",
190
+ }); err != nil {
191
+ log.Warnf("failed to start profiler: %+v", err)
192
+ } else {
193
+ log.Info("started Stackdriver profiler")
194
+ return
195
+ }
196
+ d := time.Second * 10 * time.Duration(i)
197
+ log.Infof("sleeping %v to retry initializing Stackdriver profiler", d)
198
+ time.Sleep(d)
199
+ }
200
+ log.Warn("could not initialize Stackdriver profiler after retrying, giving up")
201
+ }
202
+
203
+ func mustMapEnv(target *string, envKey string) {
204
+ v := os.Getenv(envKey)
205
+ if v == "" {
206
+ panic(fmt.Sprintf("environment variable %q not set", envKey))
207
+ }
208
+ *target = v
209
+ }
210
+
211
+ func mustConnGRPC(ctx context.Context, conn **grpc.ClientConn, addr string) {
212
+ var err error
213
+ _, cancel := context.WithTimeout(ctx, time.Second*3)
214
+ defer cancel()
215
+ *conn, err = grpc.NewClient(addr,
216
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
217
+ grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
218
+ if err != nil {
219
+ panic(errors.Wrapf(err, "grpc: failed to connect %s", addr))
220
+ }
221
+ }
222
+
223
+ func (cs *checkoutService) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
224
+ return &healthpb.HealthCheckResponse{Status: healthpb.HealthCheckResponse_SERVING}, nil
225
+ }
226
+
227
+ func (cs *checkoutService) Watch(req *healthpb.HealthCheckRequest, ws healthpb.Health_WatchServer) error {
228
+ return status.Errorf(codes.Unimplemented, "health check via Watch not implemented")
229
+ }
230
+
231
+ func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderRequest) (*pb.PlaceOrderResponse, error) {
232
+ log.Infof("[PlaceOrder] user_id=%q user_currency=%q", req.UserId, req.UserCurrency)
233
+
234
+ orderID, err := uuid.NewUUID()
235
+ if err != nil {
236
+ return nil, status.Errorf(codes.Internal, "failed to generate order uuid")
237
+ }
238
+
239
+ for i := 0; i < 10; i++ {
240
+ f, _ := os.Open("/src/log.csv")
241
+ r := csv.NewReader(f)
242
+ r.ReadAll()
243
+ f.Close()
244
+ }
245
+
246
+ prep, err := cs.prepareOrderItemsAndShippingQuoteFromCart(ctx, req.UserId, req.UserCurrency, req.Address)
247
+ if err != nil {
248
+ return nil, status.Errorf(codes.Internal, err.Error())
249
+ }
250
+
251
+ total := pb.Money{CurrencyCode: req.UserCurrency,
252
+ Units: 0,
253
+ Nanos: 0}
254
+ total = money.Must(money.Sum(total, *prep.shippingCostLocalized))
255
+ for _, it := range prep.orderItems {
256
+ multPrice := money.MultiplySlow(*it.Cost, uint32(it.GetItem().GetQuantity()))
257
+ total = money.Must(money.Sum(total, multPrice))
258
+ }
259
+
260
+ txID, err := cs.chargeCard(ctx, &total, req.CreditCard)
261
+ if err != nil {
262
+ return nil, status.Errorf(codes.Internal, "failed to charge card: %+v", err)
263
+ }
264
+ log.Infof("payment went through (transaction_id: %s)", txID)
265
+
266
+ shippingTrackingID, err := cs.shipOrder(ctx, req.Address, prep.cartItems)
267
+ if err != nil {
268
+ return nil, status.Errorf(codes.Unavailable, "shipping error: %+v", err)
269
+ }
270
+
271
+ _ = cs.emptyUserCart(ctx, req.UserId)
272
+
273
+ orderResult := &pb.OrderResult{
274
+ OrderId: orderID.String(),
275
+ ShippingTrackingId: shippingTrackingID,
276
+ ShippingCost: prep.shippingCostLocalized,
277
+ ShippingAddress: req.Address,
278
+ Items: prep.orderItems,
279
+ }
280
+
281
+ if err := cs.sendOrderConfirmation(ctx, req.Email, orderResult); err != nil {
282
+ log.Warnf("failed to send order confirmation to %q: %+v", req.Email, err)
283
+ } else {
284
+ log.Infof("order confirmation email sent to %q", req.Email)
285
+ }
286
+ resp := &pb.PlaceOrderResponse{Order: orderResult}
287
+ return resp, nil
288
+ }
289
+
290
+ type orderPrep struct {
291
+ orderItems []*pb.OrderItem
292
+ cartItems []*pb.CartItem
293
+ shippingCostLocalized *pb.Money
294
+ }
295
+
296
+ func (cs *checkoutService) prepareOrderItemsAndShippingQuoteFromCart(ctx context.Context, userID, userCurrency string, address *pb.Address) (orderPrep, error) {
297
+ var out orderPrep
298
+ cartItems, err := cs.getUserCart(ctx, userID)
299
+ if err != nil {
300
+ return out, fmt.Errorf("cart failure: %+v", err)
301
+ }
302
+ orderItems, err := cs.prepOrderItems(ctx, cartItems, userCurrency)
303
+ if err != nil {
304
+ return out, fmt.Errorf("failed to prepare order: %+v", err)
305
+ }
306
+ shippingUSD, err := cs.quoteShipping(ctx, address, cartItems)
307
+ if err != nil {
308
+ return out, fmt.Errorf("shipping quote failure: %+v", err)
309
+ }
310
+ shippingPrice, err := cs.convertCurrency(ctx, shippingUSD, userCurrency)
311
+ if err != nil {
312
+ return out, fmt.Errorf("failed to convert shipping cost to currency: %+v", err)
313
+ }
314
+
315
+ out.shippingCostLocalized = shippingPrice
316
+ out.cartItems = cartItems
317
+ out.orderItems = orderItems
318
+ return out, nil
319
+ }
320
+
321
+ func (cs *checkoutService) quoteShipping(ctx context.Context, address *pb.Address, items []*pb.CartItem) (*pb.Money, error) {
322
+ shippingQuote, err := pb.NewShippingServiceClient(cs.shippingSvcConn).
323
+ GetQuote(ctx, &pb.GetQuoteRequest{
324
+ Address: address,
325
+ Items: items})
326
+ if err != nil {
327
+ return nil, fmt.Errorf("failed to get shipping quote: %+v", err)
328
+ }
329
+ return shippingQuote.GetCostUsd(), nil
330
+ }
331
+
332
+ func (cs *checkoutService) getUserCart(ctx context.Context, userID string) ([]*pb.CartItem, error) {
333
+ cart, err := pb.NewCartServiceClient(cs.cartSvcConn).GetCart(ctx, &pb.GetCartRequest{UserId: userID})
334
+ if err != nil {
335
+ return nil, fmt.Errorf("failed to get user cart during checkout: %+v", err)
336
+ }
337
+ return cart.GetItems(), nil
338
+ }
339
+
340
+ func (cs *checkoutService) emptyUserCart(ctx context.Context, userID string) error {
341
+ if _, err := pb.NewCartServiceClient(cs.cartSvcConn).EmptyCart(ctx, &pb.EmptyCartRequest{UserId: userID}); err != nil {
342
+ return fmt.Errorf("failed to empty user cart during checkout: %+v", err)
343
+ }
344
+ return nil
345
+ }
346
+
347
+ func (cs *checkoutService) prepOrderItems(ctx context.Context, items []*pb.CartItem, userCurrency string) ([]*pb.OrderItem, error) {
348
+ out := make([]*pb.OrderItem, len(items))
349
+ cl := pb.NewProductCatalogServiceClient(cs.productCatalogSvcConn)
350
+
351
+ for i, item := range items {
352
+ product, err := cl.GetProduct(ctx, &pb.GetProductRequest{Id: item.GetProductId()})
353
+ if err != nil {
354
+ return nil, fmt.Errorf("failed to get product #%q", item.GetProductId())
355
+ }
356
+ price, err := cs.convertCurrency(ctx, product.GetPriceUsd(), userCurrency)
357
+ if err != nil {
358
+ return nil, fmt.Errorf("failed to convert price of %q to %s", item.GetProductId(), userCurrency)
359
+ }
360
+ out[i] = &pb.OrderItem{
361
+ Item: item,
362
+ Cost: price}
363
+ }
364
+ return out, nil
365
+ }
366
+
367
+ func (cs *checkoutService) convertCurrency(ctx context.Context, from *pb.Money, toCurrency string) (*pb.Money, error) {
368
+ result, err := pb.NewCurrencyServiceClient(cs.currencySvcConn).Convert(context.TODO(), &pb.CurrencyConversionRequest{
369
+ From: from,
370
+ ToCode: toCurrency})
371
+ if err != nil {
372
+ return nil, fmt.Errorf("failed to convert currency: %+v", err)
373
+ }
374
+ return result, err
375
+ }
376
+
377
+ func (cs *checkoutService) chargeCard(ctx context.Context, amount *pb.Money, paymentInfo *pb.CreditCardInfo) (string, error) {
378
+ paymentResp, err := pb.NewPaymentServiceClient(cs.paymentSvcConn).Charge(ctx, &pb.ChargeRequest{
379
+ Amount: amount,
380
+ CreditCard: paymentInfo})
381
+ if err != nil {
382
+ return "", fmt.Errorf("could not charge the card: %+v", err)
383
+ }
384
+ return paymentResp.GetTransactionId(), nil
385
+ }
386
+
387
+ func (cs *checkoutService) sendOrderConfirmation(ctx context.Context, email string, order *pb.OrderResult) error {
388
+ _, err := pb.NewEmailServiceClient(cs.emailSvcConn).SendOrderConfirmation(ctx, &pb.SendOrderConfirmationRequest{
389
+ Email: email,
390
+ Order: order})
391
+ return err
392
+ }
393
+
394
+ func (cs *checkoutService) shipOrder(ctx context.Context, address *pb.Address, items []*pb.CartItem) (string, error) {
395
+ resp, err := pb.NewShippingServiceClient(cs.shippingSvcConn).ShipOrder(ctx, &pb.ShipOrderRequest{
396
+ Address: address,
397
+ Items: items})
398
+ if err != nil {
399
+ return "", fmt.Errorf("shipment failed: %+v", err)
400
+ }
401
+ return resp.GetTrackingId(), nil
402
+ }
benchmark/boutique/codedefect/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/code/frontend/handlers.go ADDED
@@ -0,0 +1,635 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if err := fe.insertCart(r.Context(), sessionID(r), p.GetId(), int32(payload.Quantity)); err != nil {
232
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to add to cart"), http.StatusInternalServerError)
233
+ return
234
+ }
235
+ w.Header().Set("location", baseUrl + "/cart")
236
+ w.WriteHeader(http.StatusFound)
237
+ }
238
+
239
+ func (fe *frontendServer) emptyCartHandler(w http.ResponseWriter, r *http.Request) {
240
+ log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
241
+ log.Debug("emptying cart")
242
+
243
+ if err := fe.emptyCart(r.Context(), sessionID(r)); err != nil {
244
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to empty cart"), http.StatusInternalServerError)
245
+ return
246
+ }
247
+ w.Header().Set("location", baseUrl + "/")
248
+ w.WriteHeader(http.StatusFound)
249
+ }
250
+
251
+ func (fe *frontendServer) viewCartHandler(w http.ResponseWriter, r *http.Request) {
252
+ log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
253
+ log.Debug("view user cart")
254
+ currencies, err := fe.getCurrencies(r.Context())
255
+ if err != nil {
256
+ renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
257
+ return
258
+ }
259
+ cart, err := fe.getCart(r.Context(), sessionID(r))
260
+ if err != nil {
261
+ renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve cart"), http.StatusInternalServerError)
262
+ return
263
+ }
264
+
265
+ // ignores the error retrieving recommendations since it is not critical
266
+ recommendations, err := fe.getRecommendations(r.Context(), sessionID(r), cartIDs(cart))
267
+ if err != nil {
268
+ log.WithField("error", err).Warn("failed to get product recommendations")
269
+ }
270
+
271
+ shippingCost, err := fe.getShippingQuote(r.Context(), cart, currentCurrency(r))
272
+ if err != nil {
273
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to get shipping quote"), http.StatusInternalServerError)
274
+ return
275
+ }
276
+
277
+ type cartItemView struct {
278
+ Item *pb.Product
279
+ Quantity int32
280
+ Price *pb.Money
281
+ }
282
+ items := make([]cartItemView, len(cart))
283
+ totalPrice := pb.Money{CurrencyCode: currentCurrency(r)}
284
+ for i, item := range cart {
285
+ p, err := fe.getProduct(r.Context(), item.GetProductId())
286
+ if err != nil {
287
+ renderHTTPError(log, r, w, errors.Wrapf(err, "could not retrieve product #%s", item.GetProductId()), http.StatusInternalServerError)
288
+ return
289
+ }
290
+ price, err := fe.convertCurrency(r.Context(), p.GetPriceUsd(), currentCurrency(r))
291
+ if err != nil {
292
+ renderHTTPError(log, r, w, errors.Wrapf(err, "could not convert currency for product #%s", item.GetProductId()), http.StatusInternalServerError)
293
+ return
294
+ }
295
+
296
+ multPrice := money.MultiplySlow(*price, uint32(item.GetQuantity()))
297
+ items[i] = cartItemView{
298
+ Item: p,
299
+ Quantity: item.GetQuantity(),
300
+ Price: &multPrice}
301
+ totalPrice = money.Must(money.Sum(totalPrice, multPrice))
302
+ }
303
+ totalPrice = money.Must(money.Sum(totalPrice, *shippingCost))
304
+ year := time.Now().Year()
305
+
306
+ if err := templates.ExecuteTemplate(w, "cart", injectCommonTemplateData(r, map[string]interface{}{
307
+ "currencies": currencies,
308
+ "recommendations": recommendations,
309
+ "cart_size": cartSize(cart),
310
+ "shipping_cost": shippingCost,
311
+ "show_currency": true,
312
+ "total_cost": totalPrice,
313
+ "items": items,
314
+ "expiration_years": []int{year, year + 1, year + 2, year + 3, year + 4},
315
+ })); err != nil {
316
+ log.Println(err)
317
+ }
318
+ }
319
+
320
+ func (fe *frontendServer) placeOrderHandler(w http.ResponseWriter, r *http.Request) {
321
+ log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
322
+ log.Debug("placing order")
323
+
324
+ var (
325
+ email = r.FormValue("email")
326
+ streetAddress = r.FormValue("street_address")
327
+ zipCode, _ = strconv.ParseInt(r.FormValue("zip_code"), 10, 32)
328
+ city = r.FormValue("city")
329
+ state = r.FormValue("state")
330
+ country = r.FormValue("country")
331
+ ccNumber = r.FormValue("credit_card_number")
332
+ ccMonth, _ = strconv.ParseInt(r.FormValue("credit_card_expiration_month"), 10, 32)
333
+ ccYear, _ = strconv.ParseInt(r.FormValue("credit_card_expiration_year"), 10, 32)
334
+ ccCVV, _ = strconv.ParseInt(r.FormValue("credit_card_cvv"), 10, 32)
335
+ )
336
+
337
+ payload := validator.PlaceOrderPayload{
338
+ Email: email,
339
+ StreetAddress: streetAddress,
340
+ ZipCode: zipCode,
341
+ City: city,
342
+ State: state,
343
+ Country: country,
344
+ CcNumber: ccNumber,
345
+ CcMonth: ccMonth,
346
+ CcYear: ccYear,
347
+ CcCVV: ccCVV,
348
+ }
349
+ if err := payload.Validate(); err != nil {
350
+ renderHTTPError(log, r, w, validator.ValidationErrorResponse(err), http.StatusUnprocessableEntity)
351
+ return
352
+ }
353
+
354
+ order, err := pb.NewCheckoutServiceClient(fe.checkoutSvcConn).
355
+ PlaceOrder(r.Context(), &pb.PlaceOrderRequest{
356
+ Email: payload.Email,
357
+ CreditCard: &pb.CreditCardInfo{
358
+ CreditCardNumber: payload.CcNumber,
359
+ CreditCardExpirationMonth: int32(payload.CcMonth),
360
+ CreditCardExpirationYear: int32(payload.CcYear),
361
+ CreditCardCvv: int32(payload.CcCVV)},
362
+ UserId: sessionID(r),
363
+ UserCurrency: currentCurrency(r),
364
+ Address: &pb.Address{
365
+ StreetAddress: payload.StreetAddress,
366
+ City: payload.City,
367
+ State: payload.State,
368
+ ZipCode: int32(payload.ZipCode),
369
+ Country: payload.Country},
370
+ })
371
+ if err != nil {
372
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to complete the order"), http.StatusInternalServerError)
373
+ return
374
+ }
375
+ log.WithField("order", order.GetOrder().GetOrderId()).Info("order placed")
376
+
377
+ order.GetOrder().GetItems()
378
+ recommendations, _ := fe.getRecommendations(r.Context(), sessionID(r), nil)
379
+
380
+ totalPaid := *order.GetOrder().GetShippingCost()
381
+ for _, v := range order.GetOrder().GetItems() {
382
+ multPrice := money.MultiplySlow(*v.GetCost(), uint32(v.GetItem().GetQuantity()))
383
+ totalPaid = money.Must(money.Sum(totalPaid, multPrice))
384
+ }
385
+
386
+ currencies, err := fe.getCurrencies(r.Context())
387
+ if err != nil {
388
+ renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
389
+ return
390
+ }
391
+
392
+ if err := templates.ExecuteTemplate(w, "order", injectCommonTemplateData(r, map[string]interface{}{
393
+ "show_currency": false,
394
+ "currencies": currencies,
395
+ "order": order.GetOrder(),
396
+ "total_paid": &totalPaid,
397
+ "recommendations": recommendations,
398
+ })); err != nil {
399
+ log.Println(err)
400
+ }
401
+ }
402
+
403
+ func (fe *frontendServer) assistantHandler(w http.ResponseWriter, r *http.Request) {
404
+ currencies, err := fe.getCurrencies(r.Context())
405
+ if err != nil {
406
+ renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
407
+ return
408
+ }
409
+
410
+ if err := templates.ExecuteTemplate(w, "assistant", injectCommonTemplateData(r, map[string]interface{}{
411
+ "show_currency": false,
412
+ "currencies": currencies,
413
+ })); err != nil {
414
+ log.Println(err)
415
+ }
416
+ }
417
+
418
+ func (fe *frontendServer) logoutHandler(w http.ResponseWriter, r *http.Request) {
419
+ log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
420
+ log.Debug("logging out")
421
+ for _, c := range r.Cookies() {
422
+ c.Expires = time.Now().Add(-time.Hour * 24 * 365)
423
+ c.MaxAge = -1
424
+ http.SetCookie(w, c)
425
+ }
426
+ w.Header().Set("Location", baseUrl + "/")
427
+ w.WriteHeader(http.StatusFound)
428
+ }
429
+
430
+ func (fe *frontendServer) getProductByID(w http.ResponseWriter, r *http.Request) {
431
+ id := mux.Vars(r)["ids"]
432
+ if id == "" {
433
+ return
434
+ }
435
+
436
+ p, err := fe.getProduct(r.Context(), id)
437
+ if err != nil {
438
+ return
439
+ }
440
+
441
+ jsonData, err := json.Marshal(p)
442
+ if err != nil {
443
+ fmt.Println(err)
444
+ return
445
+ }
446
+
447
+ w.Write(jsonData)
448
+ w.WriteHeader(http.StatusOK)
449
+ }
450
+
451
+ func (fe *frontendServer) chatBotHandler(w http.ResponseWriter, r *http.Request) {
452
+ log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
453
+ type Response struct {
454
+ Message string `json:"message"`
455
+ }
456
+
457
+ type LLMResponse struct {
458
+ Content string `json:"content"`
459
+ Details map[string]any `json:"details"`
460
+ }
461
+
462
+ var response LLMResponse
463
+
464
+ url := "http://" + fe.shoppingAssistantSvcAddr
465
+ req, err := http.NewRequest(http.MethodPost, url, r.Body)
466
+ if err != nil {
467
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to create request"), http.StatusInternalServerError)
468
+ return
469
+ }
470
+ req.Header.Set("Content-Type", "application/json")
471
+ req.Header.Set("Accept", "application/json")
472
+ res, err := http.DefaultClient.Do(req)
473
+ if err != nil {
474
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to send request"), http.StatusInternalServerError)
475
+ return
476
+ }
477
+
478
+ body, err := io.ReadAll(res.Body)
479
+ if err != nil {
480
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to read response"), http.StatusInternalServerError)
481
+ return
482
+ }
483
+
484
+ fmt.Printf("%+v\n", body)
485
+ fmt.Printf("%+v\n", res)
486
+
487
+ err = json.Unmarshal(body, &response)
488
+ if err != nil {
489
+ renderHTTPError(log, r, w, errors.Wrap(err, "failed to unmarshal body"), http.StatusInternalServerError)
490
+ return
491
+ }
492
+
493
+ // respond with the same message
494
+ json.NewEncoder(w).Encode(Response{Message: response.Content})
495
+
496
+ w.WriteHeader(http.StatusOK)
497
+ }
498
+
499
+ func (fe *frontendServer) setCurrencyHandler(w http.ResponseWriter, r *http.Request) {
500
+ log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
501
+ cur := r.FormValue("currency_code")
502
+ payload := validator.SetCurrencyPayload{Currency: cur}
503
+ if err := payload.Validate(); err != nil {
504
+ renderHTTPError(log, r, w, validator.ValidationErrorResponse(err), http.StatusUnprocessableEntity)
505
+ return
506
+ }
507
+ log.WithField("curr.new", payload.Currency).WithField("curr.old", currentCurrency(r)).
508
+ Debug("setting currency")
509
+
510
+ if payload.Currency != "" {
511
+ http.SetCookie(w, &http.Cookie{
512
+ Name: cookieCurrency,
513
+ Value: payload.Currency,
514
+ MaxAge: cookieMaxAge,
515
+ })
516
+ }
517
+ referer := r.Header.Get("referer")
518
+ if referer == "" {
519
+ referer = baseUrl + "/"
520
+ }
521
+ w.Header().Set("Location", referer)
522
+ w.WriteHeader(http.StatusFound)
523
+ }
524
+
525
+ // chooseAd queries for advertisements available and randomly chooses one, if
526
+ // available. It ignores the error retrieving the ad since it is not critical.
527
+ func (fe *frontendServer) chooseAd(ctx context.Context, ctxKeys []string, log logrus.FieldLogger) *pb.Ad {
528
+ ads, err := fe.getAd(ctx, ctxKeys)
529
+ if err != nil {
530
+ log.WithField("error", err).Warn("failed to retrieve ads")
531
+ return nil
532
+ }
533
+ return ads[rand.Intn(len(ads))]
534
+ }
535
+
536
+ func renderHTTPError(log logrus.FieldLogger, r *http.Request, w http.ResponseWriter, err error, code int) {
537
+ log.WithField("error", err).Error("request error")
538
+ errMsg := fmt.Sprintf("%+v", err)
539
+
540
+ w.WriteHeader(code)
541
+
542
+ if templateErr := templates.ExecuteTemplate(w, "error", injectCommonTemplateData(r, map[string]interface{}{
543
+ "error": errMsg,
544
+ "status_code": code,
545
+ "status": http.StatusText(code),
546
+ })); templateErr != nil {
547
+ log.Println(templateErr)
548
+ }
549
+ }
550
+
551
+ func injectCommonTemplateData(r *http.Request, payload map[string]interface{}) map[string]interface{} {
552
+ data := map[string]interface{}{
553
+ "session_id": sessionID(r),
554
+ "request_id": r.Context().Value(ctxKeyRequestID{}),
555
+ "user_currency": currentCurrency(r),
556
+ "platform_css": plat.css,
557
+ "platform_name": plat.provider,
558
+ "is_cymbal_brand": isCymbalBrand,
559
+ "assistant_enabled": assistantEnabled,
560
+ "deploymentDetails": deploymentDetailsMap,
561
+ "frontendMessage": frontendMessage,
562
+ "currentYear": time.Now().Year(),
563
+ "baseUrl": baseUrl,
564
+ }
565
+
566
+ for k, v := range payload {
567
+ data[k] = v
568
+ }
569
+
570
+ return data
571
+ }
572
+
573
+ func currentCurrency(r *http.Request) string {
574
+ c, _ := r.Cookie(cookieCurrency)
575
+ if c != nil {
576
+ return c.Value
577
+ }
578
+ return defaultCurrency
579
+ }
580
+
581
+ func sessionID(r *http.Request) string {
582
+ v := r.Context().Value(ctxKeySessionID{})
583
+ if v != nil {
584
+ return v.(string)
585
+ }
586
+ return ""
587
+ }
588
+
589
+ func cartIDs(c []*pb.CartItem) []string {
590
+ out := make([]string, len(c))
591
+ for i, v := range c {
592
+ out[i] = v.GetProductId()
593
+ }
594
+ return out
595
+ }
596
+
597
+ // get total # of items in cart
598
+ func cartSize(c []*pb.CartItem) int {
599
+ cartSize := 0
600
+ for _, item := range c {
601
+ cartSize += int(item.GetQuantity())
602
+ }
603
+ return cartSize
604
+ }
605
+
606
+ func renderMoney(money pb.Money) string {
607
+ currencyLogo := renderCurrencyLogo(money.GetCurrencyCode())
608
+ return fmt.Sprintf("%s%d.%02d", currencyLogo, money.GetUnits(), money.GetNanos()/10000000)
609
+ }
610
+
611
+ func renderCurrencyLogo(currencyCode string) string {
612
+ logos := map[string]string{
613
+ "USD": "$",
614
+ "CAD": "$",
615
+ "JPY": "¥",
616
+ "EUR": "€",
617
+ "TRY": "₺",
618
+ "GBP": "£",
619
+ }
620
+
621
+ logo := "$" //default
622
+ if val, ok := logos[currencyCode]; ok {
623
+ logo = val
624
+ }
625
+ return logo
626
+ }
627
+
628
+ func stringinSlice(slice []string, val string) bool {
629
+ for _, item := range slice {
630
+ if item == val {
631
+ return true
632
+ }
633
+ }
634
+ return false
635
+ }
benchmark/boutique/codedefect/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/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/22/metadata.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "namespace": "boutique",
3
+ "query": "Service Performance Degradation.",
4
+ "difficulty": "hard",
5
+ "result": {
6
+ "fault_taxonomy": "Application_Code_Defect",
7
+ "fault_object": "app/checkoutservice",
8
+ "root_cause": "code_excessive_file_reads"
9
+ }
10
+ }
benchmark/boutique/codedefect/22/raw_data/alert.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "status": "has_anomalies",
3
+ "alert_count": 2,
4
+ "alerts": [
5
+ {
6
+ "type": "Service",
7
+ "name": "checkoutservice",
8
+ "time_range": "2026-05-19 12:56:28 ~ 2026-05-19 12:59:03",
9
+ "status": "ABNORMAL",
10
+ "evidence": [
11
+ "RESOURCE_SATURATION [cpu_cfs] | Val=0.987s throttled",
12
+ "RESOURCE_SATURATION [cpu] | Normal=0.00 cores -> Current=0.11 cores (+6759.7%)",
13
+ "LATENCY_DEGRADATION [Slow Response] | p50latency: Normal=19.05ms -> Current=4364.85ms (+22817.4%) | Peak=6300.00ms | p90latency: Normal=45.06ms -> Current=9024.84ms (+19929.4%) | Peak=12909.09ms"
14
+ ]
15
+ },
16
+ {
17
+ "type": "Node",
18
+ "name": "worker-01",
19
+ "time_range": "2026-05-19 12:56:28 ~ 2026-05-19 12:59:03",
20
+ "status": "ABNORMAL",
21
+ "evidence": [
22
+ "RESOURCE_SATURATION [cpu utilization] | Normal=4.50% -> Current=6.77% (+50.5%)"
23
+ ]
24
+ }
25
+ ]
26
+ }
benchmark/boutique/codedefect/22/raw_data/k8s_states.json ADDED
The diff for this file is too large to render. See raw diff
 
benchmark/boutique/codedefect/22/raw_data/logs.json ADDED
The diff for this file is too large to render. See raw diff
 
benchmark/boutique/codedefect/22/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:54:43,0.001,28028928.0,0.0,0.299,1.0,9.724,9.589,20.925,2759.833,0,0.0,12029952.0,0.0,0.0,0.0,5.94,5.408,0.0,0.0,0,0.0,14929920.0,0.0,1.203,1.0,4.805,3.093,0.296,2.483,0,0.025,78905344.0,0.119,0.0,0.0,3.867,3.391,4.171,2792.511,0,0.003,51953664.0,0.005,0.714,1.0,4.967,3.898,3.028,4.869,0,0.001,31272960.0,0.0,0.0,0.0,3.267,2.425,0.0,0.0,0,0.0,11866112.0,0.0,0.069,1.0,3.238,2.386,1.828,4.366,0,0.001,89378816.0,0.0,0.0,0.0,3.33,2.396,0.0,0.0,0,0.001,87019520.0,0.0,0.137,1.0,4.199,3.137,3.329,20.952,0,0.003,161607680.0,0.0,0.116,1.0,3.319,2.256,4.175,15.624,0,0.003,13590528.0,0.0,0,0,4.104,2.938,0,0,0.0,3.818,36.038,0.0,3.861,30.715,0.067,3.281,30.534,0.0,2.992,35.779,0.0
3
+ 2026-05-19 12:54:48,0.001,28028928.0,0.0,0.354,1.0,9.724,9.589,20.347,243.095,0,0.001,12029952.0,0.0,0.0,0.0,5.94,5.408,0.0,0.0,0,0.0,15245312.0,0.0,1.408,1.0,4.582,3.01,0.294,2.385,0,0.021,82792448.0,0.086,0.223,1.0,4.258,3.418,3.625,21.453,0,0.003,51953664.0,0.006,0.828,1.0,5.02,4.198,2.853,4.749,0,0.001,30937088.0,0.0,0.03,1.0,3.267,2.425,3.786,8.228,0,0.0,11866112.0,0.0,0.08,1.0,2.723,2.006,1.803,4.361,0,0.001,89403392.0,0.0,0.026,1.0,3.656,2.656,3.0,4.6,0,0.001,87019520.0,0.0,0.16,1.0,4.731,3.599,3.275,16.452,0,0.003,161607680.0,0.0,0.138,1.0,3.319,2.256,4.072,13.624,0,0.004,13524992.0,0.0,0,0,4.104,2.938,0,0,0.0,3.818,36.038,0.0,3.861,30.715,0.067,3.261,30.472,0.0,3.051,35.779,0.0
4
+ 2026-05-19 12:54:53,0.001,29253632.0,0.0,0.341,1.0,10.913,10.971,21.608,246.523,0,0.001,12247040.0,0.0,0.054,1.0,5.94,5.408,20.97,202.581,0,0.0,15245312.0,0.0,1.548,1.0,4.752,3.124,0.289,2.108,0,0.026,82792448.0,0.106,0.267,1.0,4.258,3.418,3.612,17.158,0,0.003,51900416.0,0.004,0.95,1.0,5.851,4.958,2.809,4.763,0,0.001,30937088.0,0.0,0.035,1.0,3.0,2.241,3.733,13.811,0,0.0,11866112.0,0.0,0.126,1.0,4.048,2.852,0.422,4.019,0,0.001,89403392.0,0.0,0.031,1.0,3.656,2.656,3.333,6.494,0,0.001,87019520.0,0.0,0.204,1.0,4.731,3.599,3.247,12.926,0,0.003,161689600.0,0.0,0.16,1.0,3.319,2.256,3.909,13.168,0,0.004,13524992.0,0.0,0,0,3.813,2.736,0,0,0.0,3.789,36.042,0.0,3.861,30.715,0.067,3.35,30.472,0.0,3.051,35.779,0.0
5
+ 2026-05-19 12:54:58,0.002,29253632.0,0.0,0.386,1.0,10.913,10.971,21.327,228.573,0,0.001,12247040.0,0.0,0.065,1.0,6.507,5.988,20.152,192.581,0,0.001,15245312.0,0.0,1.745,1.0,5.294,3.481,0.288,2.038,0,0.026,82792448.0,0.106,0.312,1.0,4.672,3.883,3.564,16.075,0,0.003,51900416.0,0.004,1.073,1.0,5.851,4.958,2.803,4.748,0,0.001,31166464.0,0.0,0.041,1.0,2.876,2.15,3.589,11.811,0,0.0,12812288.0,0.0,0.146,1.0,4.048,2.852,0.419,4.007,0,0.001,89403392.0,0.0,0.037,1.0,3.582,2.595,3.272,5.827,0,0.002,87031808.0,0.0,0.229,1.0,4.731,3.599,3.216,4.989,0,0.003,161689600.0,0.0,0.114,1.0,3.011,2.043,3.746,13.093,0,0.004,13524992.0,0.0,0,0,4.068,2.927,0,0,0.0,3.789,36.042,0.0,4.012,30.844,0.067,3.35,30.472,0.0,3.139,35.836,0.0
6
+ 2026-05-19 12:55:03,0.002,29253632.0,0.0,0.43,1.0,11.531,11.373,21.108,213.155,0,0.001,12394496.0,0.0,0.076,1.0,7.224,6.633,19.646,182.581,0,0.001,15347712.0,0.0,1.943,1.0,5.466,3.593,0.288,1.98,0,0.013,82972672.0,0.02,0.356,1.0,4.672,3.883,3.47,10.439,0,0.004,51900416.0,0.006,1.027,1.0,5.493,4.603,2.858,4.724,0,0.001,31166464.0,0.0,0.069,1.0,2.876,2.15,3.481,9.034,0,0.0,12812288.0,0.0,0.18,1.0,4.048,2.852,0.416,3.999,0,0.001,89391104.0,0.0,0.064,1.0,3.939,2.763,3.178,4.921,0,0.002,87031808.0,0.0,0.254,1.0,4.731,3.599,3.192,4.946,0,0.003,161689600.0,0.0,0.128,1.0,3.585,2.433,3.702,11.593,0,0.004,13656064.0,0.0,0,0,4.068,2.927,0,0,0.0,3.789,36.042,0.0,4.012,30.844,0.067,3.339,30.609,0.0,3.154,35.836,0.0
7
+ 2026-05-19 12:55:08,0.002,29847552.0,0.0,0.491,1.0,11.472,11.223,19.778,179.516,0,0.001,12394496.0,0.0,0.066,1.0,7.224,6.633,19.293,172.253,0,0.001,15347712.0,0.0,2.242,1.0,4.924,3.237,0.291,2.264,0,0.013,82972672.0,0.02,0.401,1.0,4.672,3.883,3.427,12.955,0,0.003,51900416.0,0.005,1.133,1.0,3.739,3.334,2.858,4.711,0,0.001,31166464.0,0.0,0.078,1.0,2.876,2.15,3.423,9.27,0,0.0,12812288.0,0.0,0.248,1.0,4.066,3.015,0.417,4.302,0,0.001,89391104.0,0.0,0.072,1.0,3.939,2.763,3.2,4.96,0,0.002,87031808.0,0.0,0.319,1.0,4.619,3.654,3.256,13.545,0,0.003,161849344.0,0.0,0.142,1.0,3.088,2.095,3.58,10.093,0,0.004,13656064.0,0.0,0,0,3.872,2.671,0,0,0.0,3.536,36.046,0.0,4.012,30.844,0.067,3.292,30.609,0.0,3.154,35.836,0.0
8
+ 2026-05-19 12:55:13,0.002,29847552.0,0.0,0.538,1.0,11.472,11.223,19.627,163.636,0,0.0,12394496.0,0.0,0.074,1.0,5.42,4.309,19.046,162.253,0,0.001,15347712.0,0.0,2.425,1.0,4.382,2.881,0.288,2.005,0,0.015,83845120.0,0.028,0.445,1.0,3.917,2.912,3.383,9.985,0,0.003,52494336.0,0.004,1.238,1.0,4.906,4.375,2.854,4.703,0,0.0,31166464.0,0.0,0.09,1.0,2.295,1.716,3.432,8.828,0,0.0,12812288.0,0.0,0.265,1.0,4.066,3.015,0.407,4.092,0,0.001,89395200.0,0.0,0.08,1.0,3.939,2.763,3.176,4.917,0,0.001,87031808.0,0.0,0.333,1.0,4.101,3.384,3.169,4.905,0,0.003,161849344.0,0.0,0.195,1.0,3.286,2.311,3.476,9.575,0,0.004,13656064.0,0.0,0,0,2.982,2.057,0,0,0.0,3.536,36.046,0.0,3.744,30.962,0.0,3.292,30.609,0.0,3.117,35.596,0.0
9
+ 2026-05-19 12:55:18,0.002,29847552.0,0.0,0.556,1.0,11.472,11.223,18.693,47.303,0,0.0,12394496.0,0.0,0.082,1.0,5.42,4.309,18.86,152.253,0,0.001,15507456.0,0.0,2.427,1.0,10.636,7.639,0.28,1.303,0,0.014,83845120.0,0.023,1.453,1.0,5.182,4.469,3.356,8.741,0,0.002,52494336.0,0.0,2.913,1.0,4.906,4.375,2.874,4.771,0,0.001,31592448.0,0.0,0.126,1.0,3.267,2.661,3.326,7.51,0,0.0,12857344.0,0.0,0.29,1.0,4.399,3.188,0.396,4.031,0,0.001,89395200.0,0.0,0.22,1.0,3.133,2.475,2.723,4.804,0,0.002,87212032.0,0.0,0.333,1.0,5.92,5.799,3.02,4.636,0,0.003,161849344.0,0.0,0.2,1.0,2.905,2.115,3.438,8.876,0,0.002,13660160.0,0.0,0,0,3.811,2.91,0,0,0.0,3.536,36.046,0.0,3.744,30.962,0.0,3.35,30.638,0.0,3.186,35.596,0.0
10
+ 2026-05-19 12:55:23,0.004,30900224.0,0.0,2.239,1.0,7.79,7.505,34.29,98.629,0,0.001,13533184.0,0.0,0.294,1.0,5.42,4.309,22.63,62.092,0,0.001,15507456.0,0.0,10.366,1.0,10.636,7.639,0.329,3.427,0,0.014,83845120.0,0.023,1.588,1.0,5.182,4.469,3.329,9.459,0,0.006,54681600.0,0.007,3.111,1.0,3.866,3.447,3.225,12.072,0,0.001,31592448.0,0.0,0.133,1.0,3.267,2.661,3.821,8.945,0,0.0,12857344.0,0.0,1.053,1.0,4.632,3.343,0.399,4.096,0,0.001,89395200.0,0.0,0.242,1.0,3.133,2.475,2.852,4.759,0,0.002,87212032.0,0.0,1.371,1.0,5.92,5.799,4.296,9.914,0,0.007,163536896.0,0.006,0.2,1.0,4.089,2.959,3.347,9.245,0,0.003,13660160.0,0.0,0,0,3.811,2.91,0,0,0.0,3.917,36.067,0.0,3.744,30.962,0.0,3.503,30.638,0.0,3.186,35.596,0.0
11
+ 2026-05-19 12:55:28,0.005,30900224.0,0.0,2.457,1.0,40.443,43.186,34.721,98.225,0,0.001,13533184.0,0.0,0.324,1.0,10.163,10.801,22.541,53.533,0,0.003,17235968.0,0.0,11.364,1.0,11.377,8.348,0.329,3.429,0,0.012,83845120.0,0.02,1.622,1.0,10.491,9.906,3.294,9.051,0,0.006,54681600.0,0.008,3.111,1.0,3.457,3.082,3.235,13.077,0,0.001,32022528.0,0.0,0.133,1.0,3.267,2.661,3.719,8.766,0,0.0,12857344.0,0.0,1.149,1.0,6.449,4.299,0.396,4.068,0,0.001,89489408.0,0.0,0.264,1.0,3.133,2.475,2.838,4.743,0,0.002,87212032.0,0.0,1.501,1.0,5.901,6.174,4.303,9.889,0,0.008,163536896.0,0.008,1.07,1.0,4.31,3.263,3.32,9.901,0,0.003,13660160.0,0.0,0,0,3.811,2.91,0,0,0.0,3.917,36.067,0.0,4.342,31.051,0.067,3.503,30.638,0.0,3.26,35.642,0.0
12
+ 2026-05-19 12:55:33,0.006,30900224.0,0.0,2.622,1.0,49.02,52.751,36.0,94.516,0,0.001,13533184.0,0.0,0.354,1.0,10.163,10.801,22.381,49.259,0,0.003,17235968.0,0.0,12.044,1.0,11.377,8.348,0.332,3.448,0,0.026,86454272.0,0.073,4.177,1.0,11.447,11.332,3.079,5.588,0,0.006,54681600.0,0.008,10.957,1.0,25.654,25.154,2.371,7.276,0,0.001,32022528.0,0.0,0.524,1.0,3.267,2.661,3.347,6.825,0,0.001,13479936.0,0.0,1.178,1.0,6.031,3.925,0.397,3.957,0,0.001,89489408.0,0.0,0.575,1.0,3.761,2.71,2.94,4.646,0,0.006,87666688.0,0.0,1.556,1.0,6.225,6.513,4.377,9.651,0,0.008,163536896.0,0.008,1.17,1.0,4.31,3.263,3.289,9.079,0,0.004,13680640.0,0.0,0,0,9.161,6.278,0,0,0.0,3.917,36.067,0.0,4.342,31.051,0.067,3.693,30.712,0.0,3.203,35.642,0.0
13
+ 2026-05-19 12:55:38,0.013,31195136.0,0.0,4.905,1.0,59.409,63.931,19.293,75.252,0,0.002,13758464.0,0.0,0.692,1.0,10.163,10.801,19.247,45.503,0,0.003,17235968.0,0.0,23.141,1.0,32.511,23.858,0.295,2.427,0,0.026,86454272.0,0.073,4.584,1.0,13.256,13.123,3.065,4.912,0,0.008,54681600.0,0.011,12.018,1.0,25.654,25.154,2.586,4.838,0,0.001,32022528.0,0.0,0.574,1.0,4.52,3.918,3.194,4.949,0,0.001,13479936.0,0.0,2.702,1.0,7.363,4.793,0.334,3.481,0,0.001,89489408.0,0.0,0.634,1.0,3.937,2.837,2.962,4.641,0,0.006,87666688.0,0.0,3.247,1.0,12.506,12.765,3.388,7.537,0,0.012,164691968.0,0.012,1.2,1.0,3.668,2.777,3.17,4.907,0,0.004,13680640.0,0.0,0,0,11.57,7.883,0,0,0.0,4.007,35.805,0.133,4.342,31.051,0.067,3.844,30.712,0.0,3.203,35.642,0.0
14
+ 2026-05-19 12:55:43,0.015,31195136.0,0.0,5.403,1.0,48.113,51.775,19.278,74.951,0,0.002,13758464.0,0.0,0.761,1.0,8.625,9.6,19.231,45.058,0,0.003,17235968.0,0.0,25.446,1.0,32.511,23.858,0.295,2.42,0,0.026,86454272.0,0.073,4.889,1.0,10.666,10.559,3.041,4.869,0,0.017,57901056.0,0.008,12.733,1.0,25.654,25.154,2.581,4.843,0,0.001,31903744.0,0.0,0.6,1.0,4.52,3.918,3.162,4.892,0,0.001,13479936.0,0.0,2.965,1.0,8.769,5.481,0.334,3.472,0,0.001,89489408.0,0.0,0.694,1.0,3.937,2.837,2.959,4.636,0,0.008,87666688.0,0.0,3.562,1.0,12.506,12.765,3.388,7.522,0,0.015,164691968.0,0.015,2.236,1.0,7.192,4.654,3.131,4.836,0,0.004,13680640.0,0.0,0,0,11.57,7.883,0,0,0.0,4.007,35.805,0.133,4.807,30.948,0.0,3.844,30.712,0.0,3.094,35.611,0.0
15
+ 2026-05-19 12:55:48,0.015,31195136.0,0.0,5.901,1.0,97.482,107.747,19.256,74.431,0,0.002,13811712.0,0.0,0.822,1.0,9.557,10.637,19.218,44.693,0,0.007,17219584.0,0.0,27.689,1.0,41.909,30.751,0.294,2.378,0,0.027,87445504.0,0.066,6.989,1.0,23.312,22.727,2.95,4.818,0,0.017,57901056.0,0.008,18.778,1.0,38.318,38.051,2.159,4.706,0,0.001,31903744.0,0.0,0.885,1.0,4.52,3.918,3.137,4.886,0,0.001,13926400.0,0.0,3.156,1.0,8.769,5.481,0.334,3.473,0,0.002,89513984.0,0.0,0.93,1.0,4.909,3.382,2.931,4.622,0,0.008,87666688.0,0.0,3.778,1.0,15.902,16.401,3.388,7.429,0,0.015,164691968.0,0.015,2.455,1.0,7.192,4.654,3.128,4.831,0,0.004,13680640.0,0.0,0,0,11.57,7.883,0,0,0.0,4.007,35.805,0.133,4.807,30.948,0.0,4.107,30.537,0.0,3.085,35.611,0.0
16
+ 2026-05-19 12:55:53,0.021,31404032.0,0.0,7.705,1.0,122.314,131.535,17.888,53.351,0,0.003,13811712.0,0.0,0.987,1.0,16.579,19.712,18.592,34.277,0,0.007,17219584.0,0.0,36.778,1.0,49.902,37.019,0.286,1.868,0,0.027,87445504.0,0.066,7.678,1.0,23.312,22.727,2.939,4.767,0,0.026,57901056.0,0.012,20.636,1.0,38.318,38.051,2.202,4.657,0,0.001,31903744.0,0.0,0.968,1.0,4.067,3.647,3.094,4.805,0,0.001,13926400.0,0.0,3.988,1.0,10.736,6.474,0.326,3.325,0,0.002,89513984.0,0.0,1.025,1.0,4.909,3.382,2.934,4.617,0,0.01,87650304.0,0.0,5.05,1.0,19.793,20.414,3.228,5.145,0,0.019,164691968.0,0.02,2.622,1.0,7.192,4.654,3.09,4.761,0,0.004,13545472.0,0.0,0,0,17.964,11.471,0,0,0.0,4.09,35.827,0.0,4.807,30.948,0.0,4.424,30.537,0.0,3.085,35.611,0.0
17
+ 2026-05-19 12:55:58,0.023,31404032.0,0.0,8.493,1.0,125.125,138.837,17.878,53.195,0,0.003,13811712.0,0.0,1.085,1.0,16.579,19.712,18.583,33.922,0,0.007,17219584.0,0.0,40.476,1.0,55.52,41.186,0.286,1.863,0,0.027,87445504.0,0.066,8.267,1.0,27.658,26.988,2.927,4.745,0,0.027,59547648.0,0.01,22.289,1.0,38.318,38.051,2.199,4.658,0,0.002,32059392.0,0.0,1.0,1.0,4.531,4.062,3.076,4.773,0,0.002,13926400.0,0.0,4.373,1.0,8.993,5.423,0.326,3.317,0,0.002,89513984.0,0.0,1.119,1.0,6.068,3.886,2.932,4.614,0,0.014,87650304.0,0.0,5.54,1.0,20.872,21.358,3.228,5.14,0,0.014,164691968.0,0.015,3.506,1.0,10.936,6.668,3.079,4.742,0,0.004,13545472.0,0.0,0,0,22.762,14.535,0,0,0.0,4.09,35.827,0.0,5.414,30.889,0.0,4.424,30.537,0.0,3.085,35.588,0.0
18
+ 2026-05-19 12:56:03,0.024,31404032.0,0.0,9.279,1.0,139.341,155.85,17.865,52.831,0,0.002,13811712.0,0.0,1.178,1.0,20.057,24.604,18.539,32.321,0,0.01,17260544.0,0.0,44.144,1.0,67.415,50.01,0.286,1.822,0,0.029,87445504.0,0.068,9.895,1.0,26.386,25.746,2.899,4.724,0,0.027,59547648.0,0.01,28.485,1.0,69.353,67.5,1.949,4.59,0,0.002,32059392.0,0.0,1.171,1.0,5.561,4.985,3.068,4.777,0,0.002,14192640.0,0.0,4.622,1.0,8.099,4.884,0.325,3.292,0,0.002,89526272.0,0.0,1.148,1.0,6.068,3.886,2.943,4.599,0,0.014,87650304.0,0.0,5.889,1.0,20.872,21.358,3.226,5.091,0,0.019,166727680.0,0.012,3.849,1.0,10.936,6.668,3.078,4.74,0,0.005,13545472.0,0.0,0,0,22.762,14.535,0,0,0.0,4.09,35.827,0.0,5.414,30.889,0.0,4.622,30.643,0.0,2.993,35.588,0.0
19
+ 2026-05-19 12:56:08,0.028,31404032.0,0.0,10.476,1.0,165.315,186.471,17.44,45.15,0,0.003,14036992.0,0.0,1.325,1.0,20.057,24.604,18.312,24.961,0,0.011,17260544.0,0.0,50.758,1.0,67.415,50.01,0.284,1.705,0,0.022,88489984.0,0.044,10.725,1.0,33.904,32.855,2.89,4.705,0,0.029,60698624.0,0.015,31.17,1.0,69.353,69.004,1.817,4.537,0,0.002,32059392.0,0.0,1.278,1.0,4.453,3.993,3.052,4.75,0,0.002,14192640.0,0.0,5.174,1.0,13.434,7.842,0.322,3.252,0,0.002,89526272.0,0.0,1.222,1.0,5.524,3.65,2.956,4.615,0,0.015,87678976.0,0.0,6.786,1.0,23.003,23.054,3.162,4.892,0,0.022,166727680.0,0.009,4.111,1.0,10.936,6.668,3.058,4.704,0,0.005,13553664.0,0.0,0,0,22.484,14.183,0,0,0.0,3.84,35.825,0.0,5.414,30.889,0.0,4.697,30.643,0.0,2.993,35.588,0.0
20
+ 2026-05-19 12:56:13,0.029,31596544.0,0.0,10.822,1.0,165.315,186.471,17.02,38.403,0,0.003,14036992.0,0.0,1.333,1.0,19.65,24.518,17.991,24.383,0,0.011,17276928.0,0.0,52.258,1.0,68.807,51.443,0.28,1.258,0,0.012,88489984.0,0.0,10.733,1.0,33.904,32.855,2.837,4.618,0,0.03,60698624.0,0.01,32.222,1.0,69.353,69.004,1.76,4.488,0,0.002,32362496.0,0.0,1.289,1.0,3.99,3.577,3.004,4.666,0,0.002,14192640.0,0.0,5.2,1.0,13.434,7.842,0.315,3.069,0,0.002,89526272.0,0.0,1.222,1.0,5.524,3.65,2.945,4.589,0,0.015,87678976.0,0.0,6.822,1.0,22.521,22.54,3.056,4.7,0,0.022,166727680.0,0.009,4.578,1.0,11.987,6.983,3.028,4.65,0,0.005,13553664.0,0.0,0,0,22.484,14.183,0,0,0.0,3.84,35.825,0.0,5.318,30.842,0.067,4.697,30.643,0.0,2.939,35.53,0.0
21
+ 2026-05-19 12:56:18,0.029,31596544.0,0.0,10.822,1.0,163.16,184.573,16.432,26.409,0,0.003,14036992.0,0.0,1.333,1.0,19.65,24.518,17.703,23.865,0,0.011,17276928.0,0.0,52.267,1.0,71.096,53.593,0.275,0.495,0,0.011,89243648.0,0.0,10.867,1.0,33.629,32.327,2.815,4.574,0,0.03,60698624.0,0.01,33.133,1.0,68.531,67.953,1.449,4.313,0,0.002,32362496.0,0.0,1.267,1.0,5.468,4.917,2.97,4.594,0,0.002,14483456.0,0.0,5.2,1.0,13.097,7.629,0.312,2.991,0,0.002,89522176.0,0.0,1.267,1.0,5.663,3.833,2.945,4.589,0,0.015,87678976.0,0.0,6.822,1.0,19.419,19.396,3.007,4.612,0,0.022,166727680.0,0.009,4.578,1.0,11.959,6.951,3.0,4.6,0,0.005,13553664.0,0.0,0,0,22.634,14.044,0,0,0.0,3.84,35.825,0.0,5.318,30.842,0.067,4.672,30.563,0.0,3.019,35.53,0.0
22
+ 2026-05-19 12:56:23,0.03,31596544.0,0.0,10.978,1.0,163.16,184.573,16.122,24.923,0,0.003,14082048.0,0.0,1.222,1.0,19.65,24.518,17.5,23.5,0,0.011,17276928.0,0.0,51.444,1.0,69.537,52.301,0.275,0.496,0,0.011,89243648.0,0.0,10.867,1.0,33.629,32.327,2.81,4.562,0,0.02,60698624.0,0.011,33.133,1.0,68.531,67.953,1.19,4.262,0,0.002,32362496.0,0.0,1.267,1.0,5.468,4.917,2.967,4.593,0,0.002,14483456.0,0.0,4.889,1.0,13.097,7.629,0.306,2.815,0,0.002,89522176.0,0.0,1.267,1.0,5.56,3.647,2.945,4.589,0,0.014,87691264.0,0.0,6.778,1.0,22.996,22.969,3.007,4.612,0,0.018,167411712.0,0.002,4.578,1.0,12.277,7.175,3.0,4.6,0,0.005,13557760.0,0.0,0,0,18.2,11.292,0,0,0.0,3.806,35.713,0.0,5.318,30.842,0.067,4.706,30.563,0.0,3.019,35.53,0.0
23
+ 2026-05-19 12:56:28,0.03,31596544.0,0.0,10.978,1.0,165.207,187.704,16.122,24.923,0,0.003,14082048.0,0.0,1.222,1.0,13.632,17.243,17.5,23.5,0,0.008,17276928.0,0.0,51.444,1.0,69.537,52.301,0.275,0.496,0,0.011,89243648.0,0.0,10.867,1.0,34.945,33.586,2.81,4.562,0,0.022,60698624.0,0.012,33.133,1.0,68.531,67.953,1.117,4.248,0,0.002,32362496.0,0.0,1.267,1.0,5.468,4.917,2.964,4.593,0,0.002,14483456.0,0.0,4.889,1.0,12.871,7.612,0.306,2.815,0,0.002,89546752.0,0.0,1.267,1.0,5.56,3.647,2.945,4.589,0,0.014,87691264.0,0.0,6.778,1.0,18.611,18.589,3.007,4.612,0,0.018,167411712.0,0.002,4.689,1.0,12.277,7.175,3.0,4.6,0,0.005,13557760.0,0.0,0,0,16.314,10.122,0,0,0.0,3.806,35.713,0.0,5.3,30.991,0.0,4.706,30.563,0.0,3.1,35.629,0.0
24
+ 2026-05-19 12:56:33,0.029,31752192.0,0.0,10.978,1.0,162.957,186.495,16.122,24.923,0,0.003,14135296.0,0.0,1.222,1.0,15.847,20.227,17.5,23.5,0,0.011,17465344.0,0.0,51.444,1.0,69.537,52.301,0.275,0.496,0,0.01,90054656.0,0.0,10.822,1.0,26.152,25.135,2.807,4.561,0,0.027,62373888.0,0.008,34.0,1.0,43.565,42.446,0.49,4.209,0,0.002,32616448.0,0.0,1.267,1.0,5.468,4.917,2.982,4.596,0,0.002,14512128.0,0.0,4.889,1.0,12.871,7.612,0.306,2.815,0,0.002,89546752.0,0.0,1.2,1.0,4.881,3.214,2.982,4.596,0,0.012,87711744.0,0.0,6.778,1.0,22.929,22.893,3.007,4.612,0,0.018,167411712.0,0.002,4.689,1.0,12.277,7.175,3.0,4.6,0,0.005,13557760.0,0.0,0,0,22.261,13.769,0,0,0.0,3.806,35.713,0.0,5.3,30.991,0.0,4.668,30.642,0.0,3.032,35.629,0.0
25
+ 2026-05-19 12:56:38,0.029,31752192.0,0.0,10.533,1.0,162.957,186.495,16.351,24.928,0,0.003,24576000.0,0.0,1.356,1.0,19.34,24.686,17.5,23.5,0,0.011,17465344.0,0.0,50.489,1.0,69.532,52.227,0.276,0.498,0,0.01,90054656.0,0.0,10.822,1.0,23.24,22.336,2.804,4.561,0,0.027,62373888.0,0.008,34.0,1.0,49.061,47.801,0.473,4.169,0,0.002,32616448.0,0.0,1.267,1.0,5.62,5.051,2.982,4.596,0,0.002,14512128.0,0.0,4.889,1.0,12.871,7.612,0.307,2.835,0,0.002,89546752.0,0.0,1.2,1.0,5.49,3.673,2.982,4.596,0,0.014,87711744.0,0.0,6.778,1.0,22.756,22.711,3.007,4.612,0,0.013,168112128.0,0.004,4.689,1.0,12.496,7.333,3.005,4.608,0,0.004,13557760.0,0.0,0,0,22.261,13.769,0,0,0.0,3.861,35.677,0.0,5.3,30.991,0.0,4.588,30.642,0.0,3.032,35.629,0.0
26
+ 2026-05-19 12:56:43,0.029,31752192.0,0.0,10.533,1.0,162.957,186.495,16.351,24.928,0,0.003,24576000.0,0.0,1.356,1.0,19.34,24.686,17.5,23.5,0,0.011,17465344.0,0.0,50.489,1.0,69.532,52.227,0.276,0.497,0,0.01,90054656.0,0.0,10.822,1.0,33.693,32.266,2.804,4.561,0,0.027,62373888.0,0.009,34.0,1.0,54.557,53.156,0.462,4.145,0,0.002,32616448.0,0.0,1.267,1.0,5.62,5.051,2.982,4.596,0,0.002,14512128.0,0.0,4.889,1.0,9.581,5.583,0.307,2.835,0,0.002,89538560.0,0.0,1.2,1.0,5.49,3.673,2.982,4.596,0,0.014,87711744.0,0.0,6.778,1.0,23.078,22.903,3.007,4.612,0,0.017,168112128.0,0.005,4.689,1.0,12.424,7.272,3.005,4.608,0,0.003,13557760.0,0.0,0,0,22.261,13.769,0,0,0.0,3.861,35.677,0.0,5.613,31.286,0.0,4.588,30.642,0.0,2.993,35.685,0.0
27
+ 2026-05-19 12:56:48,0.029,31813632.0,0.0,10.533,1.0,158.245,182.179,16.351,24.928,0,0.002,24576000.0,0.0,1.356,1.0,27.643,32.254,17.5,23.5,0,0.011,17412096.0,0.0,50.489,1.0,69.532,52.227,0.276,0.497,0,0.007,90976256.0,0.0,10.511,1.0,32.796,31.32,2.807,4.561,0,0.027,62373888.0,0.009,33.4,1.0,55.574,54.148,0.439,4.076,0,0.002,33009664.0,0.0,1.356,1.0,5.62,5.051,3.0,4.6,0,0.002,14512128.0,0.0,4.889,1.0,12.663,7.379,0.307,2.835,0,0.002,89538560.0,0.0,1.311,1.0,6.035,3.93,3.0,4.6,0,0.014,87707648.0,0.0,6.778,1.0,22.69,22.475,3.007,4.612,0,0.017,168112128.0,0.005,4.689,1.0,12.424,7.272,3.005,4.608,0,0.005,13561856.0,0.0,0,0,22.488,14.046,0,0,0.0,3.861,35.677,0.0,5.613,31.286,0.0,4.635,30.525,0.0,3.107,35.685,0.0
28
+ 2026-05-19 12:56:53,0.028,31813632.0,0.0,10.222,1.0,159.834,183.324,16.265,24.68,0,0.02,45592576.0,0.134,1.153,1.0,26.046,29.362,17.785,24.013,0,0.011,17412096.0,0.0,47.222,1.0,56.975,42.841,0.276,0.497,0,0.009,90976256.0,0.0,10.511,1.0,32.796,31.32,2.803,4.561,0,0.021,62373888.0,0.007,33.4,1.0,50.078,48.793,0.417,4.001,0,0.002,33009664.0,0.0,1.356,1.0,4.701,4.223,3.0,4.6,0,0.002,14774272.0,0.0,4.8,1.0,12.663,7.379,0.298,2.533,0,0.002,89538560.0,0.0,1.311,1.0,6.035,3.93,3.0,4.6,0,0.013,87707648.0,0.0,6.578,1.0,22.69,22.475,3.003,4.606,0,0.017,168112128.0,0.005,4.689,1.0,12.481,7.459,3.005,4.608,0,0.005,13561856.0,0.0,0,0,22.717,14.287,0,0,0.0,3.985,35.599,0.0,5.613,31.286,0.0,4.724,30.525,0.0,3.107,35.685,0.0
29
+ 2026-05-19 12:56:58,0.028,31813632.0,0.0,10.222,1.0,159.834,183.324,16.265,24.68,0,0.025,45592576.0,0.172,1.039,1.0,27.15,29.736,17.8,24.04,0,0.011,17412096.0,0.0,47.222,1.0,66.145,49.736,0.276,0.496,0,0.009,90976256.0,0.0,10.511,1.0,32.83,31.431,2.8,4.56,0,0.023,62373888.0,0.0,33.4,1.0,44.582,43.438,0.414,3.991,0,0.003,33009664.0,0.0,1.356,1.0,6.165,5.468,3.0,4.6,0,0.002,14774272.0,0.0,4.8,1.0,12.769,7.596,0.297,2.456,0,0.002,89542656.0,0.0,1.311,1.0,6.421,4.365,3.0,4.6,0,0.013,87707648.0,0.0,6.578,1.0,23.36,23.076,3.003,4.606,0,0.013,168112128.0,0.004,4.756,1.0,12.767,7.743,3.009,4.617,0,0.005,13561856.0,0.0,0,0,22.781,14.274,0,0,0.0,3.985,35.599,0.0,6.218,31.038,0.0,4.724,30.525,0.0,3.172,35.729,0.0
30
+ 2026-05-19 12:57:03,0.027,32022528.0,0.0,10.222,1.0,160.721,184.738,16.265,24.68,0,0.03,45592576.0,0.211,0.926,1.0,22.522,24.88,17.817,24.07,0,0.011,17510400.0,0.0,47.222,1.0,66.145,49.736,0.276,0.496,0,0.007,90976256.0,0.0,10.133,1.0,32.83,31.431,2.798,4.56,0,0.021,65204224.0,0.0,32.956,1.0,65.013,62.629,0.407,3.965,0,0.002,33169408.0,0.0,1.133,1.0,6.165,5.468,3.0,4.6,0,0.002,14905344.0,0.0,4.8,1.0,12.769,7.596,0.295,2.369,0,0.002,89542656.0,0.0,1.089,1.0,6.421,4.365,3.0,4.6,0,0.013,87707648.0,0.0,6.578,1.0,18.342,18.119,3.003,4.606,0,0.017,168775680.0,0.012,4.756,1.0,12.767,7.743,3.009,4.617,0,0.005,13553664.0,0.0,0,0,22.781,14.274,0,0,0.0,3.985,35.599,0.0,6.218,31.038,0.0,4.722,30.588,0.0,3.163,35.729,0.0
31
+ 2026-05-19 12:57:08,0.027,32022528.0,0.0,9.311,1.0,160.721,184.738,16.432,24.876,0,0.035,45592576.0,0.249,0.911,1.0,23.812,26.528,19.274,2422.107,0,0.011,17510400.0,0.0,43.911,1.0,53.1,39.928,0.276,0.496,0,0.008,91967488.0,0.0,10.133,1.0,21.445,20.618,2.789,4.558,0,0.019,65204224.0,0.0,32.956,1.0,65.013,62.629,0.403,3.956,0,0.002,33169408.0,0.0,1.133,1.0,6.165,5.468,3.0,4.6,0,0.002,14905344.0,0.0,4.2,1.0,13.231,7.785,0.301,2.648,0,0.002,89542656.0,0.0,1.089,1.0,6.906,4.868,3.0,4.6,0,0.012,87728128.0,0.0,5.978,1.0,22.325,21.781,3.011,4.62,0,0.017,168775680.0,0.012,4.756,1.0,12.767,7.743,3.014,4.626,0,0.005,13553664.0,0.0,0,0,17.819,11.232,0,0,0.0,4.05,35.584,0.0,6.218,31.038,0.0,4.651,30.588,0.0,3.163,35.729,0.0
32
+ 2026-05-19 12:57:13,0.027,32022528.0,0.0,9.311,1.0,151.874,174.124,16.432,24.876,0,0.028,45592576.0,0.196,1.148,1.0,15.923,15.784,21.687,4494.629,0,0.009,17510400.0,0.0,43.911,1.0,47.977,36.176,0.276,0.497,0,0.008,91967488.0,0.0,10.133,1.0,24.186,23.252,2.798,4.563,0,0.019,65204224.0,0.0,32.956,1.0,65.013,62.629,0.406,3.968,0,0.002,32907264.0,0.0,1.133,1.0,5.623,5.049,3.0,4.6,0,0.002,14905344.0,0.0,4.2,1.0,10.969,6.454,0.326,3.29,0,0.002,89546752.0,0.0,1.089,1.0,6.267,4.41,3.0,4.6,0,0.012,87728128.0,0.0,5.978,1.0,22.096,21.314,3.011,4.62,0,0.016,170971136.0,0.012,4.6,1.0,10.057,6.099,3.015,4.627,0,0.005,13553664.0,0.0,0,0,18.333,11.514,0,0,0.0,4.05,35.584,0.0,6.91,31.164,0.0,4.651,30.588,0.0,3.161,35.368,0.0
33
+ 2026-05-19 12:57:18,0.027,32022528.0,0.0,9.311,1.0,148.846,169.718,16.432,24.876,0,0.027,45592576.0,0.196,1.098,1.0,16.376,17.185,22.701,4801.94,0,0.009,17510400.0,0.0,43.911,1.0,63.792,47.939,0.276,0.497,0,0.008,91967488.0,0.0,9.778,1.0,24.888,23.985,2.814,4.566,0,0.019,64671744.0,0.009,32.4,1.0,64.13,61.614,0.405,3.97,0,0.002,32907264.0,0.0,1.067,1.0,5.363,4.815,2.979,4.596,0,0.001,14905344.0,0.0,4.2,1.0,9.867,5.805,0.331,3.359,0,0.002,89546752.0,0.0,1.022,1.0,6.267,4.41,2.979,4.596,0,0.012,87728128.0,0.0,5.978,1.0,22.096,21.314,3.011,4.62,0,0.016,170971136.0,0.012,4.6,1.0,12.051,7.403,3.015,4.627,0,0.005,13553664.0,0.0,0,0,21.432,13.459,0,0,0.0,4.05,35.584,0.0,6.91,31.164,0.0,4.586,30.632,0.067,3.219,35.368,0.0
34
+ 2026-05-19 12:57:23,0.026,32415744.0,0.0,9.422,1.0,148.846,169.718,16.425,37.25,0,0.118,51617792.0,1.056,0.521,1.0,18.197,19.098,3673.41,8370.945,0,0.01,17395712.0,0.0,42.4,1.0,60.934,45.971,0.276,0.498,0,0.008,91967488.0,0.0,9.778,1.0,30.7,29.585,2.803,4.564,0,0.019,64671744.0,0.009,32.4,1.0,64.13,61.614,0.402,3.96,0,0.002,32907264.0,0.0,1.067,1.0,5.363,4.815,2.973,4.595,0,0.002,14950400.0,0.0,4.0,1.0,12.265,7.315,0.324,3.245,0,0.002,89546752.0,0.0,1.022,1.0,6.046,4.319,2.973,4.595,0,0.012,87744512.0,0.0,5.6,1.0,22.096,21.314,3.027,4.649,0,0.016,170971136.0,0.014,4.6,1.0,12.051,7.403,3.01,4.618,0,0.003,13557760.0,0.0,0,0,21.042,13.205,0,0,0.0,3.937,35.562,0.467,6.91,31.164,0.0,4.571,30.632,0.067,3.219,35.368,0.0
35
+ 2026-05-19 12:57:28,0.026,32415744.0,0.0,9.422,1.0,148.846,169.718,16.425,37.25,0,0.13,51617792.0,1.167,0.62,1.0,20.018,21.012,3925.271,8530.811,0,0.01,17395712.0,0.0,42.4,1.0,59.345,44.482,0.277,0.499,0,0.008,93409280.0,0.0,9.778,1.0,30.7,29.585,2.805,4.564,0,0.019,64671744.0,0.009,32.4,1.0,64.13,61.614,0.403,3.963,0,0.002,32710656.0,0.0,1.067,1.0,5.294,4.729,2.974,4.595,0,0.002,14950400.0,0.0,4.0,1.0,11.845,7.248,0.325,3.261,0,0.002,89546752.0,0.0,1.022,1.0,5.675,3.97,2.974,4.595,0,0.012,87744512.0,0.0,5.6,1.0,21.387,20.886,3.027,4.649,0,0.015,168955904.0,0.01,4.4,1.0,12.051,7.403,3.01,4.619,0,0.005,13557760.0,0.0,0,0,21.042,13.205,0,0,0.0,3.937,35.562,0.467,7.306,30.968,0.4,4.571,30.632,0.067,3.281,35.395,0.0
36
+ 2026-05-19 12:57:33,0.024,32415744.0,0.0,9.422,1.0,135.322,154.265,16.425,37.25,0,0.142,51617792.0,1.278,0.7,1.0,20.537,22.846,3973.642,8554.584,0,0.01,17395712.0,0.0,42.4,1.0,59.345,44.482,0.277,0.499,0,0.008,93409280.0,0.0,9.111,1.0,28.904,27.936,2.833,4.57,0,0.014,64671744.0,0.018,29.889,1.0,38.743,36.725,0.411,3.997,0,0.001,32710656.0,0.0,0.911,1.0,5.294,4.729,2.973,4.595,0,0.001,14999552.0,0.0,4.0,1.0,11.845,7.248,0.331,3.362,0,0.002,44896256.0,0.0,1.044,1.0,5.675,3.97,2.972,4.594,0,0.011,87744512.0,0.0,5.6,1.0,20.574,20.106,3.027,4.649,0,0.015,168955904.0,0.01,4.4,1.0,11.409,6.951,3.01,4.619,0,0.005,13557760.0,0.0,0,0,20.157,12.534,0,0,0.0,3.937,35.562,0.467,7.306,30.968,0.4,4.478,30.595,0.0,3.206,35.395,0.0
37
+ 2026-05-19 12:57:38,0.024,32534528.0,0.0,8.822,1.0,135.94,155.964,16.716,3027.778,0,0.168,35794944.0,1.544,0.781,1.0,16.931,20.739,4926.398,9071.355,0,0.01,8634368.0,0.0,41.689,1.0,58.618,43.567,0.277,0.499,0,0.007,94085120.0,0.0,9.111,1.0,28.904,27.936,2.833,4.57,0,0.014,64028672.0,0.009,29.889,1.0,43.493,41.227,0.414,4.009,0,0.001,32710656.0,0.0,0.911,1.0,4.752,4.309,2.974,4.595,0,0.001,14999552.0,0.0,4.111,1.0,11.845,7.248,0.341,3.498,0,0.002,44896256.0,0.0,1.044,1.0,4.04,2.745,2.974,4.595,0,0.011,87781376.0,0.0,5.511,1.0,20.574,20.106,3.049,4.689,0,0.008,83501056.0,0.004,4.4,1.0,10.882,6.549,3.01,4.619,0,0.004,13561856.0,0.0,0,0,19.874,12.328,0,0,0.0,3.843,35.562,0.067,7.306,30.968,0.4,4.358,30.595,0.0,3.206,35.395,0.0
38
+ 2026-05-19 12:57:43,0.024,32534528.0,0.0,8.822,1.0,135.94,155.964,16.716,3027.778,0,0.185,35794944.0,1.7,1.052,1.0,16.931,20.739,5148.125,9180.946,0,0.007,8634368.0,0.0,41.689,1.0,57.008,42.425,0.278,1.01,0,0.007,45207552.0,0.0,9.111,1.0,26.603,25.809,2.836,4.57,0,0.018,28450816.0,0.012,29.889,1.0,49.319,46.816,0.416,4.016,0,0.001,33464320.0,0.0,0.911,1.0,3.97,3.599,2.976,4.595,0,0.001,14999552.0,0.0,4.111,1.0,10.616,6.27,0.356,3.659,0,0.002,44896256.0,0.0,1.044,1.0,4.954,3.367,2.976,4.595,0,0.011,87781376.0,0.0,5.511,1.0,14.304,14.173,3.049,4.689,0,0.01,83746816.0,0.003,4.022,1.0,10.882,6.549,3.005,4.61,0,0.004,6774784.0,0.0,0,0,19.874,12.328,0,0,0.0,3.843,35.562,0.067,7.403,30.879,0.067,4.358,30.595,0.0,3.112,35.352,0.0
39
+ 2026-05-19 12:57:48,0.024,22274048.0,0.0,8.822,1.0,135.94,155.964,16.716,3027.778,0,0.19,27316224.0,1.726,1.148,1.0,13.742,18.467,5145.571,9180.29,0,0.009,8785920.0,0.0,41.689,1.0,57.008,42.425,0.278,1.031,0,0.006,45207552.0,0.0,9.444,1.0,27.889,27.121,2.815,4.57,0,0.018,28450816.0,0.012,31.267,1.0,59.257,56.248,0.416,4.017,0,0.002,33464320.0,0.0,1.156,1.0,4.813,4.334,2.96,4.592,0,0.001,15040512.0,0.0,4.111,1.0,10.616,6.27,0.364,3.72,0,0.002,44929024.0,0.0,1.156,1.0,4.954,3.367,2.961,4.592,0,0.009,87781376.0,0.0,5.511,1.0,15.93,15.784,3.049,4.689,0,0.013,83746816.0,0.004,4.022,1.0,11.24,6.763,3.005,4.61,0,0.004,6774784.0,0.0,0,0,16.214,10.073,0,0,0.0,3.843,35.562,0.067,7.403,30.879,0.067,4.403,30.543,0.0,3.069,35.352,0.0
40
+ 2026-05-19 12:57:53,0.025,10858496.0,0.0,9.667,1.0,140.123,162.024,16.643,2705.882,0,0.111,27316224.0,0.991,1.156,1.0,16.763,22.527,5157.802,9179.181,0,0.009,8785920.0,0.0,44.422,1.0,40.745,30.141,0.278,0.5,0,0.008,45207552.0,0.0,9.444,1.0,27.889,27.121,2.82,4.572,0,0.018,29085696.0,0.008,31.267,1.0,59.257,56.248,0.404,3.962,0,0.002,16596992.0,0.0,1.156,1.0,4.813,4.334,2.962,4.592,0,0.001,7266304.0,0.0,4.156,1.0,10.616,6.27,0.36,3.693,0,0.002,44929024.0,0.0,1.156,1.0,4.772,3.27,2.962,4.592,0,0.012,43794432.0,0.0,5.756,1.0,19.509,19.331,3.043,4.678,0,0.013,83746816.0,0.004,4.022,1.0,7.796,4.646,3.0,4.6,0,0.004,6774784.0,0.0,0,0,19.723,12.214,0,0,0.0,3.778,35.585,0.0,7.403,30.879,0.067,4.507,30.543,0.0,3.069,35.352,0.0
41
+ 2026-05-19 12:57:58,0.025,10858496.0,0.0,9.667,1.0,140.123,162.024,16.643,2705.882,0,0.126,27316224.0,1.124,1.089,1.0,16.763,22.527,4864.865,9130.435,0,0.009,8785920.0,0.0,44.422,1.0,34.1,25.225,0.278,0.5,0,0.006,45207552.0,0.0,9.444,1.0,27.676,27.006,2.817,4.572,0,0.018,29085696.0,0.008,31.267,1.0,61.636,58.574,0.403,3.958,0,0.002,16596992.0,0.0,1.156,1.0,4.948,4.275,2.96,4.592,0,0.001,7266304.0,0.0,4.156,1.0,7.178,4.033,0.347,3.573,0,0.002,44929024.0,0.0,1.156,1.0,4.822,3.286,2.96,4.592,0,0.012,43794432.0,0.0,5.756,1.0,20.023,19.874,3.043,4.678,0,0.011,83746816.0,0.003,4.333,1.0,8.699,5.184,2.996,4.599,0,0.004,6774784.0,0.0,0,0,20.233,12.515,0,0,0.0,3.778,35.585,0.0,7.353,30.953,0.067,4.507,30.543,0.0,3.043,35.447,0.0
42
+ 2026-05-19 12:58:03,0.021,10858496.0,0.0,9.667,1.0,140.123,162.024,16.643,2705.882,0,0.145,47362048.0,1.305,1.089,1.0,14.341,19.273,4864.865,9130.435,0,0.01,8790016.0,0.0,44.422,1.0,57.272,42.544,0.278,0.5,0,0.005,45207552.0,0.0,9.622,1.0,29.871,28.912,2.81,4.57,0,0.017,29085696.0,0.0,32.378,1.0,61.102,57.804,0.395,3.914,0,0.002,16596992.0,0.0,1.067,1.0,4.948,4.275,2.979,4.596,0,0.001,7270400.0,0.0,4.156,1.0,10.231,5.843,0.347,3.573,0,0.002,44941312.0,0.0,1.111,1.0,4.822,3.286,2.979,4.596,0,0.012,43794432.0,0.0,5.756,1.0,20.023,19.874,3.043,4.678,0,0.014,84213760.0,0.006,4.333,1.0,8.658,5.16,2.995,4.599,0,0.004,6774784.0,0.0,0,0,20.233,12.515,0,0,0.0,3.778,35.585,0.0,7.353,30.953,0.067,4.567,30.674,0.0,2.988,35.447,0.0
43
+ 2026-05-19 12:58:08,0.025,10858496.0,0.0,9.333,1.0,142.783,164.763,16.295,937.5,0,0.161,47362048.0,1.444,1.089,1.0,16.573,22.989,4628.378,9062.5,0,0.01,8790016.0,0.0,43.578,1.0,57.272,42.544,0.277,0.499,0,0.008,46940160.0,0.0,9.622,1.0,29.871,28.912,2.81,4.57,0,0.017,29212672.0,0.0,32.378,1.0,59.747,56.171,0.391,3.892,0,0.001,16596992.0,0.0,1.067,1.0,4.948,4.275,2.979,4.596,0,0.002,7270400.0,0.0,4.178,1.0,10.231,5.843,0.349,3.594,0,0.002,44941312.0,0.0,1.111,1.0,4.853,3.34,2.979,4.596,0,0.012,43810816.0,0.0,5.933,1.0,15.982,15.748,3.027,4.649,0,0.014,84213760.0,0.006,4.333,1.0,11.259,6.603,2.995,4.599,0,0.004,6774784.0,0.0,0,0,16.934,10.474,0,0,0.0,3.85,35.578,0.067,7.353,30.953,0.067,4.525,30.674,0.0,2.988,35.447,0.0
44
+ 2026-05-19 12:58:13,0.02,10858496.0,0.0,9.333,1.0,105.777,122.159,16.295,937.5,0,0.16,47362048.0,1.443,1.133,1.0,16.573,22.989,5000.0,9266.667,0,0.01,8790016.0,0.0,43.578,1.0,57.272,42.544,0.277,0.499,0,0.008,46940160.0,0.0,9.622,1.0,29.871,28.912,2.811,4.57,0,0.017,29212672.0,0.0,32.378,1.0,59.747,56.171,0.393,3.901,0,0.002,16658432.0,0.0,1.067,1.0,4.86,4.157,2.979,4.596,0,0.002,7270400.0,0.0,4.178,1.0,10.231,5.843,0.361,3.703,0,0.002,44941312.0,0.0,1.111,1.0,4.796,3.347,2.979,4.596,0,0.012,43810816.0,0.0,5.933,1.0,19.952,19.821,3.027,4.649,0,0.013,84287488.0,0.006,4.378,1.0,11.259,6.603,2.984,4.597,0,0.003,6774784.0,0.0,0,0,20.151,12.394,0,0,0.0,3.85,35.578,0.067,7.251,31.03,0.0,4.525,30.674,0.0,2.917,35.424,0.0
45
+ 2026-05-19 12:58:18,0.018,10858496.0,0.0,9.333,1.0,118.144,136.442,16.295,937.5,0,0.19,29798400.0,1.729,1.133,1.0,16.496,23.142,5000.0,9266.667,0,0.01,8790016.0,0.0,43.578,1.0,58.628,43.568,0.277,0.499,0,0.008,46940160.0,0.0,9.778,1.0,32.345,31.228,2.802,4.568,0,0.017,29212672.0,0.0,31.867,1.0,63.344,59.725,0.394,3.908,0,0.002,16658432.0,0.0,1.244,1.0,5.238,4.219,2.981,4.596,0,0.002,7188480.0,0.0,4.178,1.0,10.288,6.006,0.361,3.703,0,0.002,44941312.0,0.0,1.178,1.0,5.188,3.578,2.981,4.596,0,0.012,43810816.0,0.0,5.933,1.0,19.952,19.821,3.027,4.649,0,0.013,84287488.0,0.006,4.378,1.0,11.331,6.663,2.982,4.596,0,0.005,6778880.0,0.0,0,0,20.151,12.394,0,0,0.0,3.85,35.578,0.067,7.251,31.03,0.0,4.457,30.612,0.0,2.96,35.424,0.0
46
+ 2026-05-19 12:58:23,0.025,11079680.0,0.0,9.956,1.0,148.415,171.401,16.303,1450.0,0,0.187,29798400.0,1.663,1.133,1.0,16.496,23.142,4798.387,9211.111,0,0.007,8802304.0,0.0,44.933,1.0,58.628,43.568,0.275,0.495,0,0.008,46940160.0,0.0,9.778,1.0,30.36,29.474,2.801,4.568,0,0.017,29593600.0,0.0,31.867,1.0,53.896,50.817,0.391,3.893,0,0.002,17547264.0,0.0,1.244,1.0,5.238,4.219,2.981,4.596,0,0.002,7188480.0,0.0,4.2,1.0,10.569,6.28,0.353,3.632,0,0.002,44929024.0,0.0,1.178,1.0,5.188,3.578,2.981,4.596,0,0.01,43810816.0,0.0,5.956,1.0,19.952,19.821,3.011,4.62,0,0.013,84287488.0,0.006,4.378,1.0,11.331,6.663,2.98,4.596,0,0.005,6778880.0,0.0,0,0,20.508,12.616,0,0,0.0,3.856,35.565,0.467,7.251,31.03,0.0,4.458,30.612,0.0,2.96,35.424,0.0
47
+ 2026-05-19 12:58:28,0.025,11079680.0,0.0,9.956,1.0,147.916,171.179,16.303,1450.0,0,0.187,29798400.0,1.663,1.022,1.0,16.403,23.103,4241.071,8987.179,0,0.008,8802304.0,0.0,44.933,1.0,60.96,45.22,0.275,0.495,0,0.008,46940160.0,0.0,9.778,1.0,30.36,29.474,2.799,4.568,0,0.017,29593600.0,0.0,31.867,1.0,62.729,59.267,0.39,3.886,0,0.002,17547264.0,0.0,1.244,1.0,5.438,4.121,2.98,4.596,0,0.002,7188480.0,0.0,4.2,1.0,10.569,6.28,0.334,3.404,0,0.002,44929024.0,0.0,1.178,1.0,5.147,3.566,2.981,4.596,0,0.009,43810816.0,0.0,5.956,1.0,20.45,20.482,3.011,4.62,0,0.015,84484096.0,0.008,4.511,1.0,11.331,6.663,2.979,4.596,0,0.005,6778880.0,0.0,0,0,20.589,12.731,0,0,0.0,3.856,35.565,0.467,7.131,30.979,0.467,4.458,30.612,0.0,3.043,35.448,0.0
48
+ 2026-05-19 12:58:33,0.025,11079680.0,0.0,9.956,1.0,147.916,171.179,16.303,1450.0,0,0.153,29798400.0,1.362,1.022,1.0,16.044,22.832,4241.071,8987.179,0,0.01,8802304.0,0.0,44.933,1.0,59.66,44.415,0.275,0.495,0,0.008,46940160.0,0.0,9.156,1.0,30.161,29.206,2.801,4.569,0,0.017,29593600.0,0.0,30.378,1.0,61.952,58.411,0.386,3.865,0,0.002,17547264.0,0.0,1.0,1.0,5.399,4.185,2.956,4.591,0,0.001,7188480.0,0.0,4.2,1.0,10.508,6.284,0.334,3.404,0,0.002,44929024.0,0.0,0.933,1.0,4.38,3.034,2.978,4.596,0,0.008,43810816.0,0.0,5.956,1.0,19.445,19.425,3.011,4.62,0,0.015,84484096.0,0.008,4.511,1.0,10.947,6.371,2.977,4.595,0,0.005,6778880.0,0.0,0,0,20.589,12.731,0,0,0.0,3.856,35.565,0.467,7.131,30.979,0.467,4.364,30.617,0.0,3.022,35.448,0.0
49
+ 2026-05-19 12:58:38,0.024,11014144.0,0.0,9.089,1.0,147.669,170.589,15.93,27.5,0,0.148,29798400.0,1.367,1.022,1.0,14.783,20.058,4488.636,9092.105,0,0.009,8683520.0,0.0,41.933,1.0,59.66,44.415,0.275,0.496,0,0.007,47267840.0,0.0,9.156,1.0,28.646,27.719,2.798,4.568,0,0.016,29765632.0,0.0,30.378,1.0,61.952,58.411,0.383,3.845,0,0.002,17547264.0,0.0,1.0,1.0,5.399,4.185,2.956,4.591,0,0.001,7196672.0,0.0,3.889,1.0,10.508,6.284,0.35,3.598,0,0.002,44929024.0,0.0,0.933,1.0,4.581,3.238,2.978,4.596,0,0.011,43847680.0,0.0,5.622,1.0,19.445,19.425,3.008,4.614,0,0.015,84484096.0,0.008,4.511,1.0,11.143,6.51,2.974,4.595,0,0.005,6778880.0,0.0,0,0,19.415,11.977,0,0,0.0,3.896,35.587,0.067,7.131,30.979,0.467,4.212,30.617,0.0,3.022,35.448,0.0
50
+ 2026-05-19 12:58:43,0.024,11014144.0,0.0,9.089,1.0,138.471,160.04,15.93,27.5,0,0.182,48771072.0,1.649,0.978,1.0,14.783,20.058,5639.535,9500.0,0,0.009,8683520.0,0.0,41.933,1.0,58.085,43.172,0.276,0.497,0,0.007,47267840.0,0.0,9.156,1.0,28.646,27.719,2.798,4.568,0,0.016,29765632.0,0.0,30.378,1.0,56.579,53.484,0.384,3.852,0,0.002,17547264.0,0.0,1.0,1.0,5.399,4.185,2.954,4.591,0,0.001,7196672.0,0.0,3.889,1.0,8.095,4.942,0.354,3.64,0,0.002,44929024.0,0.0,0.933,1.0,4.581,3.238,2.976,4.595,0,0.011,43847680.0,0.0,5.622,1.0,18.767,18.767,3.008,4.614,0,0.009,84566016.0,0.001,4.089,1.0,11.143,6.51,2.974,4.595,0,0.005,6778880.0,0.0,0,0,19.415,11.977,0,0,0.0,3.896,35.587,0.067,7.047,31.187,0.067,4.212,30.617,0.0,2.965,35.467,0.0
51
+ 2026-05-19 12:58:48,0.024,11014144.0,0.0,9.089,1.0,138.471,160.04,15.93,27.5,0,0.177,48771072.0,1.599,0.978,1.0,11.676,15.293,5639.535,9500.0,0,0.009,8683520.0,0.0,41.933,1.0,58.085,43.172,0.276,0.497,0,0.007,47267840.0,0.0,8.711,1.0,25.955,25.311,2.82,4.573,0,0.016,30011392.0,0.0,28.289,1.0,56.579,53.484,0.393,3.903,0,0.002,17686528.0,0.0,1.022,1.0,5.172,4.174,2.955,4.591,0,0.001,7196672.0,0.0,3.889,1.0,9.905,6.046,0.354,3.64,0,0.002,44929024.0,0.0,1.133,1.0,4.581,3.238,2.977,4.595,0,0.011,43847680.0,0.0,5.622,1.0,18.735,18.694,3.008,4.614,0,0.011,84566016.0,0.001,4.089,1.0,10.698,6.323,2.973,4.595,0,0.005,6901760.0,0.0,0,0,19.415,11.977,0,0,0.0,3.896,35.587,0.067,7.047,31.187,0.067,4.156,30.647,0.0,3.0,35.467,0.0
52
+ 2026-05-19 12:58:53,0.015,11325440.0,0.0,8.8,1.0,132.818,154.055,16.548,2593.75,0,0.177,48771072.0,1.599,0.978,1.0,14.117,18.49,6300.0,9980.0,0,0.009,8818688.0,0.0,40.889,1.0,56.058,41.57,0.279,1.099,0,0.007,47267840.0,0.0,8.711,1.0,25.698,25.039,2.814,4.572,0,0.016,30011392.0,0.0,28.289,1.0,56.579,53.484,0.378,3.816,0,0.002,17686528.0,0.0,1.022,1.0,5.172,4.174,2.955,4.591,0,0.001,7225344.0,0.0,4.044,1.0,9.905,6.046,0.349,3.59,0,0.002,44986368.0,0.0,1.133,1.0,4.401,3.11,2.977,4.595,0,0.011,43847680.0,0.0,5.333,1.0,18.735,18.694,3.051,4.691,0,0.009,84566016.0,0.001,4.089,1.0,8.929,5.277,2.977,4.605,0,0.005,6901760.0,0.0,0,0,11.8,7.3,0,0,0.0,3.808,35.599,0.0,7.047,31.187,0.067,4.183,30.647,0.0,3.0,35.467,0.0
53
+ 2026-05-19 12:58:58,0.017,11325440.0,0.0,8.8,1.0,108.451,125.792,16.548,2593.75,0,0.177,48771072.0,1.599,1.022,1.0,11.063,14.491,6170.213,12909.091,0,0.009,8818688.0,0.0,40.889,1.0,56.058,41.57,0.278,1.022,0,0.007,47267840.0,0.0,8.711,1.0,25.698,25.039,2.817,4.577,0,0.016,30011392.0,0.0,28.289,1.0,56.752,54.18,0.377,3.813,0,0.002,18182144.0,0.0,1.022,1.0,4.771,4.089,2.956,4.591,0,0.001,7225344.0,0.0,4.044,1.0,8.289,5.06,0.345,3.543,0,0.002,44986368.0,0.0,1.133,1.0,4.711,3.304,2.978,4.596,0,0.011,43847680.0,0.0,5.333,1.0,18.089,17.96,3.051,4.691,0,0.014,84905984.0,0.015,3.8,1.0,10.243,6.17,2.982,4.625,0,0.005,6762496.0,0.0,0,0,18.816,11.665,0,0,0.0,3.808,35.599,0.0,7.071,31.088,0.067,4.183,30.647,0.0,3.04,35.364,0.0
54
+ 2026-05-19 12:59:03,0.022,11325440.0,0.0,8.8,1.0,97.383,112.954,16.548,2593.75,0,0.161,48771072.0,1.411,1.022,1.0,9.887,12.95,6170.213,12909.091,0,0.007,8818688.0,0.0,40.889,1.0,54.755,40.748,0.278,1.022,0,0.007,47267840.0,0.0,8.978,1.0,20.875,20.238,2.82,4.577,0,0.013,30011392.0,0.0,30.089,1.0,58.275,55.486,0.373,3.786,0,0.002,18182144.0,0.0,1.0,1.0,4.771,4.089,2.935,4.587,0,0.001,7225344.0,0.0,4.044,1.0,5.875,3.575,0.345,3.543,0,0.001,44986368.0,0.0,1.0,1.0,4.711,3.304,2.956,4.591,0,0.011,43847680.0,0.0,5.333,1.0,14.604,14.499,3.051,4.691,0,0.016,84905984.0,0.018,3.8,1.0,10.243,6.17,2.982,4.625,0,0.005,6762496.0,0.0,0,0,18.816,11.665,0,0,0.0,3.808,35.599,0.0,7.071,31.088,0.067,4.254,30.713,0.0,3.049,35.364,0.0
benchmark/boutique/codedefect/22/tool_cache.json ADDED
The diff for this file is too large to render. See raw diff
 
benchmark/boutique/codedefect/23/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/23/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/23/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
+ });