Skip to content

Commit

Permalink
Merge branch 'jeffdaley/highlight-affordance-test' into jeffdaley/doc…
Browse files Browse the repository at this point in the history
…ument-route-performance
  • Loading branch information
jeffdaley committed Sep 29, 2023
2 parents 15e2d9a + 59dda06 commit cfc18fd
Show file tree
Hide file tree
Showing 58 changed files with 3,930 additions and 1,610 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hermes

![](https://github.com/hashicorp-forge/hermes/workflows/ci/badge.svg)
[![CI](https://github.com/hashicorp-forge/hermes/workflows/ci/badge.svg?branch=main)](https://github.com/hashicorp-forge/hermes/actions/workflows/ci.yml?query=branch%3Amain)

> Hermes is not an official HashiCorp project.
> The repository contains software which is under active development and is in the alpha stage. Please read the “[Project Status](#project-status)” section for more information.
Expand Down
4 changes: 4 additions & 0 deletions configs/config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// URL of the application.
base_url = "http://localhost:8000"

// log_format configures the logging format. Supported values are "standard" or
// "json".
log_format = "standard"

// algolia configures Hermes to work with Algolia.
algolia {
application_id = ""
Expand Down
104 changes: 104 additions & 0 deletions internal/api/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,58 @@ func ApprovalHandler(
"path", r.URL.Path,
)

// Compare Algolia and database documents to find data inconsistencies.
// Get document object from Algolia.
var algoDoc map[string]any
err = ar.Docs.GetObject(docID, &algoDoc)
if err != nil {
l.Error("error getting Algolia object for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
// Get document from database.
dbDoc := models.Document{
GoogleFileID: docID,
}
if err := dbDoc.Get(db); err != nil {
l.Error("error getting document from database for data comparison",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
return
}
// Get all reviews for the document.
var reviews models.DocumentReviews
if err := reviews.Find(db, models.DocumentReview{
Document: models.Document{
GoogleFileID: docID,
},
}); err != nil {
l.Error("error getting all reviews for document for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
if err := compareAlgoliaAndDatabaseDocument(
algoDoc, dbDoc, reviews, cfg.DocumentTypes.DocumentType,
); err != nil {
l.Warn("inconsistencies detected between Algolia and database docs",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
}

case "POST":
// Validate request.
docID, err := parseResourceIDFromURL(r.URL.Path, "approvals")
Expand Down Expand Up @@ -439,6 +491,58 @@ func ApprovalHandler(
"path", r.URL.Path,
)

// Compare Algolia and database documents to find data inconsistencies.
// Get document object from Algolia.
var algoDoc map[string]any
err = ar.Docs.GetObject(docID, &algoDoc)
if err != nil {
l.Error("error getting Algolia object for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
// Get document from database.
dbDoc := models.Document{
GoogleFileID: docID,
}
if err := dbDoc.Get(db); err != nil {
l.Error("error getting document from database for data comparison",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
return
}
// Get all reviews for the document.
var reviews models.DocumentReviews
if err := reviews.Find(db, models.DocumentReview{
Document: models.Document{
GoogleFileID: docID,
},
}); err != nil {
l.Error("error getting all reviews for document for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
if err := compareAlgoliaAndDatabaseDocument(
algoDoc, dbDoc, reviews, cfg.DocumentTypes.DocumentType,
); err != nil {
l.Warn("inconsistencies detected between Algolia and database docs",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
}

default:
w.WriteHeader(http.StatusMethodNotAllowed)
return
Expand Down
105 changes: 104 additions & 1 deletion internal/api/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,58 @@ func DocumentHandler(
"doc_id", docID,
)

// Compare Algolia and database documents to find data inconsistencies.
// Get document object from Algolia.
var algoDoc map[string]any
err = ar.Docs.GetObject(docID, &algoDoc)
if err != nil {
l.Error("error getting Algolia object for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
// Get document from database.
dbDoc := models.Document{
GoogleFileID: docID,
}
if err := dbDoc.Get(db); err != nil {
l.Error("error getting document from database for data comparison",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
return
}
// Get all reviews for the document.
var reviews models.DocumentReviews
if err := reviews.Find(db, models.DocumentReview{
Document: models.Document{
GoogleFileID: docID,
},
}); err != nil {
l.Error("error getting all reviews for document for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
if err := compareAlgoliaAndDatabaseDocument(
algoDoc, dbDoc, reviews, cfg.DocumentTypes.DocumentType,
); err != nil {
l.Warn("inconsistencies detected between Algolia and database docs",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
}

case "PATCH":
// Authorize request (only the owner can PATCH the doc).
userEmail := r.Context().Value("userEmail").(string)
Expand Down Expand Up @@ -688,7 +740,58 @@ Hermes

w.WriteHeader(http.StatusOK)
l.Info("patched document", "doc_id", docID)
return

// Compare Algolia and database documents to find data inconsistencies.
// Get document object from Algolia.
var algoDoc map[string]any
err = ar.Docs.GetObject(docID, &algoDoc)
if err != nil {
l.Error("error getting Algolia object for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
// Get document from database.
dbDoc := models.Document{
GoogleFileID: docID,
}
if err := dbDoc.Get(db); err != nil {
l.Error("error getting document from database for data comparison",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
return
}
// Get all reviews for the document.
var reviews models.DocumentReviews
if err := reviews.Find(db, models.DocumentReview{
Document: models.Document{
GoogleFileID: docID,
},
}); err != nil {
l.Error("error getting all reviews for document for data comparison",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
return
}
if err := compareAlgoliaAndDatabaseDocument(
algoDoc, dbDoc, reviews, cfg.DocumentTypes.DocumentType,
); err != nil {
l.Warn("inconsistencies detected between Algolia and database docs",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
}

default:
w.WriteHeader(http.StatusMethodNotAllowed)
Expand Down
Loading

0 comments on commit cfc18fd

Please sign in to comment.