From 7c4545459d3963d2e6dd681ec055607d319622b2 Mon Sep 17 00:00:00 2001 From: zyl <2025320615@qq.com> Date: Fri, 25 Dec 2020 17:51:42 +0800 Subject: [PATCH] =?UTF-8?q?#79=20=E6=B6=88=E6=81=AF=E8=BD=A8=E8=BF=B9?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E8=B7=9F=E8=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deployments/db.js | 29 +++++---- go.mod | 2 - go.sum | 62 ++++--------------- pkg/model/db_schema.go | 24 ++++--- server/handler/track_handler.go | 5 +- server/resource/v1/common.go | 1 + server/service/mongo/session/session.go | 12 +--- .../service/mongo/track/polling_detail_dao.go | 6 +- 8 files changed, 53 insertions(+), 88 deletions(-) diff --git a/deployments/db.js b/deployments/db.js index 42b919fb..c1201e3e 100644 --- a/deployments/db.js +++ b/deployments/db.js @@ -83,7 +83,7 @@ db.createCollection( "polling_detail", { max: 100, validator: { $jsonSchema: { bsonType: "object", - required: [ "id","session_id","domain","url_path" ], + required: [ "id","session_id","revision","url_path" ], properties: { id: { bsonType: "string", @@ -91,7 +91,7 @@ db.createCollection( "polling_detail", { domain: { bsonType: "string", }, - params: { + polling_data: { bsonType: "object" }, ip: { @@ -103,8 +103,8 @@ db.createCollection( "polling_detail", { response_body: { bsonType: "object" }, - response_header: { - bsonType: "object" + Revision: { + bsonType: "string" }, response_code: { bsonType: "number" @@ -114,15 +114,14 @@ db.createCollection( "polling_detail", { } ); //index -db.kv.createIndex({"id": 1}, { unique: true } ); -db.kv.createIndex({key: 1, label_format: 1,domain:1,project:1},{ unique: true }); -db.kv_revision.createIndex( { "delete_time": 1 }, { expireAfterSeconds: 7 * 24 * 3600 } ); -db.label.createIndex({"id": 1}, { unique: true } ); -db.label.createIndex({format: 1,domain:1,project:1},{ unique: true }); -db.polling_detail.createIndex({"id": 1}, { unique: true } ); -db.polling_detail.createIndex({session_id:1,domain:1}, { unique: true } ); -db.counter.createIndex({name: 1,domain:1},{ unique: true }); -db.view.createIndex({"id": 1}, { unique: true } ); -db.view.createIndex({display:1,domain:1,project:1},{ unique: true }); +db.kv.createIndex({"id": 1}, {unique: true}); +db.kv.createIndex({key: 1, label_format: 1, domain: 1, project: 1}, {unique: true}); +db.kv_revision.createIndex({"delete_time": 1}, {expireAfterSeconds: 7 * 24 * 3600}); +db.label.createIndex({"id": 1}, {unique: true}); +db.label.createIndex({format: 1, domain: 1, project: 1}, {unique: true}); +db.polling_detail.createIndex({timestamp: 1}, {expireAfterSeconds: 7 * 24 * 3600}); +db.counter.createIndex({name: 1, domain: 1}, {unique: true}); +db.view.createIndex({"id": 1}, {unique: true}); +db.view.createIndex({display: 1, domain: 1, project: 1}, {unique: true}); //db config -db.setProfilingLevel(1, {slowms: 80, sampleRate: 1} ); \ No newline at end of file +db.setProfilingLevel(1, {slowms: 80, sampleRate: 1}); \ No newline at end of file diff --git a/go.mod b/go.mod index 3da62ba0..bb8f4be7 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,7 @@ require ( github.com/emicklei/go-restful v2.12.0+incompatible github.com/go-chassis/go-archaius v1.3.6-0.20201103103813-43dd1680ebfb github.com/go-chassis/go-chassis/v2 v2.1.1-0.20201208062518-9c2e86bd7a6c - github.com/go-chassis/openlog v1.1.2 - github.com/go-chassis/paas-lager v1.1.1 github.com/go-chassis/seclog v1.3.0 github.com/go-playground/universal-translator v0.17.0 github.com/go-playground/validator v9.31.0+incompatible diff --git a/go.sum b/go.sum index 309b9e1c..d4aab76b 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,7 @@ github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxB github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/NYTimes/gziphandler v1.0.2-0.20180820182813-253f1acb9d9f h1:JliTHSbyp6SvSqw5Kdkd+kq2jJueTlDNQCyyr+4+/0o= @@ -15,17 +16,11 @@ github.com/NYTimes/gziphandler v1.0.2-0.20180820182813-253f1acb9d9f/go.mod h1:3w github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/Shonminh/apollo-client v0.2.0/go.mod h1:Jk6K99uIGxQm7Uyy1gCQTvM/kc1YLp4Qo9/jtGkEXvI= github.com/Shonminh/apollo-client v0.4.0/go.mod h1:Jk6K99uIGxQm7Uyy1gCQTvM/kc1YLp4Qo9/jtGkEXvI= github.com/Shopify/sarama v1.18.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/apache/servicecomb-service-center v0.0.0-20200710073115-6116a2ef5fdf/go.mod h1:AfixmoGz97+4vRyDJEoV4t3k0NUljIaELR2iEXU1hqU= -github.com/apache/servicecomb-service-center v0.0.0-20200717014253-66215bb9917b h1:X6s9WrKO+hVZSJRTJ8v4noq6xoulzO6cJBryGH4umW0= -github.com/apache/servicecomb-service-center v0.0.0-20200717014253-66215bb9917b/go.mod h1:jiw0zTHphl1PVLX+LgftTSebaECo7XX6qwCNUONSMvE= -github.com/apache/servicecomb-service-center v0.0.0-20200723031815-784c3533a8f2 h1:zTED7VqI+WD+gLXvbXoEV3ItUGRoQ54qlPghTo2HmhM= -github.com/apache/servicecomb-service-center v0.0.0-20200723031815-784c3533a8f2/go.mod h1:jiw0zTHphl1PVLX+LgftTSebaECo7XX6qwCNUONSMvE= github.com/apache/servicecomb-service-center v0.0.0-20200817025835-7bb8c4eb9421 h1:mdc3hngmwShPlG0z7NCdLre63Ll/jbL6/xQNoIiqJe8= github.com/apache/servicecomb-service-center v0.0.0-20200817025835-7bb8c4eb9421/go.mod h1:jiw0zTHphl1PVLX+LgftTSebaECo7XX6qwCNUONSMvE= github.com/apache/thrift v0.0.0-20180125231006-3d556248a8b9/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= @@ -87,53 +82,15 @@ github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4 h1:wx8JXvg github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c= github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3 h1:c+bwT0qLY69jSU8TmzuNcb9UL/QFAiU96kjuX5TMiQc= github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c= +github.com/go-chassis/foundation v0.2.2-0.20201208060254-d5e8e5beb1f0 h1:6oazFyZKryG3r7K20UuWx+bclHMFGXjKBSMJpCefmMI= github.com/go-chassis/foundation v0.2.2-0.20201208060254-d5e8e5beb1f0/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA= -github.com/go-chassis/go-archaius v1.2.1-0.20200309104817-8c3d4e87d33c h1:pimEM4Oy/Uf4xG4G7TrRUQbIRFAfHiarxDQQS2gmKaM= -github.com/go-chassis/go-archaius v1.2.1-0.20200309104817-8c3d4e87d33c/go.mod h1:gVP52u/jCU0fgUjXdUW1VLp5YLLJ+Yl2zoOPrLM/WOM= -github.com/go-chassis/go-archaius v1.2.1/go.mod h1:gVP52u/jCU0fgUjXdUW1VLp5YLLJ+Yl2zoOPrLM/WOM= -github.com/go-chassis/go-archaius v1.2.2-0.20200409030209-a48668e4a025 h1:zzqQeCKkslJwW0/QuOLQyZVqiCl7tgTTrdTbMEb0+kI= -github.com/go-chassis/go-archaius v1.2.2-0.20200409030209-a48668e4a025/go.mod h1:gVP52u/jCU0fgUjXdUW1VLp5YLLJ+Yl2zoOPrLM/WOM= github.com/go-chassis/go-archaius v1.3.2 h1:b52voYtSL+fukmvg/rsn/quw/hgDWtV945adl0VV8Lg= github.com/go-chassis/go-archaius v1.3.2/go.mod h1:nzRL1sSodtgeCZMzCNu0y2LPH5zz7chp8uaQ0GS0x6I= -github.com/go-chassis/go-archaius v1.3.3 h1:phNCPOi5tIMj6SBLJCoD2GcE2f43rk0I3gdpHqm90Pg= -github.com/go-chassis/go-archaius v1.3.3/go.mod h1:K9gt8DIj582EQfKQdZV+jWBKNeevwaM+2cdLQgpOlZM= github.com/go-chassis/go-archaius v1.3.6-0.20201103103813-43dd1680ebfb h1:+6mPi1HDASveJ72gWkH0rmq5hNz/rTZhrIgRXjFnSRE= github.com/go-chassis/go-archaius v1.3.6-0.20201103103813-43dd1680ebfb/go.mod h1:K9gt8DIj582EQfKQdZV+jWBKNeevwaM+2cdLQgpOlZM= -github.com/go-chassis/go-chassis v0.0.0-20200318142212-4ca7f5fb7745 h1:BDHDeJBW+0/iC/1otn4XQ7ndfqzeGrFFi6SLSBuhRvs= -github.com/go-chassis/go-chassis v0.0.0-20200318142212-4ca7f5fb7745/go.mod h1:UsROzOZPD9YgTpVUE/jFclVxDwHWESLNdwwbfKQ8aMs= -github.com/go-chassis/go-chassis v0.0.0-20200320074343-30f669c0c47b h1:ZH88vLcGL4bNc+Vbm1g3jrhtTxBSnGvyZCpbbkVa5a0= -github.com/go-chassis/go-chassis v0.0.0-20200320074343-30f669c0c47b/go.mod h1:UsROzOZPD9YgTpVUE/jFclVxDwHWESLNdwwbfKQ8aMs= -github.com/go-chassis/go-chassis v0.0.0-20200322084331-36849ab2cb10 h1:l3bUZf0Hjh1+7b2Ed5Fqb/cCOjMGBe8WmPd/ucyoGgQ= -github.com/go-chassis/go-chassis v0.0.0-20200322084331-36849ab2cb10/go.mod h1:UsROzOZPD9YgTpVUE/jFclVxDwHWESLNdwwbfKQ8aMs= -github.com/go-chassis/go-chassis v0.0.0-20200701101447-f47108e3903d h1:ynz1G/YO61f/u34J08oeXhLANKzSicduvRSdPDhQ1sg= -github.com/go-chassis/go-chassis v0.0.0-20200701101447-f47108e3903d/go.mod h1:S7RbnpeTWBqZ4+UxGAs05a6qdhDyWKpTNuil8FYNiME= -github.com/go-chassis/go-chassis v0.0.0-20200709095636-48e710908928 h1:y464C11Trvr8uZcsRVKu8grVeXbwFdftSA5BAKYVR+8= -github.com/go-chassis/go-chassis v0.0.0-20200709095636-48e710908928/go.mod h1:S7RbnpeTWBqZ4+UxGAs05a6qdhDyWKpTNuil8FYNiME= github.com/go-chassis/go-chassis v0.0.0-20200716073336-4183d5dd1246 h1:yxtoclu0QclYtwXxo4AYTCPJsYFM/Xo2/5C1HLRnzqg= github.com/go-chassis/go-chassis v0.0.0-20200716073336-4183d5dd1246/go.mod h1:S7RbnpeTWBqZ4+UxGAs05a6qdhDyWKpTNuil8FYNiME= -github.com/go-chassis/go-chassis v0.0.0-20200728122719-5c6c673368c5 h1:HVDP4+W7InMwxTorvBjJxuKOJY/L+z4zy2IIiDcmpfs= -github.com/go-chassis/go-chassis v0.0.0-20200728122719-5c6c673368c5/go.mod h1:nMWwWrgDEyDKnMQLE5Gt65RdwbgrQg5amt4BqNFY09g= -github.com/go-chassis/go-chassis v0.0.0-20200803103444-d7b1d63e60bc h1:5k+qm8uj2jOJff2tiUlprtMwpLiwukjThoZ3KXacK8c= -github.com/go-chassis/go-chassis v0.0.0-20200803103444-d7b1d63e60bc/go.mod h1:nMWwWrgDEyDKnMQLE5Gt65RdwbgrQg5amt4BqNFY09g= -github.com/go-chassis/go-chassis v0.0.0-20200812055904-70406395b783 h1:zFQcB2BGZJLSOfKk4Pq2cJSXu9fSZWUbeYtoFoBnBI4= -github.com/go-chassis/go-chassis v0.0.0-20200812055904-70406395b783/go.mod h1:nMWwWrgDEyDKnMQLE5Gt65RdwbgrQg5amt4BqNFY09g= -github.com/go-chassis/go-chassis v0.0.0-20200817095942-bf386412b79e h1:OElheBuqH8OL3//IlPwrM+AKfeEXlnIgXMypW1N2CLk= -github.com/go-chassis/go-chassis v0.0.0-20200817095942-bf386412b79e/go.mod h1:nMWwWrgDEyDKnMQLE5Gt65RdwbgrQg5amt4BqNFY09g= -github.com/go-chassis/go-chassis v0.0.0-20200818014813-890265d94a1c h1:aAokQ5cgL/6a8tJsj3W6qr7M3EBoMs3MzlfYqalLLto= -github.com/go-chassis/go-chassis v0.0.0-20200818014813-890265d94a1c/go.mod h1:nMWwWrgDEyDKnMQLE5Gt65RdwbgrQg5amt4BqNFY09g= -github.com/go-chassis/go-chassis v0.0.0-20200826064053-d90be848aa10 h1:eImN6UFx4pksyxJQnT1laHoVOwSlhEC1ONhJQc4Ix08= -github.com/go-chassis/go-chassis v0.0.0-20200826064053-d90be848aa10/go.mod h1:ZzLCaQFgFHbkwf8grJrbzBLlE19iz+4LMgNtjGlnanU= -github.com/go-chassis/go-chassis v1.8.2-0.20200310060113-4b383ba3d3f0 h1:YD9MtuYIpQb+EKxIzV/swdXUhnV5PtXtSW696JiwW1c= -github.com/go-chassis/go-chassis v1.8.2-0.20200310060113-4b383ba3d3f0/go.mod h1:sFnVxSvprpy6umPFK4uSdfCDdfqdgbp3FdW/CG0VNnE= -github.com/go-chassis/go-chassis v1.8.2-0.20200331092516-8cf0b374128b h1:AvZjvPQdla1KoLrxbU8bohR3Y9FYnScZFY5KnK2HnSU= -github.com/go-chassis/go-chassis v1.8.2-0.20200331092516-8cf0b374128b/go.mod h1:ooQ3peVePtKic3ci/vIGEmGHTC5/BxUeYLN+eKu+EUU= -github.com/go-chassis/go-chassis v1.8.2-0.20200426111522-0f37ad3d79e5 h1:QpSTAsKX2S/H0lc7bPOrFGDlPLQGr86y+q4nt0r0lCg= -github.com/go-chassis/go-chassis v1.8.2-0.20200426111522-0f37ad3d79e5/go.mod h1:ooQ3peVePtKic3ci/vIGEmGHTC5/BxUeYLN+eKu+EUU= -github.com/go-chassis/go-chassis v1.8.2 h1:lX+XJbIGSkC4c+1h8IcoBQFEX9vaZ0+KNugE24Q/I/Y= -github.com/go-chassis/go-chassis/v2 v2.0.2 h1:FMiZgAa6IjDobtZN5oql+eSgMIlDq5+12ogrZRR62ks= -github.com/go-chassis/go-chassis/v2 v2.0.2/go.mod h1:xgXXrRUgn5sybtecTDn60ypepHKIV9QpSqR3CIEBNt0= -github.com/go-chassis/go-chassis/v2 v2.1.0 h1:NnVUBj3U/pPijpZGooH+3QIRlOB2nAuZtx9b71aiaig= -github.com/go-chassis/go-chassis/v2 v2.1.0/go.mod h1:DHA83QKVmuOtdkaWCP5yCDOh+GIRH+YpX3uZ2BlGMWw= +github.com/go-chassis/go-chassis/v2 v2.1.1-0.20201208062518-9c2e86bd7a6c h1:k+D2w1oZ/fQjingJc1KzuwGv0cJKfaGDgaOW/4T4Q1c= github.com/go-chassis/go-chassis/v2 v2.1.1-0.20201208062518-9c2e86bd7a6c/go.mod h1:C5j2kuBAdch4DsSjKQxiYJr3Xy0PoZu2Bxx9QIJIArI= github.com/go-chassis/go-restful-swagger20 v1.0.3-0.20200310030431-17d80f34264f h1:5QmmNpVcGqIc6tuKNe5EAI4PA8Yn2EL9Oee7YdcJ4PE= github.com/go-chassis/go-restful-swagger20 v1.0.3-0.20200310030431-17d80f34264f/go.mod h1:eW62fYuzlNFDvIacB6AV8bhUDCTy4myfTCv0bT9Gbb0= @@ -143,8 +100,6 @@ github.com/go-chassis/openlog v1.1.2 h1:LgGfwwOhpU8c6URV6ADpaRBPVY7Ph1C28jCQ6zzQ github.com/go-chassis/openlog v1.1.2/go.mod h1:+eYCADVxWyJkwsFMUBrMxyQlNqW+UUsCxvR2LrYZUaA= github.com/go-chassis/paas-lager v1.1.1 h1:/6wqawUGjPCpd57A/tzJzgC4MnEhNuigbayQS+2VWPQ= github.com/go-chassis/paas-lager v1.1.1/go.mod h1:tILYbn3+0jjCxhY6/ue9L8eRq+VJ60U6VYIdugqchB4= -github.com/go-chassis/seclog v1.2.1 h1:h+Aijmh76ICKD1jcajpt/LK2wJMmtHofUjE+/MhOrYs= -github.com/go-chassis/seclog v1.2.1/go.mod h1:88O2MV8uP6L3ulaIGcrwAtXhNAii/57cuvdDfW7JQIg= github.com/go-chassis/seclog v1.3.0 h1:ofjF+GpDd7YFdxa6xk13brZfVSKMdZoQVPoCWjFHGUk= github.com/go-chassis/seclog v1.3.0/go.mod h1:a/zGvX5BRiwtq/O0fRqS6VWjrBaXYtqFJBx3EX9xzSE= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -221,6 +176,7 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -342,6 +298,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/natefinch/lumberjack v0.0.0-20170531160350-a96e63847dc3 h1:BDvcX7oM8ZWOS08LQXaW8ucGblfoSG4srpoW6pKhvqs= github.com/natefinch/lumberjack v0.0.0-20170531160350-a96e63847dc3/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= +github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/olekukonko/tablewriter v0.0.0-20180506121414-d4647c9c7a84/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -349,11 +306,13 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= @@ -411,6 +370,7 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY= github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= @@ -432,13 +392,12 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA= github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= @@ -555,6 +514,7 @@ golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c h1:IGkKhmfzcztjm6gYkykvu/NiS8kaqbCWAEWWAyf8J5U= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= @@ -582,6 +542,7 @@ gopkg.in/cheggaaa/pb.v1 v1.0.28/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qS gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= @@ -598,6 +559,7 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/model/db_schema.go b/pkg/model/db_schema.go index 4d6fe506..0776aba5 100644 --- a/pkg/model/db_schema.go +++ b/pkg/model/db_schema.go @@ -17,6 +17,8 @@ package model +import "time" + //LabelDoc is database struct to store labels type LabelDoc struct { ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" swag:"string"` @@ -57,16 +59,18 @@ type ViewDoc struct { //PollingDetail is db struct, it record operation history type PollingDetail struct { - ID string `json:"id,omitempty" yaml:"id,omitempty"` - SessionID string `json:"session_id,omitempty" bson:"session_id," yaml:"session_id,omitempty"` - Domain string `json:"domain,omitempty" yaml:"domain,omitempty"` - PollingData map[string]interface{} `json:"polling_data,omitempty" yaml:"polling_data,omitempty"` - IP string `json:"ip,omitempty" yaml:"ip,omitempty"` - UserAgent string `json:"user_agent,omitempty" bson:"user_agent," yaml:"user_agent,omitempty"` - URLPath string `json:"url_path,omitempty" bson:"url_path," yaml:"url_path,omitempty"` - ResponseBody []*KVDoc `json:"kv,omitempty" bson:"kv," yaml:"kv,omitempty"` - ResponseHeader map[string][]string `json:"response_header,omitempty" bson:"response_header," yaml:"response_header,omitempty"` - ResponseCode int `json:"response_code,omitempty" bson:"response_code," yaml:"response_code,omitempty"` + ID string `json:"id,omitempty" yaml:"id,omitempty"` + SessionID string `json:"session_id,omitempty" bson:"session_id," yaml:"session_id,omitempty"` + SessionGroup string `json:"session_group,omitempty" bson:"session_group," yaml:"session_group,omitempty"` + Domain string `json:"domain,omitempty" yaml:"domain,omitempty"` + PollingData map[string]interface{} `json:"polling_data,omitempty" yaml:"polling_data,omitempty"` + Revision string `json:"revision,omitempty" yaml:"revision,omitempty"` + IP string `json:"ip,omitempty" yaml:"ip,omitempty"` + UserAgent string `json:"user_agent,omitempty" bson:"user_agent," yaml:"user_agent,omitempty"` + URLPath string `json:"url_path,omitempty" bson:"url_path," yaml:"url_path,omitempty"` + ResponseBody []*KVDoc `json:"kv,omitempty" bson:"kv," yaml:"kv,omitempty"` + ResponseCode int `json:"response_code,omitempty" bson:"response_code," yaml:"response_code,omitempty"` + Timestamp time.Time `json:"times_tamp,omitempty" yaml:"times_tamp,omitempty"` } // UpdateKVRequest is db struct, it contains kv update request params diff --git a/server/handler/track_handler.go b/server/handler/track_handler.go index bddd7a8b..b5be76b8 100644 --- a/server/handler/track_handler.go +++ b/server/handler/track_handler.go @@ -29,6 +29,7 @@ import ( "github.com/go-chassis/openlog" "net/http" "strings" + "time" ) //const of noop auth handler @@ -66,13 +67,15 @@ func (h *TrackHandler) Handle(chain *handler.Chain, inv *invocation.Invocation, data := &model.PollingDetail{} data.URLPath = req.Request.Method + " " + req.Request.URL.Path data.SessionID = sessionID + data.SessionGroup = req.HeaderParameter(v1.HeaderSessionGroup) data.UserAgent = req.HeaderParameter(v1.HeaderUserAgent) data.Domain = v1.ReadDomain(req.Request.Context()) data.IP = iputil.ClientIP(req.Request) data.ResponseBody = req.Attribute(common.RespBodyContextKey).([]*model.KVDoc) + data.Timestamp = time.Now() data.ResponseCode = ir.Status if resp != nil { - data.ResponseHeader = resp.Header() + data.Revision = resp.Header().Get(common.HeaderRevision) } data.PollingData = map[string]interface{}{ "revision": revStr, diff --git a/server/resource/v1/common.go b/server/resource/v1/common.go index 21b80c1e..8500e415 100644 --- a/server/resource/v1/common.go +++ b/server/resource/v1/common.go @@ -43,6 +43,7 @@ import ( const ( HeaderUserAgent = "User-Agent" HeaderSessionID = "X-Session-Id" + HeaderSessionGroup = "X-Session-Group" AttributeDomainKey = "domain" FmtReadRequestError = "decode request body failed: %v" diff --git a/server/service/mongo/session/session.go b/server/service/mongo/session/session.go index 16e3d6b2..cb999338 100644 --- a/server/service/mongo/session/session.go +++ b/server/service/mongo/session/session.go @@ -222,19 +222,13 @@ func ensureKVLongPolling(session *mgo.Session) { c := session.DB(DBName).C(CollectionPollingDetail) err := c.Create(&mgo.CollectionInfo{Validator: bson.M{ "id": bson.M{"$exists": true}, - "params": bson.M{"$exists": true}, + "revision": bson.M{"$exists": true}, "session_id": bson.M{"$exists": true}, "url_path": bson.M{"$exists": true}, }}) - wrapError(err, MsgDBExists) - err = c.EnsureIndex(mgo.Index{ - Key: []string{"id"}, - Unique: true, - }) - wrapError(err) err = c.EnsureIndex(mgo.Index{ - Key: []string{"session_id", "domain"}, - Unique: true, + Key: []string{"timestamp"}, + ExpireAfter: 7 * 24 * time.Hour, }) wrapError(err) } diff --git a/server/service/mongo/track/polling_detail_dao.go b/server/service/mongo/track/polling_detail_dao.go index bb3bcae6..5df094b8 100644 --- a/server/service/mongo/track/polling_detail_dao.go +++ b/server/service/mongo/track/polling_detail_dao.go @@ -29,9 +29,10 @@ import ( ) //CreateOrUpdate create a record or update exist record +//If revision and session_id is exit: update else: insert func CreateOrUpdate(ctx context.Context, detail *model.PollingDetail) (*model.PollingDetail, error) { collection := session.GetDB().Collection(session.CollectionPollingDetail) - queryFilter := bson.M{"domain": detail.Domain, "session_id": detail.SessionID} + queryFilter := bson.M{"revision": detail.Revision, "session_id": detail.SessionID} res := collection.FindOne(ctx, queryFilter) if res.Err() != nil { if res.Err() == mongo.ErrNoDocuments { @@ -67,6 +68,9 @@ func Get(ctx context.Context, detail *model.PollingDetail) ([]*model.PollingDeta if detail.URLPath != "" { queryFilter["url_path"] = detail.URLPath } + if detail.Revision != "" { + queryFilter["revision"] = detail.Revision + } cur, err := collection.Find(ctx, queryFilter) if err != nil { return nil, err