add snapshot version
This commit is contained in:
1 parent
4c7e96813c
commit
909ff91b2b
8 files changed
+18
-10
No files matched your search
@@ -1,6 +1,7 @@
|
||||
## 2.1.0
|
||||
* fix proxy path
|
||||
* add skip authenticate
|
||||
* add snapshot version
|
||||
## 2.0.0
|
||||
* add integration with isp-config-service 2.0
|
||||
## 1.3.0
|
||||
|
||||
@@ -23,8 +23,9 @@ func (app *accountant) Accept(method string) bool {
|
||||
|
||||
app.mx.Lock()
|
||||
resp := state.Update(stateStorage)
|
||||
//only true or every request todo
|
||||
atomic.AddInt64(&app.version, 1)
|
||||
if resp {
|
||||
atomic.AddInt64(&app.version, 1)
|
||||
}
|
||||
app.mx.Unlock()
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ type Accounting interface {
|
||||
|
||||
func Consumer(list []structure.AddressConfiguration) bool {
|
||||
accountingSetting := config.GetRemote().(*conf.RemoteConfig).AccountingSetting
|
||||
receiveConfiguration(accountingSetting)
|
||||
ReceiveConfiguration(accountingSetting)
|
||||
return true
|
||||
}
|
||||
|
||||
func receiveConfiguration(conf conf.Accounting) {
|
||||
func ReceiveConfiguration(conf conf.Accounting) {
|
||||
Close()
|
||||
|
||||
newAccountingStorage := make(map[int32]Accounting)
|
||||
|
||||
@@ -63,7 +63,7 @@ var (
|
||||
func TestAccounting(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
model.SnapshotRep = &snapshotRepository{cache: make(map[int32]map[string]state.Snapshot)}
|
||||
receiveConfiguration(accountingSetting)
|
||||
ReceiveConfiguration(accountingSetting)
|
||||
|
||||
req := reqExample[4]
|
||||
for _, path := range req.path {
|
||||
@@ -97,7 +97,7 @@ func TestAccounting(t *testing.T) {
|
||||
a.Equal(expected, Accept(req.appId, path))
|
||||
}
|
||||
|
||||
receiveConfiguration(accountingSetting)
|
||||
ReceiveConfiguration(accountingSetting)
|
||||
|
||||
req = reqExample[4]
|
||||
for _, path := range req.path {
|
||||
|
||||
@@ -49,9 +49,9 @@ type (
|
||||
|
||||
Accounting struct {
|
||||
Enable bool `schema:"Учет запросов,включает/отключает учет запросов"`
|
||||
SnapshotTimeout string `schema:"Частота выгрузки данных учета в БД" valid:"required~Required"`
|
||||
SnapshotTimeout string `schema:"Частота выгрузки ограничений для приложений" valid:"required~Required"`
|
||||
Setting []AccountingSetting `schema:"Настройка учета для приложений"`
|
||||
Storing StoringSetting `schema:"Настройка хранения запросов"`
|
||||
Storing StoringSetting `schema:"Настройка хранения всех запросов"`
|
||||
}
|
||||
|
||||
AccountingSetting struct {
|
||||
@@ -68,7 +68,7 @@ type (
|
||||
|
||||
StoringSetting struct {
|
||||
Size int `schema:"Размер буфера,размер буфера,при достижении которого данные сбрасываются в БД" valid:"required,range(1|1000000)"`
|
||||
Timeout string `schema:"Частота сброса,периодичность сброса данных в БД" valid:"required~Required"`
|
||||
Timeout string `schema:"Частота выгрузки всех учтенных запросов,периодичность сброса данных в БД" valid:"required~Required"`
|
||||
}
|
||||
|
||||
HttpSetting struct {
|
||||
|
||||
@@ -64,6 +64,7 @@ func onRemoteConfigReceive(remoteConfig, oldRemoteConfig *conf.RemoteConfig) {
|
||||
|
||||
redis.Client.ReceiveConfiguration(remoteConfig.Redis)
|
||||
authenticate.ReceiveConfiguration(remoteConfig.AuthCacheSetting)
|
||||
accounting.ReceiveConfiguration(remoteConfig.AccountingSetting)
|
||||
|
||||
metric.InitCollectors(remoteConfig.Metrics, oldRemoteConfig.Metrics)
|
||||
metric.InitHttpServer(remoteConfig.Metrics)
|
||||
|
||||
File renamed without changes.
+6
-1
@@ -21,7 +21,12 @@ type (
|
||||
)
|
||||
|
||||
func (r snapshotRepository) Update(list []entity.Snapshot) error {
|
||||
_, err := r.getDb().Model(&list).OnConflict("(app_id) DO UPDATE WHERE EXCLUDED.version > version").Insert()
|
||||
_, err := r.getDb().Model(&list).OnConflict("(app_id) DO UPDATE").
|
||||
Set("version = EXCLUDED.version").
|
||||
Set("app_id = EXCLUDED.app_id").
|
||||
Set("limit_state = EXCLUDED.limit_state").
|
||||
Where("snapshot.version < EXCLUDED.version").
|
||||
Insert()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user