Skip to content

Commit

Permalink
Merge branch 'develop' into feature/default-mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
jessjenkins committed Sep 13, 2021
2 parents 20a3aee + c3d4a81 commit f578eca
Show file tree
Hide file tree
Showing 18 changed files with 387 additions and 610 deletions.
13 changes: 6 additions & 7 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ONSdigital/dp-search-api/service"

"github.com/ONSdigital/go-ns/server"
"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
"github.com/gorilla/mux"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -39,7 +39,7 @@ type QueryBuilder interface {

// ResponseTransformer provides methods for the transform package
type ResponseTransformer interface {
TransformSearchResponse(ctx context.Context, responseData []byte, query string) ([]byte, error)
TransformSearchResponse(ctx context.Context, responseData []byte, query string, highlight bool) ([]byte, error)
}

// CreateAndInitialise initiates a new Search API
Expand Down Expand Up @@ -76,9 +76,10 @@ func CreateAndInitialise(cfg *config.Config, queryBuilder QueryBuilder, elasticS
httpServer.HandleOSSignals = false

go func() {
log.Event(nil, "search api starting", log.INFO)
ctx := context.Background()
log.Info(ctx, "search api starting")
if err := httpServer.ListenAndServe(); err != nil {
log.Event(nil, "search api http server returned error", log.Error(err), log.ERROR)
log.Error(ctx, "search api http server returned error", err)
errorChan <- err
}
}()
Expand Down Expand Up @@ -107,8 +108,6 @@ func Close(ctx context.Context) error {
if err := httpServer.Shutdown(ctx); err != nil {
return err
}
log.Event(ctx, "graceful shutdown of http server complete", log.INFO)
log.Info(ctx, "graceful shutdown of http server complete")
return nil
}


12 changes: 6 additions & 6 deletions api/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"

"github.com/ONSdigital/dp-search-api/query"
"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
)

type dataLookupRequest struct {
Expand Down Expand Up @@ -41,35 +41,35 @@ func DataLookupHandlerFunc(elasticSearchClient ElasticSearcher) http.HandlerFunc

err := dataTemplates.Execute(&doc, reqParams)
if err != nil {
log.Event(ctx, "creation of search from template failed", log.Data{"Params": reqParams}, log.Error(err), log.ERROR)
log.Error(ctx, "creation of search from template failed", err, log.Data{"Params": reqParams})
http.Error(w, "Failed to create query", http.StatusInternalServerError)
return
}

formattedQuery, err := query.FormatMultiQuery(doc.Bytes())
if err != nil {
log.Event(ctx, "formating of data query for elasticsearch failed", log.Error(err), log.ERROR)
log.Error(ctx, "formating of data query for elasticsearch failed", err)
http.Error(w, "Failed to create query", http.StatusInternalServerError)
return
}

responseString, err := elasticSearchClient.Search(ctx, "", "", formattedQuery)
if err != nil {
log.Event(ctx, "elasticsearch data query failed", log.Error(err), log.ERROR)
log.Error(ctx, "elasticsearch data query failed", err)
http.Error(w, "Failed to run data query", http.StatusInternalServerError)
return
}

responseData := dataLookupResponse{Responses: make([]interface{}, 1)}
if err := json.Unmarshal([]byte(responseString), &responseData.Responses[0]); err != nil {
log.Event(ctx, "failed to unmarshal response from elasticsearch for data query", log.Error(err), log.ERROR)
log.Error(ctx, "failed to unmarshal response from elasticsearch for data query", err)
http.Error(w, "Failed to process data query", http.StatusInternalServerError)
return
}

dataWithResponse, err := json.Marshal(responseData)
if err != nil {
log.Event(ctx, "Failed to marshal response data for data query", log.Error(err), log.ERROR)
log.Error(ctx, "Failed to marshal response data for data query", err)
http.Error(w, "Failed to encode data query response", http.StatusInternalServerError)
return
}
Expand Down
4 changes: 2 additions & 2 deletions api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"strings"

"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
)

type healthMessage struct {
Expand Down Expand Up @@ -41,7 +41,7 @@ func HealthCheckHandlerCreator(elasticSearchClient ElasticSearcher) func(http.Re
Status: "error",
Error: healthIssue,
}); err != nil {
log.Event(ctx, "elasticsearch healthcheck status json failed to parse", log.Error(err), log.ERROR)
log.Error(ctx, "elasticsearch healthcheck status json failed to parse", err)
panic(err)
}
}
Expand Down
Loading

0 comments on commit f578eca

Please sign in to comment.