Skip to content

Commit 5843c84

Browse files
committed
Revert "PI-2876 Log OpenSearch query JSON to app insights (#821)"
This reverts commit 76908c2.
1 parent 76908c2 commit 5843c84

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/main/kotlin/uk/gov/justice/hmpps/probationsearch/contactsearch/ContactSearchController.kt

+18-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,31 @@ import java.time.temporal.ChronoUnit
1111

1212
@RestController
1313
@RequestMapping("/search/contacts")
14-
class ContactSearchController(val contactSearchService: ContactSearchService) {
14+
class ContactSearchController(
15+
val contactSearchService: ContactSearchService,
16+
val telemetryClient: TelemetryClient
17+
) {
1518
@PreAuthorize("hasAnyRole('ROLE_PROBATION_CONTACT_SEARCH', 'ROLE_PROBATION_INTEGRATION_ADMIN')")
1619
@RequestMapping(method = [RequestMethod.GET, RequestMethod.POST])
1720
fun searchContact(
1821
@RequestBody request: ContactSearchRequest,
1922
@ParameterObject @PageableDefault pageable: Pageable,
2023
@RequestParam(defaultValue = "false") semantic: Boolean = false,
2124
): ContactSearchResponse = if (semantic) {
22-
contactSearchService.semanticSearch(request, pageable)
25+
val started = Instant.now()
26+
val response = contactSearchService.semanticSearch(request, pageable)
27+
telemetryClient.trackEvent(
28+
"SemanticSearchCompleted",
29+
mapOf(
30+
"crn" to request.crn,
31+
"query" to request.query.length.toString(),
32+
"resultCount" to response.totalResults.toString(),
33+
),
34+
mapOf(
35+
"duration" to started.until(Instant.now(), ChronoUnit.MILLIS).toDouble(),
36+
),
37+
)
38+
response
2339
} else {
2440
contactSearchService.keywordSearch(request, pageable)
2541
}

src/main/kotlin/uk/gov/justice/hmpps/probationsearch/contactsearch/ContactSearchService.kt

-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package uk.gov.justice.hmpps.probationsearch.contactsearch
22

33
import com.fasterxml.jackson.databind.ObjectMapper
4-
import com.microsoft.applicationinsights.TelemetryClient
54
import io.opentelemetry.api.trace.Span
65
import io.opentelemetry.context.Context
76
import io.opentelemetry.extension.kotlin.asContextElement
@@ -39,7 +38,6 @@ import uk.gov.justice.hmpps.probationsearch.contactsearch.ContactSearchService.S
3938
import uk.gov.justice.hmpps.probationsearch.services.DeliusService
4039
import uk.gov.justice.hmpps.sqs.audit.HmppsAuditService
4140
import java.time.Instant
42-
import java.time.temporal.ChronoUnit
4341
import org.opensearch.client.opensearch._types.SortOrder as JavaClientSortOrder
4442
import org.opensearch.client.opensearch._types.query_dsl.Operator as JavaClientOperator
4543

@@ -50,7 +48,6 @@ class ContactSearchService(
5048
private val objectMapper: ObjectMapper,
5149
private val deliusService: DeliusService,
5250
private val openSearchClient: OpenSearchClient,
53-
private val telemetryClient: TelemetryClient
5451
) {
5552

5653
private val scope = CoroutineScope(Context.current().asContextElement())
@@ -81,7 +78,6 @@ class ContactSearchService(
8178
}
8279

8380
fun semanticSearch(request: ContactSearchRequest, pageable: Pageable): ContactSearchResponse {
84-
val started = Instant.now()
8581
audit(request, pageable)
8682

8783
val indexName = "contact-semantic-search-${request.crn.lowercase()}"
@@ -111,7 +107,6 @@ class ContactSearchService(
111107
val searchRequest = SearchRequest.of { searchRequest ->
112108
searchRequest
113109
.index(indexName)
114-
.source { source -> source.filter { it.excludes("textEmbedding", "textChunks") } }
115110
.query { query -> query.hybrid { hybrid -> hybrid.queries(keywordQuery, semanticQuery) } }
116111
.trackTotalHits(TrackHits.of { it.count(5000) })
117112
.size(pageable.pageSize)
@@ -143,19 +138,6 @@ class ContactSearchService(
143138
}
144139
val response = PageImpl(results, pageable, searchResponse.hits().total().value())
145140

146-
telemetryClient.trackEvent(
147-
"SemanticSearchCompleted",
148-
mapOf(
149-
"crn" to request.crn,
150-
"query" to request.query.length.toString(),
151-
"jsonQuery" to searchRequest.toJsonString(),
152-
"resultCount" to response.totalElements.toString(),
153-
),
154-
mapOf(
155-
"duration" to started.until(Instant.now(), ChronoUnit.MILLIS).toDouble(),
156-
),
157-
)
158-
159141
return ContactSearchResponse(
160142
response.numberOfElements,
161143
response.pageable.pageNumber,

0 commit comments

Comments
 (0)