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
06855d2b
Unverified
Commit
06855d2b
authored
Sep 13, 2018
by
Torkel Ödegaard
Committed by
GitHub
Sep 13, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13253 from grafana/13240_auth_stats
Fix anonymous usage stats for authentication types
parents
4b0eeab2
1d66f9a4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
7 deletions
+75
-7
pkg/metrics/metrics.go
+19
-1
pkg/metrics/metrics_test.go
+26
-3
pkg/metrics/service.go
+2
-1
pkg/metrics/settings.go
+4
-0
pkg/social/social.go
+24
-2
No files found.
pkg/metrics/metrics.go
View file @
06855d2b
...
...
@@ -350,7 +350,7 @@ func getEdition() string {
}
}
func
sendUsageStats
()
{
func
sendUsageStats
(
oauthProviders
map
[
string
]
bool
)
{
if
!
setting
.
ReportingEnabled
{
return
}
...
...
@@ -450,6 +450,24 @@ func sendUsageStats() {
metrics
[
"stats.alert_notifiers."
+
stats
.
Type
+
".count"
]
=
stats
.
Count
}
authTypes
:=
map
[
string
]
bool
{}
authTypes
[
"anonymous"
]
=
setting
.
AnonymousEnabled
authTypes
[
"basic_auth"
]
=
setting
.
BasicAuthEnabled
authTypes
[
"ldap"
]
=
setting
.
LdapEnabled
authTypes
[
"auth_proxy"
]
=
setting
.
AuthProxyEnabled
for
provider
,
enabled
:=
range
oauthProviders
{
authTypes
[
"oauth_"
+
provider
]
=
enabled
}
for
authType
,
enabled
:=
range
authTypes
{
enabledValue
:=
0
if
enabled
{
enabledValue
=
1
}
metrics
[
"stats.auth_enabled."
+
authType
+
".count"
]
=
enabledValue
}
out
,
_
:=
json
.
MarshalIndent
(
report
,
""
,
" "
)
data
:=
bytes
.
NewBuffer
(
out
)
...
...
pkg/metrics/metrics_test.go
View file @
06855d2b
...
...
@@ -147,11 +147,19 @@ func TestMetrics(t *testing.T) {
}))
usageStatsURL
=
ts
.
URL
sendUsageStats
()
oauthProviders
:=
map
[
string
]
bool
{
"github"
:
true
,
"gitlab"
:
true
,
"google"
:
true
,
"generic_oauth"
:
true
,
"grafana_com"
:
true
,
}
sendUsageStats
(
oauthProviders
)
Convey
(
"Given reporting not enabled and sending usage stats"
,
func
()
{
setting
.
ReportingEnabled
=
false
sendUsageStats
()
sendUsageStats
(
oauthProviders
)
Convey
(
"Should not gather stats or call http endpoint"
,
func
()
{
So
(
getSystemStatsQuery
,
ShouldBeNil
)
...
...
@@ -164,8 +172,13 @@ func TestMetrics(t *testing.T) {
Convey
(
"Given reporting enabled and sending usage stats"
,
func
()
{
setting
.
ReportingEnabled
=
true
setting
.
BuildVersion
=
"5.0.0"
setting
.
AnonymousEnabled
=
true
setting
.
BasicAuthEnabled
=
true
setting
.
LdapEnabled
=
true
setting
.
AuthProxyEnabled
=
true
wg
.
Add
(
1
)
sendUsageStats
()
sendUsageStats
(
oauthProviders
)
Convey
(
"Should gather stats and call http endpoint"
,
func
()
{
if
waitTimeout
(
&
wg
,
2
*
time
.
Second
)
{
...
...
@@ -220,6 +233,16 @@ func TestMetrics(t *testing.T) {
So
(
metrics
.
Get
(
"stats.alert_notifiers.slack.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.alert_notifiers.webhook.count"
)
.
MustInt
(),
ShouldEqual
,
2
)
So
(
metrics
.
Get
(
"stats.auth_enabled.anonymous.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.basic_auth.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.ldap.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.auth_proxy.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.oauth_github.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.oauth_gitlab.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.oauth_google.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.oauth_generic_oauth.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
So
(
metrics
.
Get
(
"stats.auth_enabled.oauth_grafana_com.count"
)
.
MustInt
(),
ShouldEqual
,
1
)
})
})
...
...
pkg/metrics/service.go
View file @
06855d2b
...
...
@@ -30,6 +30,7 @@ type InternalMetricsService struct {
intervalSeconds
int64
graphiteCfg
*
graphitebridge
.
Config
oauthProviders
map
[
string
]
bool
}
func
(
im
*
InternalMetricsService
)
Init
()
error
{
...
...
@@ -60,7 +61,7 @@ func (im *InternalMetricsService) Run(ctx context.Context) error {
for
{
select
{
case
<-
onceEveryDayTick
.
C
:
sendUsageStats
()
sendUsageStats
(
im
.
oauthProviders
)
case
<-
everyMinuteTicker
.
C
:
updateTotalStats
()
case
<-
ctx
.
Done
()
:
...
...
pkg/metrics/settings.go
View file @
06855d2b
...
...
@@ -5,6 +5,8 @@ import (
"strings"
"time"
"github.com/grafana/grafana/pkg/social"
"github.com/grafana/grafana/pkg/metrics/graphitebridge"
"github.com/grafana/grafana/pkg/setting"
"github.com/prometheus/client_golang/prometheus"
...
...
@@ -22,6 +24,8 @@ func (im *InternalMetricsService) readSettings() error {
return
fmt
.
Errorf
(
"Unable to parse metrics graphite section, %v"
,
err
)
}
im
.
oauthProviders
=
social
.
GetOAuthProviders
(
im
.
Cfg
)
return
nil
}
...
...
pkg/social/social.go
View file @
06855d2b
...
...
@@ -49,14 +49,13 @@ func (e *Error) Error() string {
var
(
SocialBaseUrl
=
"/login/"
SocialMap
=
make
(
map
[
string
]
SocialConnector
)
allOauthes
=
[]
string
{
"github"
,
"gitlab"
,
"google"
,
"generic_oauth"
,
"grafananet"
,
"grafana_com"
}
)
func
NewOAuthService
()
{
setting
.
OAuthService
=
&
setting
.
OAuther
{}
setting
.
OAuthService
.
OAuthInfos
=
make
(
map
[
string
]
*
setting
.
OAuthInfo
)
allOauthes
:=
[]
string
{
"github"
,
"gitlab"
,
"google"
,
"generic_oauth"
,
"grafananet"
,
"grafana_com"
}
for
_
,
name
:=
range
allOauthes
{
sec
:=
setting
.
Raw
.
Section
(
"auth."
+
name
)
info
:=
&
setting
.
OAuthInfo
{
...
...
@@ -184,3 +183,26 @@ func NewOAuthService() {
}
}
}
// GetOAuthProviders returns available oauth providers and if they're enabled or not
var
GetOAuthProviders
=
func
(
cfg
*
setting
.
Cfg
)
map
[
string
]
bool
{
result
:=
map
[
string
]
bool
{}
if
cfg
==
nil
||
cfg
.
Raw
==
nil
{
return
result
}
for
_
,
name
:=
range
allOauthes
{
if
name
==
"grafananet"
{
name
=
"grafana_com"
}
sec
:=
cfg
.
Raw
.
Section
(
"auth."
+
name
)
if
sec
==
nil
{
continue
}
result
[
name
]
=
sec
.
Key
(
"enabled"
)
.
MustBool
()
}
return
result
}
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