mirror of
https://github.com/grafana/grafana.git
synced 2025-01-13 09:32:12 -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/pkg/cmd/grafana/",
|
||||
"env": {
|
||||
"GF_DEFAULT_TARGET": "storage-server"
|
||||
},
|
||||
"env": {"GF_DEFAULT_TARGET": "storage-server","GF_SERVER_HTTP_PORT": "3001"},
|
||||
"cwd": "${workspaceFolder}",
|
||||
"args": ["server", "target", "--homepath", "${workspaceFolder}", "--packaging", "dev"]
|
||||
},
|
||||
|
@ -8,18 +8,20 @@ import (
|
||||
|
||||
"github.com/grafana/dskit/services"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
type instrumentationService struct {
|
||||
*services.BasicService
|
||||
cfg *setting.Cfg
|
||||
httpServ *http.Server
|
||||
log log.Logger
|
||||
errChan chan error
|
||||
}
|
||||
|
||||
func NewInstrumentationService(log log.Logger) (*instrumentationService, error) {
|
||||
s := &instrumentationService{log: log}
|
||||
func NewInstrumentationService(log log.Logger, cfg *setting.Cfg) (*instrumentationService, error) {
|
||||
s := &instrumentationService{log: log, cfg: cfg}
|
||||
s.BasicService = services.NewBasicService(s.start, s.running, s.stop)
|
||||
return s, nil
|
||||
}
|
||||
@ -59,7 +61,7 @@ func (s *instrumentationService) newInstrumentationServer(ctx context.Context) *
|
||||
srv := &http.Server{
|
||||
// 5s timeout for header reads to avoid Slowloris attacks (https://thetooth.io/blog/slowloris-attack/)
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
Addr: ":3000", // TODO - make configurable?
|
||||
Addr: ":" + s.cfg.HTTPPort,
|
||||
Handler: router,
|
||||
BaseContext: func(_ net.Listener) context.Context { return ctx },
|
||||
}
|
||||
|
@ -9,13 +9,16 @@ import (
|
||||
|
||||
"github.com/grafana/dskit/services"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
|
||||
@ -35,7 +38,7 @@ func TestRunInstrumentationService(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
client := http.Client{}
|
||||
res, err := client.Get("http://localhost:3000/metrics")
|
||||
res, err := client.Get("http://localhost:3001/metrics")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 200, res.StatusCode)
|
||||
|
||||
|
@ -113,7 +113,7 @@ func (s *ModuleServer) Run() error {
|
||||
if m.IsModuleEnabled(modules.All) || m.IsModuleEnabled(modules.Core) {
|
||||
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) {
|
||||
|
@ -34,6 +34,7 @@ func TestIntegrationWillRunInstrumentationServerWhenTargetHasNoHttpServer(t *tes
|
||||
}
|
||||
|
||||
_, cfg := db.InitTestDBWithCfg(t)
|
||||
cfg.HTTPPort = "3001"
|
||||
cfg.GRPCServerNetwork = "tcp"
|
||||
cfg.GRPCServerAddress = "localhost:10000"
|
||||
addStorageServerToConfig(t, cfg, dbType)
|
||||
@ -51,7 +52,7 @@ func TestIntegrationWillRunInstrumentationServerWhenTargetHasNoHttpServer(t *tes
|
||||
time.Sleep(500 * time.Millisecond) // wait for http server to be running
|
||||
|
||||
client := http.Client{}
|
||||
res, err := client.Get("http://localhost:3000/metrics")
|
||||
res, err := client.Get("http://localhost:3001/metrics")
|
||||
require.NoError(t, err)
|
||||
err = res.Body.Close()
|
||||
require.NoError(t, err)
|
||||
|
Loading…
Reference in New Issue
Block a user