mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
VSCode: Launch Grafana with Storage server (#88351)
* VSCode: Launch Grafana with Storage server * Fix module_server_test
This commit is contained in:
parent
1f90123f35
commit
5eecc01123
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@ -38,15 +38,23 @@
|
|||||||
"--hg-key=$HGAPIKEY"
|
"--hg-key=$HGAPIKEY"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Run Server (query GRPC Storage Server)",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}/pkg/cmd/grafana/",
|
||||||
|
"env": {"GF_GRAFANA_APISERVER_STORAGE_TYPE": "unified-grpc"},
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"args": ["server", "--homepath", "${workspaceFolder}", "--packaging", "dev"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Run Storage Server",
|
"name": "Run Storage Server",
|
||||||
"type": "go",
|
"type": "go",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"program": "${workspaceFolder}/pkg/cmd/grafana/",
|
"program": "${workspaceFolder}/pkg/cmd/grafana/",
|
||||||
"env": {
|
"env": {"GF_DEFAULT_TARGET": "storage-server","GF_SERVER_HTTP_PORT": "3001"},
|
||||||
"GF_DEFAULT_TARGET": "storage-server"
|
|
||||||
},
|
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"args": ["server", "target", "--homepath", "${workspaceFolder}", "--packaging", "dev"]
|
"args": ["server", "target", "--homepath", "${workspaceFolder}", "--packaging", "dev"]
|
||||||
},
|
},
|
||||||
|
@ -8,18 +8,20 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/dskit/services"
|
"github.com/grafana/dskit/services"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type instrumentationService struct {
|
type instrumentationService struct {
|
||||||
*services.BasicService
|
*services.BasicService
|
||||||
|
cfg *setting.Cfg
|
||||||
httpServ *http.Server
|
httpServ *http.Server
|
||||||
log log.Logger
|
log log.Logger
|
||||||
errChan chan error
|
errChan chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInstrumentationService(log log.Logger) (*instrumentationService, error) {
|
func NewInstrumentationService(log log.Logger, cfg *setting.Cfg) (*instrumentationService, error) {
|
||||||
s := &instrumentationService{log: log}
|
s := &instrumentationService{log: log, cfg: cfg}
|
||||||
s.BasicService = services.NewBasicService(s.start, s.running, s.stop)
|
s.BasicService = services.NewBasicService(s.start, s.running, s.stop)
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
@ -59,7 +61,7 @@ func (s *instrumentationService) newInstrumentationServer(ctx context.Context) *
|
|||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
// 5s timeout for header reads to avoid Slowloris attacks (https://thetooth.io/blog/slowloris-attack/)
|
// 5s timeout for header reads to avoid Slowloris attacks (https://thetooth.io/blog/slowloris-attack/)
|
||||||
ReadHeaderTimeout: 5 * time.Second,
|
ReadHeaderTimeout: 5 * time.Second,
|
||||||
Addr: ":3000", // TODO - make configurable?
|
Addr: ":" + s.cfg.HTTPPort,
|
||||||
Handler: router,
|
Handler: router,
|
||||||
BaseContext: func(_ net.Listener) context.Context { return ctx },
|
BaseContext: func(_ net.Listener) context.Context { return ctx },
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,16 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/dskit/services"
|
"github.com/grafana/dskit/services"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunInstrumentationService(t *testing.T) {
|
func TestRunInstrumentationService(t *testing.T) {
|
||||||
s, err := NewInstrumentationService(log.New("test-logger"))
|
cfg := setting.NewCfg()
|
||||||
|
cfg.HTTPPort = "3001"
|
||||||
|
s, err := NewInstrumentationService(log.New("test-logger"), cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
|
||||||
@ -35,7 +38,7 @@ func TestRunInstrumentationService(t *testing.T) {
|
|||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
res, err := client.Get("http://localhost:3000/metrics")
|
res, err := client.Get("http://localhost:3001/metrics")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 200, res.StatusCode)
|
assert.Equal(t, 200, res.StatusCode)
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ func (s *ModuleServer) Run() error {
|
|||||||
if m.IsModuleEnabled(modules.All) || m.IsModuleEnabled(modules.Core) {
|
if m.IsModuleEnabled(modules.All) || m.IsModuleEnabled(modules.Core) {
|
||||||
return services.NewBasicService(nil, nil, nil).WithName(modules.InstrumentationServer), nil
|
return services.NewBasicService(nil, nil, nil).WithName(modules.InstrumentationServer), nil
|
||||||
}
|
}
|
||||||
return NewInstrumentationService(s.log)
|
return NewInstrumentationService(s.log, s.cfg)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.RegisterModule(modules.Core, func() (services.Service, error) {
|
m.RegisterModule(modules.Core, func() (services.Service, error) {
|
||||||
|
@ -34,6 +34,7 @@ func TestIntegrationWillRunInstrumentationServerWhenTargetHasNoHttpServer(t *tes
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, cfg := db.InitTestDBWithCfg(t)
|
_, cfg := db.InitTestDBWithCfg(t)
|
||||||
|
cfg.HTTPPort = "3001"
|
||||||
cfg.GRPCServerNetwork = "tcp"
|
cfg.GRPCServerNetwork = "tcp"
|
||||||
cfg.GRPCServerAddress = "localhost:10000"
|
cfg.GRPCServerAddress = "localhost:10000"
|
||||||
addStorageServerToConfig(t, cfg, dbType)
|
addStorageServerToConfig(t, cfg, dbType)
|
||||||
@ -51,7 +52,7 @@ func TestIntegrationWillRunInstrumentationServerWhenTargetHasNoHttpServer(t *tes
|
|||||||
time.Sleep(500 * time.Millisecond) // wait for http server to be running
|
time.Sleep(500 * time.Millisecond) // wait for http server to be running
|
||||||
|
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
res, err := client.Get("http://localhost:3000/metrics")
|
res, err := client.Get("http://localhost:3001/metrics")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = res.Body.Close()
|
err = res.Body.Close()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user