Skip to content
Snippets Groups Projects

Full MVC of gitlab-zoekt-indexer

Merged Dylan Griffith requested to merge add-new-api-paths into main
All threads resolved!
Compare and Show latest version
4 files
+ 43
24
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -18,6 +18,7 @@ import (
@@ -18,6 +18,7 @@ import (
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/client_golang/prometheus/promhttp"
 
"gitlab.com/gitlab-org/search-team/gitlab-zoekt-indexer/correlation"
"gitlab.com/gitlab-org/search-team/gitlab-zoekt-indexer/indexer"
"gitlab.com/gitlab-org/search-team/gitlab-zoekt-indexer/indexer"
)
)
@@ -28,6 +29,7 @@ type options struct {
@@ -28,6 +29,7 @@ type options struct {
type indexServer struct {
type indexServer struct {
indexDir string
indexDir string
 
indexBuilder indexBuilder
promRegistry *prometheus.Registry
promRegistry *prometheus.Registry
metricsRequestsTotal *prometheus.CounterVec
metricsRequestsTotal *prometheus.CounterVec
}
}
@@ -46,7 +48,21 @@ type indexRequest struct {
@@ -46,7 +48,21 @@ type indexRequest struct {
FileSizeLimit int
FileSizeLimit int
}
}
func (s *indexServer) indexRepository(req indexRequest, ctx context.Context) error {
type indexBuilder interface {
 
indexRepository(ctx context.Context, req indexRequest, indexDir string) error
 
}
 
 
type defaultIndexBuilder struct{}
 
 
func (b defaultIndexBuilder) indexRepository(ctx context.Context, req indexRequest, indexDir string) error {
 
if req.GitalyConnectionInfo == nil {
 
return errors.New("gitalyConnectionInfo is not set")
 
}
 
 
if req.FileSizeLimit == 0 {
 
return errors.New("fileSizeLimit is not set")
 
}
 
timeout, err := time.ParseDuration(req.Timeout)
timeout, err := time.ParseDuration(req.Timeout)
if err != nil {
if err != nil {
return fmt.Errorf("failed to parse Timeout: %v with error %v", req.Timeout, err)
return fmt.Errorf("failed to parse Timeout: %v with error %v", req.Timeout, err)
@@ -56,9 +72,9 @@ func (s *indexServer) indexRepository(req indexRequest, ctx context.Context) err
@@ -56,9 +72,9 @@ func (s *indexServer) indexRepository(req indexRequest, ctx context.Context) err
defer cancel()
defer cancel()
idx := &indexer.Indexer{
idx := &indexer.Indexer{
IndexDir: s.indexDir,
IndexDir: indexDir,
ProjectID: req.RepoID,
ProjectID: req.RepoID,
CorrelationID: getCorrelationID(ctx),
CorrelationID: correlation.GetCorrelationID(ctx),
GitalyAddress: req.GitalyConnectionInfo.Address,
GitalyAddress: req.GitalyConnectionInfo.Address,
GitalyStorageName: req.GitalyConnectionInfo.Storage,
GitalyStorageName: req.GitalyConnectionInfo.Storage,
GitalyRelativePath: req.GitalyConnectionInfo.Path,
GitalyRelativePath: req.GitalyConnectionInfo.Path,
@@ -148,14 +164,6 @@ func (s *indexServer) handleIndex() http.HandlerFunc {
@@ -148,14 +164,6 @@ func (s *indexServer) handleIndex() http.HandlerFunc {
return req, errors.New("json parser error")
return req, errors.New("json parser error")
}
}
if req.GitalyConnectionInfo == nil {
return req, errors.New("gitalyConnectionInfo Error")
}
if req.FileSizeLimit == 0 {
return req, errors.New("fileSizeLimit is not set")
}
return req, nil
return req, nil
}
}
@@ -166,7 +174,7 @@ func (s *indexServer) handleIndex() http.HandlerFunc {
@@ -166,7 +174,7 @@ func (s *indexServer) handleIndex() http.HandlerFunc {
return
return
}
}
err = s.indexRepository(req, r.Context())
err = s.indexBuilder.indexRepository(r.Context(), req, s.indexDir)
if err != nil {
if err != nil {
s.respondWithError(w, r, route, err)
s.respondWithError(w, r, route, err)
return
return
@@ -296,7 +304,8 @@ func main() {
@@ -296,7 +304,8 @@ func main() {
opts := parseOptions()
opts := parseOptions()
server := indexServer{
server := indexServer{
indexDir: opts.indexDir,
indexDir: opts.indexDir,
 
indexBuilder: defaultIndexBuilder{},
}
}
server.startIndexingApi(opts.listen)
server.startIndexingApi(opts.listen)
Loading