jaegertracing/jaeger · error

failed to get latest index: %w

Error message

failed to get latest index: %w

What it means

GetLatestProbabilities in the Elasticsearch sampling store wraps any failure from getLatestIndex with this message. getLatestIndex iterates the rotation-eligible index candidates within the lookback window and returns an error if none exist or the existence check itself fails. The wrapper preserves the underlying cause via %w so callers can inspect it with errors.Is/As.

Source

Thrown at internal/storage/v1/elasticsearch/samplingstore/storage.go:126

func (s *SamplingStore) InsertProbabilitiesAndQPS(hostname string,
	probabilities model.ServiceOperationProbabilities,
	qps model.ServiceOperationQPS,
) error {
	ts := s.now()
	writeIndexName := s.rotation.WriteTarget(ts)
	val := dbmodel.ProbabilitiesAndQPS{
		Hostname:      hostname,
		Probabilities: probabilities,
		QPS:           qps,
	}
	return s.writeProbabilitiesAndQPS(writeIndexName, ts, val)
}

func (s *SamplingStore) GetLatestProbabilities() (model.ServiceOperationProbabilities, error) {
	ctx := context.Background()
	index, err := s.getLatestIndex(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to get latest index: %w", err)
	}
	searchResult, err := s.searcher.Search(ctx, []string{index}, esclient.SearchRequest{
		Size: s.maxDocCount,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to search for Latest Probabilities: %w", err)
	}
	lengthOfSearchResult := len(searchResult.Hits.Hits)
	if lengthOfSearchResult == 0 {
		return nil, nil
	}

	var latestProbabilities dbmodel.TimeProbabilitiesAndQPS
	latestTime := time.Time{}
	for _, hit := range searchResult.Hits.Hits {
		var data dbmodel.TimeProbabilitiesAndQPS
		if err = json.Unmarshal(hit.Source, &data); err != nil {
			return nil, fmt.Errorf("unmarshalling documents failed: %w", err)

View on GitHub (pinned to 806f444784)

Solutions

  1. Verify Elasticsearch connectivity and credentials (curl the cluster health endpoint using the configured addresses).
  2. Check that sampling data has been written at least once so an index exists; inspect index names with GET /_cat/indices.
  3. Align lookback/rotation/prefix configuration so candidates cover the indices actually present.
  4. Inspect the wrapped cause with errors.Unwrap to distinguish 'no index found' from an ES client error.

Example fix

// before
idx, err := store.GetLatestProbabilities()
// after
if err != nil {
  if strings.Contains(err.Error(), "failed to find latest index") {
    // fall back to default probabilities; no sampling index yet
  } else {
    log.Fatal(err) // real ES connectivity problem
  }
}
Defensive patterns

Strategy: fallback

Validate before calling

if err != nil {
  if strings.Contains(err.Error(), "failed to find latest index") {
    probs = defaultProbabilities // no index yet
  }
}

Try / catch

probs, err := store.GetLatestProbabilities()
if err != nil {
  log.Printf("sampling probabilities unavailable: %v", err)
  probs = defaultProbabilities
}

Prevention

When it happens

Trigger: Calling GetLatestProbabilities when no sampling index for the current rotation window exists, or when IndexExists returns a transport/cluster error (e.g. ES down, bad URL, auth failure) for every candidate index.

Common situations: Elasticsearch unreachable or misconfigured (wrong addresses/credentials); the sampling index was never created because the collector has not written any sampling data yet; lookback/rotation settings point at a date range with no indices; index name prefix changed between versions.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/fb551fd8fe552e1c. Report an issue: GitHub.