diff --git a/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.pb.go b/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.pb.go index f8e3939c8..ba4741afd 100644 --- a/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.pb.go +++ b/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.pb.go @@ -748,6 +748,8 @@ type UpdateIndexStatusRequest_Repository struct { Branches []*ZoektRepositoryBranch `protobuf:"bytes,2,rep,name=branches,proto3" json:"branches,omitempty"` // index_time_unix is the unix timestamp for when the index was created. IndexTimeUnix int64 `protobuf:"varint,3,opt,name=index_time_unix,json=indexTimeUnix,proto3" json:"index_time_unix,omitempty"` + // last_index_error is non-empty when the most recent index attempt failed. + LastIndexError string `protobuf:"bytes,4,opt,name=last_index_error,json=lastIndexError,proto3" json:"last_index_error,omitempty"` } func (x *UpdateIndexStatusRequest_Repository) Reset() { @@ -803,6 +805,13 @@ func (x *UpdateIndexStatusRequest_Repository) GetIndexTimeUnix() int64 { return 0 } +func (x *UpdateIndexStatusRequest_Repository) GetLastIndexError() string { + if x != nil { + return x.LastIndexError + } + return "" +} + var File_sourcegraph_zoekt_configuration_v1_configuration_proto protoreflect.FileDescriptor var file_sourcegraph_zoekt_configuration_v1_configuration_proto_rawDesc = []byte{ diff --git a/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.proto b/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.proto index ecd611d70..d2786961e 100644 --- a/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.proto +++ b/cmd/zoekt-sourcegraph-indexserver/grpc/protos/sourcegraph/zoekt/configuration/v1/configuration.proto @@ -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; diff --git a/cmd/zoekt-sourcegraph-indexserver/main.go b/cmd/zoekt-sourcegraph-indexserver/main.go index ad909916d..bc3d21534 100644 --- a/cmd/zoekt-sourcegraph-indexserver/main.go +++ b/cmd/zoekt-sourcegraph-indexserver/main.go @@ -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 } @@ -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 { diff --git a/cmd/zoekt-sourcegraph-indexserver/sg.go b/cmd/zoekt-sourcegraph-indexserver/sg.go index da9b4e2ec..8ebef8601 100644 --- a/cmd/zoekt-sourcegraph-indexserver/sg.go +++ b/cmd/zoekt-sourcegraph-indexserver/sg.go @@ -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 { @@ -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, }) } @@ -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(), }) }