Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 7.x] Fix global checkpoint based monitoring #117

Merged
Merged
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
21 changes: 20 additions & 1 deletion internal/pkg/monitor/global_checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ package monitor
import (
"context"
"encoding/json"
"errors"
"fmt"

"github.com/elastic/fleet-server/v7/internal/pkg/es"

"github.com/elastic/go-elasticsearch/v8"
)

var ErrGlobalCheckpoint = errors.New("global checkpoint error")

type shard struct {
SeqNo struct {
GlobalCheckpoint int64 `json:"global_checkpoint"`
Expand Down Expand Up @@ -49,7 +54,21 @@ func queryGlobalCheckpoint(ctx context.Context, es *elasticsearch.Client, index
return
}

if stats, ok := sres.IndexStats[index]; ok {
if len(sres.IndexStats) > 1 {
indices := make([]string, 0, len(sres.IndexStats))
for k := range sres.IndexStats {
indices = append(indices, k)
}
return seqno, fmt.Errorf("more than one indices found %v, %w", indices, ErrGlobalCheckpoint)
}

if len(sres.IndexStats) > 0 {
// Grab the first and only index stats
var stats indexStats
for _, stats = range sres.IndexStats {
break
}

if shards, ok := stats.Shards["0"]; ok {
if len(shards) > 0 {
seqno = shards[0].SeqNo.GlobalCheckpoint
Expand Down