Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
dbb34020
Unverified
Commit
dbb34020
authored
Dec 07, 2018
by
Torkel Ödegaard
Committed by
GitHub
Dec 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14375 from moznion/fix_quota_updating
Fix quota updating
parents
9cc4e052
4397ee61
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
6 deletions
+71
-6
pkg/services/sqlstore/quota.go
+6
-6
pkg/services/sqlstore/quota_test.go
+65
-0
No files found.
pkg/services/sqlstore/quota.go
View file @
dbb34020
...
@@ -99,14 +99,14 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error {
...
@@ -99,14 +99,14 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error {
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
//Check if quota is already defined in the DB
//Check if quota is already defined in the DB
quota
:=
m
.
Quota
{
quota
:=
m
.
Quota
{
Target
:
cmd
.
Target
,
Target
:
cmd
.
Target
,
OrgId
:
cmd
.
OrgId
,
OrgId
:
cmd
.
OrgId
,
Updated
:
time
.
Now
(),
}
}
has
,
err
:=
sess
.
Get
(
&
quota
)
has
,
err
:=
sess
.
Get
(
&
quota
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
quota
.
Updated
=
time
.
Now
()
quota
.
Limit
=
cmd
.
Limit
quota
.
Limit
=
cmd
.
Limit
if
!
has
{
if
!
has
{
quota
.
Created
=
time
.
Now
()
quota
.
Created
=
time
.
Now
()
...
@@ -201,14 +201,14 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error {
...
@@ -201,14 +201,14 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error {
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
//Check if quota is already defined in the DB
//Check if quota is already defined in the DB
quota
:=
m
.
Quota
{
quota
:=
m
.
Quota
{
Target
:
cmd
.
Target
,
Target
:
cmd
.
Target
,
UserId
:
cmd
.
UserId
,
UserId
:
cmd
.
UserId
,
Updated
:
time
.
Now
(),
}
}
has
,
err
:=
sess
.
Get
(
&
quota
)
has
,
err
:=
sess
.
Get
(
&
quota
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
quota
.
Updated
=
time
.
Now
()
quota
.
Limit
=
cmd
.
Limit
quota
.
Limit
=
cmd
.
Limit
if
!
has
{
if
!
has
{
quota
.
Created
=
time
.
Now
()
quota
.
Created
=
time
.
Now
()
...
...
pkg/services/sqlstore/quota_test.go
View file @
dbb34020
...
@@ -2,6 +2,7 @@ package sqlstore
...
@@ -2,6 +2,7 @@ package sqlstore
import
(
import
(
"testing"
"testing"
"time"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
...
@@ -168,5 +169,69 @@ func TestQuotaCommandsAndQueries(t *testing.T) {
...
@@ -168,5 +169,69 @@ func TestQuotaCommandsAndQueries(t *testing.T) {
So
(
query
.
Result
.
Limit
,
ShouldEqual
,
5
)
So
(
query
.
Result
.
Limit
,
ShouldEqual
,
5
)
So
(
query
.
Result
.
Used
,
ShouldEqual
,
1
)
So
(
query
.
Result
.
Used
,
ShouldEqual
,
1
)
})
})
// related: https://github.com/grafana/grafana/issues/14342
Convey
(
"Should org quota updating is successful even if it called multiple time"
,
func
()
{
orgCmd
:=
m
.
UpdateOrgQuotaCmd
{
OrgId
:
orgId
,
Target
:
"org_user"
,
Limit
:
5
,
}
err
:=
UpdateOrgQuota
(
&
orgCmd
)
So
(
err
,
ShouldBeNil
)
query
:=
m
.
GetOrgQuotaByTargetQuery
{
OrgId
:
orgId
,
Target
:
"org_user"
,
Default
:
1
}
err
=
GetOrgQuotaByTarget
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Limit
,
ShouldEqual
,
5
)
// XXX: resolution of `Updated` column is 1sec, so this makes delay
time
.
Sleep
(
1
*
time
.
Second
)
orgCmd
=
m
.
UpdateOrgQuotaCmd
{
OrgId
:
orgId
,
Target
:
"org_user"
,
Limit
:
10
,
}
err
=
UpdateOrgQuota
(
&
orgCmd
)
So
(
err
,
ShouldBeNil
)
query
=
m
.
GetOrgQuotaByTargetQuery
{
OrgId
:
orgId
,
Target
:
"org_user"
,
Default
:
1
}
err
=
GetOrgQuotaByTarget
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Limit
,
ShouldEqual
,
10
)
})
// related: https://github.com/grafana/grafana/issues/14342
Convey
(
"Should user quota updating is successful even if it called multiple time"
,
func
()
{
userQuotaCmd
:=
m
.
UpdateUserQuotaCmd
{
UserId
:
userId
,
Target
:
"org_user"
,
Limit
:
5
,
}
err
:=
UpdateUserQuota
(
&
userQuotaCmd
)
So
(
err
,
ShouldBeNil
)
query
:=
m
.
GetUserQuotaByTargetQuery
{
UserId
:
userId
,
Target
:
"org_user"
,
Default
:
1
}
err
=
GetUserQuotaByTarget
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Limit
,
ShouldEqual
,
5
)
// XXX: resolution of `Updated` column is 1sec, so this makes delay
time
.
Sleep
(
1
*
time
.
Second
)
userQuotaCmd
=
m
.
UpdateUserQuotaCmd
{
UserId
:
userId
,
Target
:
"org_user"
,
Limit
:
10
,
}
err
=
UpdateUserQuota
(
&
userQuotaCmd
)
So
(
err
,
ShouldBeNil
)
query
=
m
.
GetUserQuotaByTargetQuery
{
UserId
:
userId
,
Target
:
"org_user"
,
Default
:
1
}
err
=
GetUserQuotaByTarget
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Limit
,
ShouldEqual
,
10
)
})
})
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment