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

Storage: Unified Storage based on Entity API #71977

Merged
merged 27 commits into from
Dec 6, 2023
Merged

Storage: Unified Storage based on Entity API #71977

merged 27 commits into from
Dec 6, 2023

Conversation

DanCech
Copy link
Collaborator

@DanCech DanCech commented Jul 19, 2023

This PR explores running entity api against a separate dedicated database, and the changes needed to support alternative databases beyond sqlite/mysql/postgres.

It requires some configuration to be able to exercise it:

app_mode = development
target = all

[feature_toggles]
unifiedStorage = true
grafanaAPIServer = true
kubernetesPlaylists = true
idForwarding = true

[grafana-apiserver]
storage_type = unified

[entity_api]
db_type = mysql
db_host = localhost:3306
db_name = grafana
db_user = grafanauser
db_pass = grafanapass

With this configuration, you can run everything in-process with:

bra run

The default kubeconfig sends requests directly to the apiserver, to authenticate as a grafana user, create grafana.kubeconfig:

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://127.0.0.1:3000
  name: default-cluster
contexts:
- context:
    cluster: default-cluster
    namespace: default
    user: default
  name: default-context
current-context: default-context
kind: Config
preferences: {}
users:
- name: default
  user:
    username: <username>
    password: <password>

Where <username> and <password> are credentials for basic auth against Grafana.

In this mode, you can interact with the k8s api via:

kubectl --kubeconfig=./grafana.kubeconfig get playlist

To create a playlist, create a file playlist-generate.yaml:

apiVersion: playlist.grafana.app/v0alpha1
kind: Playlist
metadata:
  generateName: x # anything is ok here... except yes or true -- they become boolean!
  labels:
    foo: bar
spec:
  title: Playlist with auto generated UID
  interval: 5m
  items:
  - type: dashboard_by_tag
    value: panel-tests
  - type: dashboard_by_uid
    value: vmie2cmWz # dashboard from devenv

then run:

kubectl --kubeconfig=./grafana.kubeconfig create -f playlist-generate.yaml

To run with a separate storage api using grpc, first update conf/custom.ini and set:

[grafana-apiserver]
storage_type = unified-grpc

Start the storage-apiserver with:

GF_DEFAULT_TARGET=storage-apiserver ./bin/grafana server target

Then in another session start the grafana server:

bra run

Finally, you can list the previously-created playlists with:

kubectl --kubeconfig=./grafana.kubeconfig get playlist

pkg/services/grafana-apiserver/storage.go Outdated Show resolved Hide resolved
pkg/services/grafana-apiserver/storage.go Outdated Show resolved Hide resolved
pkg/services/grafana-apiserver/storage.go Outdated Show resolved Hide resolved
pkg/services/grafana-apiserver/storage.go Outdated Show resolved Hide resolved
pkg/services/grafana-apiserver/storage.go Outdated Show resolved Hide resolved
pkg/services/grafana-apiserver/storage.go Outdated Show resolved Hide resolved
pkg/services/grafana-apiserver/storage.go Outdated Show resolved Hide resolved
@DanCech DanCech force-pushed the entityapi-database branch 3 times, most recently from e937d2b to 27efbc4 Compare October 11, 2023 14:10
@DanCech DanCech force-pushed the entityapi-database branch 2 times, most recently from ce37f9a to 06ccd14 Compare October 30, 2023 16:05
@DanCech DanCech force-pushed the entityapi-database branch 2 times, most recently from b6946a1 to 089935b Compare November 2, 2023 20:45
go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@DanCech DanCech changed the title EntityAPI database Storage: Unified Storage based on Entity API Dec 6, 2023
@@ -47,7 +47,7 @@ func newConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles) *config {

return &config{
enabled: features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServer),
devMode: cfg.Env == setting.Dev,
devMode: features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerEnsureKubectlAccess),
Copy link
Member

Choose a reason for hiding this comment

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

@toddtreece @grafana/grafana-app-platform-squad -- this changes the behavior for when we auto-start the extra kubectl port.

This now requires a feature flag (and dev mode) rather than just dev mode. This change was required to simplify the integration test setup, but I think is generally better anyway.

Copy link
Member

Choose a reason for hiding this comment

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

the README probably also needs to be updated with this info for kubectl access

Copy link
Member

Choose a reason for hiding this comment

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

good call -- updated

@@ -222,10 +222,11 @@ var (
Created: time.Date(2022, time.September, 27, 12, 0, 0, 0, time.UTC),
},
{
Name: "entityStore",
Description: "SQL-based entity store (requires storage flag also)",
Name: "unifiedStorage",
Copy link
Member

Choose a reason for hiding this comment

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

@DanCech -- i renamed this while we are here futzing with feature flags. In general we will want to clear all reference to "entity" but after merging :)

@DanCech DanCech merged commit c4c9bfa into main Dec 6, 2023
19 checks passed
@DanCech DanCech deleted the entityapi-database branch December 6, 2023 20:21
@aangelisc aangelisc modified the milestones: 10.3.x, 10.2.3 Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants