Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-12185 migrate telemetry GrafanaDS to using PostgreSQL #2542

Merged
merged 18 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ require (
k8s.io/cli-runtime v0.28.0
k8s.io/client-go v0.28.0
k8s.io/kubectl v0.28.0
modernc.org/sqlite v1.26.0
sigs.k8s.io/controller-runtime v0.14.6
)

Expand All @@ -114,11 +113,11 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-ieproxy v0.0.1 // indirect
github.com/minio/minio-go v6.0.14+incompatible // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand All @@ -128,7 +127,6 @@ require (
github.com/percona/percona-backup-mongodb v1.8.1 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -142,15 +140,6 @@ require (
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.24.1 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.6.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
Expand Down
33 changes: 0 additions & 33 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,6 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down Expand Up @@ -710,9 +708,6 @@ github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwa
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/ramr/go-reaper v0.2.1 h1:zww+wlQOvTjBZuk1920R/e0GFEb6O7+B0WQLV6dM924=
github.com/ramr/go-reaper v0.2.1/go.mod h1:AVypdzrcCXjSc/JYnlXl8TsB+z84WyFzxWE8Jh0MOJc=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down Expand Up @@ -1231,34 +1226,6 @@ k8s.io/kubectl v0.28.0 h1:qhfju0OaU+JGeBlToPeeIg2UJUWP++QwTkpio6nlPKg=
k8s.io/kubectl v0.28.0/go.mod h1:1We+E5nSX3/TVoSQ6y5Bzld5OhTBHZHlKEYl7g/NaTk=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.40.0 h1:P3g79IUS/93SYhtoeaHW+kRCIrYaxJ27MFPv+7kaTOw=
modernc.org/cc/v3 v3.40.0/go.mod h1:/bTg4dnWkSXowUO6ssQKnOV0yMVxDYNIsIrzqTFDGH0=
modernc.org/ccgo/v3 v3.16.13 h1:Mkgdzl46i5F/CNR/Kj80Ri59hC8TKAhZrYSaqvkwzUw=
modernc.org/ccgo/v3 v3.16.13/go.mod h1:2Quk+5YgpImhPjv2Qsob1DnZ/4som1lJTodubIcoUkY=
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
modernc.org/libc v1.24.1 h1:uvJSeCKL/AgzBo2yYIPPTy82v21KgGnizcGYfBHaNuM=
modernc.org/libc v1.24.1/go.mod h1:FmfO1RLrU3MHJfyi9eYYmZBfi/R+tqZ6+hQ3yQQUkak=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.6.0 h1:i6mzavxrE9a30whzMfwf7XWVODx2r5OYXvU46cirX7o=
modernc.org/memory v1.6.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sqlite v1.26.0 h1:SocQdLRSYlA8W99V8YH0NES75thx19d9sB/aFc4R8Lw=
modernc.org/sqlite v1.26.0/go.mod h1:FL3pVXie73rg3Rii6V/u5BoHlSoyeZeIgKZEgHARyCU=
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=
modernc.org/tcl v1.15.2/go.mod h1:3+k/ZaEbKrC8ePv8zJWPtBSW0V7Gg9g8rkmhI1Kfs3c=
modernc.org/token v1.0.1 h1:A3qvTqOwexpfZZeyI0FeGPDlSWX5pjZu9hF4lU+EKWg=
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/z v1.7.3 h1:zDJf6iHjrnB+WRD88stbXokugjyc0/pB91ri1gO6LZY=
modernc.org/z v1.7.3/go.mod h1:Ipv4tsdxZRbQyLq9Q1M6gdbkxYzdlrciF2Hi/lS7nWE=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
6 changes: 6 additions & 0 deletions managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,12 @@ func main() { //nolint:cyclop,maintidx
}
pmmdb.DSN.Params = q.Encode()

grafanadb := ds.GrafanaDBSelect
grafanadb.DSN.Scheme = "postgres"
grafanadb.DSN.Host = *postgresAddrF
grafanadb.DSN.DB = "grafana"
grafanadb.DSN.Params = q.Encode()

clickhouseDSN := "tcp://" + *clickhouseAddrF + "/" + *clickHouseDatabaseF

qanDB := ds.QanDBSelect
Expand Down
5 changes: 4 additions & 1 deletion managed/services/config/pmm-managed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ services:
GRAFANADB_SELECT:
enabled: true
timeout: 5s
db_file: /srv/grafana/grafana.db
use_separate_credentials: true
separate_credentials:
username: grafana
password: grafana
Comment on lines -22 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has TODO comment on the top. Can we eliminate its extension and use just plain constants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per TODO, all of them need to be migrated. For the sake of scope and testing, isn't it better to do that in one PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's ok to do that later. Just wanted to get your attention to plans regarding this config.

reporting:
send: true
send_on_start: false
Expand Down
15 changes: 8 additions & 7 deletions managed/services/telemetry/config.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ telemetry:

- id: GrafanaStatDailyActiveUsers
source: GRAFANADB_SELECT
query: count(*) AS count FROM user WHERE last_seen_at > datetime('now', '-1 day')
query: count(*) AS count FROM public.user WHERE last_seen_at > now() - interval '1 day'
summary: "Daily active users"
data:
- metric_name: "pmm_server_grafana_stat_daily_active_users"
Expand Down Expand Up @@ -761,47 +761,47 @@ telemetry:
#Grafana
- id: GrafanaUsersCount
source: GRAFANADB_SELECT
query: count(*) AS count FROM user
query: count(*) AS count FROM public.user
summary: "Grafana Users Count"
data:
- metric_name: "grafana_users_count"
column: "count"

- id: GrafanaDarkThemeUsersCount
source: GRAFANADB_SELECT
query: count(u.id) as count from user u left join preferences p on p.user_id = u.id where p.theme = 'dark'
query: count(u.id) as count from public.user u left join preferences p on p.user_id = u.id where p.theme = 'dark'
summary: "Grafana Dark Theme Users Count"
data:
- metric_name: "grafana_dark_theme_users_count"
column: "count"

- id: GrafanaLightThemeUsersCount
source: GRAFANADB_SELECT
query: count(u.id) as count from user u left join preferences p on p.user_id = u.id where p.theme = 'light'
query: count(u.id) as count from public.user u left join preferences p on p.user_id = u.id where p.theme = 'light'
summary: "Grafana Light Theme Users Count"
data:
- metric_name: "grafana_light_theme_users_count"
column: "count"

- id: GrafanaDefaultThemeUsersCount
source: GRAFANADB_SELECT
query: count(u.id) as count from user u left join preferences p on p.user_id = u.id where p.theme = '' or p.theme is null
query: count(u.id) as count from public.user u left join preferences p on p.user_id = u.id where p.theme = '' or p.theme is null
summary: "Grafana Default Theme Users Count"
data:
- metric_name: "grafana_default_theme_users_count"
column: "count"

- id: GrafanaCustomDashboardsCount
source: GRAFANADB_SELECT
query: count(*) as count from dashboard where created_by != -1 and is_folder = 0
query: count(*) as count from dashboard where created_by != -1 and is_folder = false
summary: "Grafana Custom Dashboards Count"
data:
- metric_name: "grafana_custom_dashboards_count"
column: "count"

- id: GrafanaCustomDashboardsPerPillar
source: GRAFANADB_SELECT
query: inn.title as pillar, count(d.title) as count from dashboard d left join dashboard inn ON d.folder_id = inn.id where d.created_by != -1 and d.is_folder = 0 group by inn.title
query: inn.title as pillar, count(d.title) as count from dashboard d left join dashboard inn ON d.folder_id = inn.id where d.created_by != -1 and d.is_folder = false group by inn.title
summary: "Grafana Custom Dashboards Count By Pillar"
transform:
type: JSON
Expand All @@ -810,6 +810,7 @@ telemetry:
- metric_name: "pillar"
column: "pillar"
- metric_name: "count"
column: "count"

# API usage
- id: APIUsageMetrics
Expand Down
26 changes: 11 additions & 15 deletions managed/services/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type ServiceConfig struct {
telemetry []Config `yaml:"-"`
SaasHostname string `yaml:"saas_hostname"`
DataSources struct {
VM *DataSourceVictoriaMetrics `yaml:"VM"`
QanDBSelect *DSConfigQAN `yaml:"QANDB_SELECT"`
PmmDBSelect *DSConfigPMMDB `yaml:"PMMDB_SELECT"`
GrafanaDBSelect *DSGrafanaSqliteDB `yaml:"GRAFANADB_SELECT"`
VM *DSVictoriaMetrics `yaml:"VM"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

QanDBSelect *DSConfigQAN `yaml:"QANDB_SELECT"`
PmmDBSelect *DSConfigPMMDB `yaml:"PMMDB_SELECT"`
GrafanaDBSelect *DSConfigGrafanaDB `yaml:"GRAFANADB_SELECT"`
} `yaml:"datasources"`
Reporting ReportingConfig `yaml:"reporting"`
}
Expand All @@ -64,32 +64,25 @@ type DSConfigQAN struct {
DSN string `yaml:"-"`
}

// DataSourceVictoriaMetrics telemetry config.
type DataSourceVictoriaMetrics struct {
// DSVictoriaMetrics telemetry config.
type DSVictoriaMetrics struct {
Enabled bool `yaml:"enabled"`
Timeout time.Duration `yaml:"timeout"`
Address string `yaml:"address"`
}

// DSGrafanaSqliteDB telemetry config.
type DSGrafanaSqliteDB struct {
Enabled bool `yaml:"enabled"`
Timeout time.Duration `yaml:"timeout"`
DBFile string `yaml:"db_file"`
}

// DSConfigPMMDB telemetry config.
type DSConfigPMMDB struct { //nolint:musttag
Enabled bool `yaml:"enabled"`
Timeout time.Duration `yaml:"timeout"`
UseSeparateCredentials bool `yaml:"use_separate_credentials"`
// Credentials used by PMM
DSN struct {
DSN struct {
Scheme string
Host string
DB string
Params string
} `yaml:"-"`
// Credentials used by PMM
Credentials struct {
Username string
Password string
Expand All @@ -100,6 +93,9 @@ type DSConfigPMMDB struct { //nolint:musttag
} `yaml:"separate_credentials"`
}

// DSConfigGrafanaDB is a Grafana telemetry config.
type DSConfigGrafanaDB DSConfigPMMDB

// Config telemetry config.
type Config struct {
ID string `yaml:"id"`
Expand Down
30 changes: 20 additions & 10 deletions managed/services/telemetry/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ datasources:
GRAFANADB_SELECT:
enabled: true
timeout: 2s
db_file: /srv/grafana/grafana.db
use_separate_credentials: true
separate_credentials:
username: grafana
password: grafana

reporting:
send: true
Expand All @@ -72,12 +75,12 @@ reporting:
SendTimeout: time.Second * 10,
},
DataSources: struct {
VM *DataSourceVictoriaMetrics `yaml:"VM"`
QanDBSelect *DSConfigQAN `yaml:"QANDB_SELECT"`
PmmDBSelect *DSConfigPMMDB `yaml:"PMMDB_SELECT"`
GrafanaDBSelect *DSGrafanaSqliteDB `yaml:"GRAFANADB_SELECT"`
VM *DSVictoriaMetrics `yaml:"VM"`
QanDBSelect *DSConfigQAN `yaml:"QANDB_SELECT"`
PmmDBSelect *DSConfigPMMDB `yaml:"PMMDB_SELECT"`
GrafanaDBSelect *DSConfigGrafanaDB `yaml:"GRAFANADB_SELECT"`
}{
VM: &DataSourceVictoriaMetrics{
VM: &DSVictoriaMetrics{
Enabled: true,
Timeout: time.Second * 2,
Address: "http://localhost:80/victoriametrics/",
Expand All @@ -98,10 +101,17 @@ reporting:
Password: "pmm-managed",
},
},
GrafanaDBSelect: &DSGrafanaSqliteDB{
Enabled: true,
Timeout: time.Second * 2,
DBFile: "/srv/grafana/grafana.db",
GrafanaDBSelect: &DSConfigGrafanaDB{
Enabled: true,
Timeout: time.Second * 2,
UseSeparateCredentials: true,
SeparateCredentials: struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
}{
Username: "grafana",
Password: "grafana",
},
},
},
}
Expand Down
Loading