Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ message UpdateIndexStatusRequest {

// index_time_unix is the unix timestamp for when the index was created.
int64 index_time_unix = 3;

// last_index_error is non-empty when the most recent index attempt failed.
// An empty string means the attempt succeeded.
string last_index_error = 4;
}

repeated Repository repositories = 1;
Expand Down
20 changes: 20 additions & 0 deletions cmd/zoekt-sourcegraph-indexserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ func (s *Server) index(ctx context.Context, args *indexArgs) (state indexState,

err = gitIndex(ctx, c, args, s.Sourcegraph, s.logger)
if err != nil {
reportIndexFailureToSourcegraph(args, s.Sourcegraph, err, s.logger)
return indexStateFail, err
}

Expand All @@ -692,6 +693,25 @@ func (s *Server) index(ctx context.Context, args *indexArgs) (state indexState,
return indexStateSuccess, nil
}

// reportIndexFailureToSourcegraph sends the error message of a failed index
// attempt to Sourcegraph via UpdateIndexStatus so it can be persisted.
// Any error is logged but not propagated — this is best-effort.
func reportIndexFailureToSourcegraph(args *indexArgs, sg Sourcegraph, indexErr error, logger sglog.Logger) {
status := []indexStatus{{
RepoID: args.RepoID,
LastIndexError: indexErr.Error(),
// Branches and IndexTimeUnix intentionally zero:
// the index did not complete so there is no new shard data.
}}
if err := sg.UpdateIndexStatus(status); err != nil {
logger.Error("failed to report index failure to sourcegraph",
sglog.String("repo", args.Name),
sglog.Uint32("id", args.RepoID),
sglog.Error(err),
)
}
}

// updateIndexStatusOnSourcegraph pushes the current state to sourcegraph so
// it can update the zoekt_repos table.
func updateIndexStatusOnSourcegraph(c gitIndexConfig, args *indexArgs, sg Sourcegraph) error {
Expand Down
21 changes: 12 additions & 9 deletions cmd/zoekt-sourcegraph-indexserver/sg.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,10 @@ func (s *sourcegraphClient) listRepoIDs(ctx context.Context, indexed []uint32) (
}

type indexStatus struct {
RepoID uint32
Branches []zoekt.RepositoryBranch
IndexTimeUnix int64
RepoID uint32
Branches []zoekt.RepositoryBranch
IndexTimeUnix int64
LastIndexError string
}

type updateIndexStatusRequest struct {
Expand All @@ -392,9 +393,10 @@ func (u *updateIndexStatusRequest) ToProto() *configv1.UpdateIndexStatusRequest
}

repositories = append(repositories, &configv1.UpdateIndexStatusRequest_Repository{
RepoId: repo.RepoID,
Branches: branches,
IndexTimeUnix: repo.IndexTimeUnix,
RepoId: repo.RepoID,
Branches: branches,
IndexTimeUnix: repo.IndexTimeUnix,
LastIndexError: repo.LastIndexError,
})
}

Expand All @@ -419,9 +421,10 @@ func (u *updateIndexStatusRequest) FromProto(x *configv1.UpdateIndexStatusReques
}

repositories = append(repositories, indexStatus{
RepoID: repo.GetRepoId(),
Branches: branches,
IndexTimeUnix: repo.GetIndexTimeUnix(),
RepoID: repo.GetRepoId(),
Branches: branches,
IndexTimeUnix: repo.GetIndexTimeUnix(),
LastIndexError: repo.GetLastIndexError(),
})
}

Expand Down
Loading