Encryption: Add support for multiple data keys per day (#47765)
* Add database migrations * Use short uids as data key ids * Add support for manual data key rotation * Fix duplicated mutex unlocks * Fix migration * Manage current data keys per name * Adjust key re-encryption and test * Modify rename column migration for MySQL compatibility * Refactor secrets manager and data keys cache * Multiple o11y adjustments * Fix stats query * Apply suggestions from code review Co-authored-by: Tania <yalyna.ts@gmail.com> * Fix linter * Docs: Rotate data encryption keys API endpoint Co-authored-by: Tania <yalyna.ts@gmail.com>
This commit is contained in:
co-authored by
Tania
parent
ae8c11bfa4
commit
e43879e55d
@@ -192,7 +192,7 @@ var (
|
||||
StatsTotalLibraryVariables prometheus.Gauge
|
||||
|
||||
// StatsTotalDataKeys is a metric of total number of data keys stored in Grafana.
|
||||
StatsTotalDataKeys prometheus.Gauge
|
||||
StatsTotalDataKeys *prometheus.GaugeVec
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -568,11 +568,11 @@ func init() {
|
||||
Namespace: ExporterName,
|
||||
})
|
||||
|
||||
StatsTotalDataKeys = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
StatsTotalDataKeys = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "stat_totals_data_keys",
|
||||
Help: "total amount of data keys in the database",
|
||||
Namespace: ExporterName,
|
||||
})
|
||||
}, []string{"active"})
|
||||
}
|
||||
|
||||
// SetBuildInformation sets the build information for this binary
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
@@ -139,6 +140,7 @@ func (s *Service) collect(ctx context.Context) (map[string]interface{}, error) {
|
||||
m["stats.folders_viewers_can_admin.count"] = statsQuery.Result.FoldersViewersCanAdmin
|
||||
m["stats.api_keys.count"] = statsQuery.Result.APIKeys
|
||||
m["stats.data_keys.count"] = statsQuery.Result.DataKeys
|
||||
m["stats.active_data_keys.count"] = statsQuery.Result.ActiveDataKeys
|
||||
|
||||
ossEditionCount := 1
|
||||
enterpriseEditionCount := 0
|
||||
@@ -327,7 +329,10 @@ func (s *Service) updateTotalStats(ctx context.Context) bool {
|
||||
metrics.StatsTotalAlertRules.Set(float64(statsQuery.Result.AlertRules))
|
||||
metrics.StatsTotalLibraryPanels.Set(float64(statsQuery.Result.LibraryPanels))
|
||||
metrics.StatsTotalLibraryVariables.Set(float64(statsQuery.Result.LibraryVariables))
|
||||
metrics.StatsTotalDataKeys.Set(float64(statsQuery.Result.DataKeys))
|
||||
|
||||
metrics.StatsTotalDataKeys.With(prometheus.Labels{"active": "true"}).Set(float64(statsQuery.Result.ActiveDataKeys))
|
||||
inactiveDataKeys := statsQuery.Result.DataKeys - statsQuery.Result.ActiveDataKeys
|
||||
metrics.StatsTotalDataKeys.With(prometheus.Labels{"active": "false"}).Set(float64(inactiveDataKeys))
|
||||
|
||||
dsStats := models.GetDataSourceStatsQuery{}
|
||||
if err := s.sqlstore.GetDataSourceStats(ctx, &dsStats); err != nil {
|
||||
|
||||
@@ -281,6 +281,7 @@ func TestCollectingUsageStats(t *testing.T) {
|
||||
assert.EqualValues(t, 1, metrics["stats.distributor.hosted-grafana.count"])
|
||||
|
||||
assert.EqualValues(t, 11, metrics["stats.data_keys.count"])
|
||||
assert.EqualValues(t, 3, metrics["stats.active_data_keys.count"])
|
||||
|
||||
assert.InDelta(t, int64(65), metrics["stats.uptime"], 6)
|
||||
}
|
||||
@@ -325,6 +326,7 @@ func mockSystemStats(sqlStore *mockstore.SQLStoreMock) {
|
||||
FoldersViewersCanEdit: 5,
|
||||
APIKeys: 2,
|
||||
DataKeys: 11,
|
||||
ActiveDataKeys: 3,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user