mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
987bffe482
* initial implementation of csv support for test data source * CSV file & content scenarios working * Removing categorical data * fixing handler names * Update pkg/tsdb/testdatasource/csv_data.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/testdatasource/csv_data.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/testdatasource/csv_data.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/testdatasource/csv_data.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/testdatasource/csv_data.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/testdatasource/csv_data.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/testdatasource/csv_data.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Fixed lint issues * updated so it uses the same parsing * more CSV tests * lint fixes * more lint * lint * support time field * migrate manual entry to csv * more test output * more test output * missing file Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package testdatasource
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
|
"github.com/grafana/grafana/pkg/registry"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
func init() {
|
|
registry.RegisterService(&testDataPlugin{})
|
|
}
|
|
|
|
type testDataPlugin struct {
|
|
BackendPluginManager backendplugin.Manager `inject:""`
|
|
Cfg *setting.Cfg `inject:""`
|
|
logger log.Logger
|
|
scenarios map[string]*Scenario
|
|
queryMux *datasource.QueryTypeMux
|
|
}
|
|
|
|
func (p *testDataPlugin) Init() error {
|
|
p.logger = log.New("tsdb.testdata")
|
|
p.scenarios = map[string]*Scenario{}
|
|
p.queryMux = datasource.NewQueryTypeMux()
|
|
p.registerScenarios()
|
|
resourceMux := http.NewServeMux()
|
|
p.registerRoutes(resourceMux)
|
|
factory := coreplugin.New(backend.ServeOpts{
|
|
QueryDataHandler: p.queryMux,
|
|
CallResourceHandler: httpadapter.New(resourceMux),
|
|
StreamHandler: newTestStreamHandler(p.logger),
|
|
})
|
|
err := p.BackendPluginManager.RegisterAndStart(context.Background(), "testdata", factory)
|
|
if err != nil {
|
|
p.logger.Error("Failed to register plugin", "error", err)
|
|
}
|
|
return nil
|
|
}
|