Skip to content

Commit

Permalink
Merge pull request #4185 from guardian/image-counter-lambda/uploadedI…
Browse files Browse the repository at this point in the history
…nLastFiveMinutes
  • Loading branch information
twrichards authored Nov 14, 2023
2 parents a6febb6 + e3a5ec8 commit a365d74
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}

case class ElasticSearchImageCounts(catCount: Long,
searchResponseCount: Long,
indexStatsCount: Long)
case class ElasticSearchImageCounts(
catCount: Long,
searchResponseCount: Long,
indexStatsCount: Long,
uploadedInLastFiveMinutes: Long
)

trait ElasticSearchClient extends ElasticSearchExecutions with GridLogging {

Expand Down Expand Up @@ -83,20 +86,25 @@ trait ElasticSearchClient extends ElasticSearchExecutions with GridLogging {
implicit val logMarker = MarkerMap()
val queryCatCount = catCount(indexName) // document count only of index including live documents, not deleted documents which have not yet been removed by the merge process
val queryImageSearch = search(indexName) trackTotalHits true limit 0 // hits that match the query defined in the request
val uploadedInLastFiveMinutes = count(indexName) query rangeQuery("uploadTime").gte("now-5m")
val queryStats = indexStats(indexName) // total accumulated values of an index for both primary and replica shards
val indexForAlias = getIndexForAlias(indexName)

for {
catCount <- executeAndLog(queryCatCount, "Images cat count")
imageSearch <- executeAndLog(queryImageSearch, "Images search")
stats <- executeAndLog(queryStats, "Stats aggregation")
uploadedInLastFiveMinutes <- executeAndLog(uploadedInLastFiveMinutes, "Count uploaded in last five minutes")
maybeRealIndexName <- indexForAlias
} yield {
// indexName may also be an alias; do a lookup for the real name if it exists
val realIndexName = maybeRealIndexName.map(_.name).getOrElse(indexName)
ElasticSearchImageCounts(catCount.result.count,
imageSearch.result.hits.total.value,
stats.result.indices(realIndexName).total.docs.count)
ElasticSearchImageCounts(
catCount = catCount.result.count,
searchResponseCount = imageSearch.result.hits.total.value,
indexStatsCount = stats.result.indices(realIndexName).total.docs.count,
uploadedInLastFiveMinutes = uploadedInLastFiveMinutes.result.count
)
}
}

Expand Down

0 comments on commit a365d74

Please sign in to comment.