Skip to content

Commit

Permalink
Fx/bus 105 Changing OpenSearch query for MachinesFailedData (#15)
Browse files Browse the repository at this point in the history
* Adding logs

* Changing OpenSearch query for MachinesFailedData

* Fixing OpenSearch query for MachinesFailedData
  • Loading branch information
Gretchen-z authored Jul 22, 2024
1 parent ce65908 commit 07b60f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void registerMetrics() {
.map(MachinesFailedData::getMachineId)
.limit(10)
.toList();
log.info("withdrawalIds {}", withdrawalIds);
var withdrawalEntities = withdrawalRepository.getWithdrawalsMetrics(withdrawalIds);
log.info("withdrawalEntities {}", withdrawalEntities);

Expand All @@ -35,6 +36,7 @@ public void registerMetrics() {
.map(MachinesFailedData::getMachineId)
.limit(10)
.toList();
log.info("invoiceIds {}", invoiceIds);
var invoiceEntities = paymentRepository.getPaymentsStatusMetrics(invoiceIds);
log.info("invoiceEntities {}", invoiceEntities);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class OpenSearchService {
private static final String MACHINE_FAILED = "machine failed";
private static final String STATUS_START = "100";
private static final String STATUS_END = "599";
private static final String CONTEXT_AUTH_EXPIRATION = "context.auth.expiration";
private static final String CONTEXT_ENV_NOW = "context.env.now";
private static final String DEADLINE = "deadline";
private static final String RESCHEDULE_TIME = "reschedule_time";
private static final String TARGET_TIMESTAMP = "target_timestamp";

private final OpenSearchProperties openSearchProperties;
private final OpenSearchClient openSearchClient;
Expand Down Expand Up @@ -187,40 +192,47 @@ public List<HttpCodeData> getWapiHttpCodeData() {
@SneakyThrows
public List<MachinesFailedData> getMachinesFailedData() {
return openSearchClient.search(s -> s
.size(10000)
.size(500)
.index(openSearchProperties.getIndex())
.sort(builder -> builder
.field(builder1 -> builder1
.field(TIMESTAMP)
.order(SortOrder.Desc)
.unmappedType(FieldType.Boolean)))
.docvalueFields(builder -> builder
.field(TIMESTAMP)
.format(DATE_TIME))
.field(TIMESTAMP).format(DATE_TIME)
.field(CONTEXT_AUTH_EXPIRATION).format(DATE_TIME)
.field(CONTEXT_ENV_NOW).format(DATE_TIME)
.field(DEADLINE).format(DATE_TIME)
.field(RESCHEDULE_TIME).format(DATE_TIME)
.field(TARGET_TIMESTAMP).format(DATE_TIME))
.query(builder -> builder
.bool(builder1 -> builder1
.filter(new RangeQuery.Builder()
.filter(
new RangeQuery.Builder()
.field(TIMESTAMP)
.gte(JsonData.of(
String.format("now-%ss", intervalTime)))
.gte(JsonData.of(String.format("now-%ss", intervalTime)))
.format(STRICT_DATE_OPTIONAL_TIME)
.build()
._toQuery(),
new BoolQuery.Builder()
.should(new Query(new MatchPhraseQuery.Builder()
.field(SERVICE)
.query(MACHINEGUN)
.build()),
new Query(new MatchPhraseQuery.Builder()
.field(SEVERITY)
.query(ERROR)
.build()),
new Query(new MatchPhraseQuery.Builder()
.field(MESSAGE)
.query(MACHINE_FAILED)
.build()))
new MatchPhraseQuery.Builder()
.field(SERVICE)
.query(MACHINEGUN)
.build()
._toQuery()))),
._toQuery(),
new MatchPhraseQuery.Builder()
.field(SEVERITY)
.query(ERROR)
.build()
._toQuery(),
new MatchPhraseQuery.Builder()
.field(MESSAGE)
.query(MACHINE_FAILED)
.build()
._toQuery()
)
)
),
MachinesFailedData.class)
.hits()
.hits()
Expand Down

0 comments on commit 07b60f8

Please sign in to comment.