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

Brojd/backend plugin #4333

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ cluster/up: ## (beta) create a local development k8s cluster
cluster/down: ## (beta) delete local development k8s cluster
ctlptl delete -f dev/kind-config.yaml

# .PHONY: build/plugin-backend
# build/plugin-backend:
# ifeq ("$(wildcard grafana-plugin/Magefile.go)","grafana-plugin/Magefile.go")
# @cd grafana-plugin && go list -f '{{.Dir}}||{{.Name}}' github.com/grafana/grafana-plugin-sdk-go/build
# @cd grafana-plugin && mage -v
# @cd grafana-plugin && mage reloadPlugin
# else
# @echo "No Magefile.go found, skipping backend build"
# endif

start: ## start all of the docker containers
$(call run_docker_compose_command,up --remove-orphans -d)

Expand Down
27 changes: 25 additions & 2 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if not running_under_parent_tiltfile:
# Load the custom Grafana extensions
v1alpha1.extension_repo(
name="grafana-tilt-extensions",
ref="v1.2.0",
ref="v1.4.2",
url="https://github.com/grafana/tilt-extensions",
)
v1alpha1.extension(
Expand Down Expand Up @@ -67,6 +67,24 @@ local_resource(
allow_parallel=True,
)


local_resource(
'build-plugin-backend',
labels=["pluginBackend"],
dir="./grafana-plugin",
cmd="mage buildAll",
deps=['grafana-plugin/pkg/plugin']
)

local_resource(
'restart-plugin-backend',
labels=["pluginBackend"],
dir="./dev/grafana",
cmd="chmod +x ./restart_backend_plugin.sh && ./restart_backend_plugin.sh",
resource_deps=["grafana", "build-plugin-backend"],
deps=['grafana-plugin/pkg/plugin']
)

local_resource(
"e2e-tests",
labels=["E2eTests"],
Expand Down Expand Up @@ -141,12 +159,17 @@ if not running_under_parent_tiltfile:
context="grafana-plugin",
plugin_files=["grafana-plugin/src/plugin.json"],
namespace="default",
deps=["grafana-oncall-app-provisioning-configmap", "build-ui", "engine"],
# deps=["grafana-oncall-app-provisioning-configmap", "build-ui", "engine", "build-plugin-backend"],
extra_env={
"GF_SECURITY_ADMIN_PASSWORD": "oncall",
"GF_SECURITY_ADMIN_USER": "oncall",
"GF_AUTH_ANONYMOUS_ENABLED": "false",
"GF_FEATURE_TOGGLES_ENABLE": "externalServiceAccounts",
"GF_DEFAULT_APP_MODE": "development"
},
extra_grafana_ini={
"app_mode": "development"
}
)

k8s_resource(
Expand Down
4 changes: 2 additions & 2 deletions dev/helm-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ celery:
worker_beat_enabled: false

externalGrafana:
url: http://grafana:3000
url: http://localhost:3000

grafana:
enabled: false
Expand Down Expand Up @@ -62,7 +62,7 @@ grafana:
- name: DATABASE_PASSWORD
value: oncallpassword
env:
GF_FEATURE_TOGGLES_ENABLE: topnav
GF_FEATURE_TOGGLES_ENABLE: topnav,externalServiceAccounts
GF_SECURITY_ADMIN_PASSWORD: oncall
GF_SECURITY_ADMIN_USER: oncall
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: grafana-oncall-app
Expand Down
4 changes: 4 additions & 0 deletions engine/apps/auth_token/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ApiTokenAuthentication(BaseAuthentication):

def authenticate(self, request):
auth = get_authorization_header(request).decode("utf-8")
print("AUTH_HERE", auth)
user, auth_token = self.authenticate_credentials(auth)

if not user_is_authorized(user, [RBACPermission.Permissions.API_KEYS_WRITE]):
Expand All @@ -62,6 +63,7 @@ def authenticate_credentials(self, token):
Due to the random nature of hashing a value, this must inspect
each auth_token individually to find the correct one.
"""
print("TOKEN_HERE", token)
try:
auth_token = self.model.validate_token_string(token)
except InvalidToken:
Expand Down Expand Up @@ -109,6 +111,7 @@ def authenticate_credentials(self, token_string: str, request: Request) -> typin

try:
auth_token = check_token(token_string, context=context)
print("AUTH_TOKEN_HERE: ", token_string)
if not auth_token.organization:
raise exceptions.AuthenticationFailed("No organization associated with token.")
except InvalidToken:
Expand Down Expand Up @@ -158,6 +161,7 @@ def _get_user(request: Request, organization: Organization) -> User:
user_id = context["UserID"]

try:
print("ORG_USERS_HERE", organization.users)
return organization.users.get(user_id=user_id)
except User.DoesNotExist:
logger.debug(f"Could not get user from grafana request. Context {context}")
Expand Down
11 changes: 10 additions & 1 deletion engine/apps/grafana_plugin/views/self_hosted_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class SelfHostedInstallView(GrafanaHeadersMixin, APIView):
def post(self, _request: Request) -> Response:
def post(self, req: Request) -> Response:
"""
We've already validated that settings.GRAFANA_API_URL is set (in apps.grafana_plugin.GrafanaPluginConfig)
The user is now trying to finish plugin installation. We'll take the Grafana API url that they specified +
Expand All @@ -21,8 +21,14 @@ def post(self, _request: Request) -> Response:
stack_id = settings.SELF_HOSTED_SETTINGS["STACK_ID"]
org_id = settings.SELF_HOSTED_SETTINGS["ORG_ID"]
grafana_url = settings.SELF_HOSTED_SETTINGS["GRAFANA_API_URL"]

print("REQ_HERE", req.headers)
print("INST_CONT", self.instance_context)

grafana_api_token = self.instance_context["grafana_token"]

print("GRAFANA_TOKEN_HERE", grafana_api_token)

provisioning_info = {"error": None}

if settings.LICENSE != settings.OPEN_SOURCE_LICENSE_NAME:
Expand All @@ -31,6 +37,9 @@ def post(self, _request: Request) -> Response:

grafana_api_client = GrafanaAPIClient(api_url=grafana_url, api_token=grafana_api_token)
_, client_status = grafana_api_client.check_token()

print("client_status", client_status)

status_code = client_status["status_code"]

if status_code == status.HTTP_404_NOT_FOUND:
Expand Down
2 changes: 1 addition & 1 deletion engine/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ class BrokerTypes:
"ORG_SLUG": os.environ.get("SELF_HOSTED_ORG_SLUG", "self_hosted_org"),
"ORG_TITLE": os.environ.get("SELF_HOSTED_ORG_TITLE", "Self-Hosted Organization"),
"REGION_SLUG": os.environ.get("SELF_HOSTED_REGION_SLUG", "self_hosted_region"),
"GRAFANA_API_URL": os.environ.get("GRAFANA_API_URL", default=None),
"GRAFANA_API_URL": os.environ.get("GRAFANA_API_URL", "http://localhost:3000"),
"CLUSTER_SLUG": os.environ.get("SELF_HOSTED_CLUSTER_SLUG", "self_hosted_cluster"),
}

Expand Down
12 changes: 12 additions & 0 deletions grafana-plugin/Magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build mage
// +build mage

package main

import (
// mage:import
build "github.com/grafana/grafana-plugin-sdk-go/build"
)

// Default configures the default target.
var Default = build.BuildAll
89 changes: 89 additions & 0 deletions grafana-plugin/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module github.com/grafana-labs/grafana-oncall-app

go 1.21

require github.com/grafana/grafana-plugin-sdk-go v0.228.0

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/apache/arrow/go/v15 v15.0.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/chromedp/cdproto v0.0.0-20220208224320-6efb837e6bc2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/elazarl/goproxy v0.0.0-20230731152917-f99041a5c027 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/getkin/kin-openapi v0.124.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/flatbuffers v23.5.26+incompatible // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/magefile/mage v1.15.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattetti/filebuffer v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/unknwon/bra v0.0.0-20200517080246-1e3013ecaff8 // indirect
github.com/unknwon/com v1.0.1 // indirect
github.com/unknwon/log v0.0.0-20150304194804-e617c87089d3 // indirect
github.com/urfave/cli v1.22.15 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.51.0 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.26.0 // indirect
go.opentelemetry.io/contrib/samplers/jaegerremote v0.20.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.26.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/sdk v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)