The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/export/export_kv_store.go

46 lines
995 B

package export
import (
"fmt"
"path"
"time"
"github.com/grafana/grafana/pkg/infra/db"
)
func exportKVStore(helper *commitHelper, job *gitExportJob) error {
kvdir := path.Join(helper.orgDir, "system", "kv_store")
return job.sql.WithDbSession(helper.ctx, func(sess *db.Session) error {
type kvResult struct {
Namespace string `xorm:"namespace"`
Key string `xorm:"key"`
Value string `xorm:"value"`
Updated time.Time `xorm:"updated"`
}
rows := make([]*kvResult, 0)
sess.Table("kv_store").Where("org_id = ? OR org_id = 0", helper.orgID)
err := sess.Find(&rows)
if err != nil {
return err
}
for _, row := range rows {
err = helper.add(commitOptions{
body: []commitBody{{
body: []byte(row.Value),
fpath: path.Join(kvdir, row.Namespace, row.Key),
}},
comment: fmt.Sprintf("Exporting: %s/%s", row.Namespace, row.Key),
when: row.Updated,
})
if err != nil {
return err
}
}
return err
})
}