Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Store checks results on the db instead of ARA #415

Closed

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Nov 2, 2021

Store the checks results content in the database instead of ARA.

The major changes:

  • Add a new checks results table in the database: CheckResultsRaw (check_results is the actual name on the database). This table contains the checks GroupID (which by now is always the cluster id) and the results json as payload. It contains the creation time and an unique ID as well.
  • Split the checks catalog and checks results models in 2 files. It makes the distinction easier
  • Create a new API endpoint to post the checks results. In our case from the runner to the web. This is a post operation as it creates new entries every time
  • Replace all the code related to ARA. Now these records are in the database.
  • Update the runner callback code to post the results in this new API endpoint rather than in ARA. The content is exactly the same though

There are a lot of ARA leftovers in the code yet. I will remove them definitely once this PR is done, as this pieces of code are the ones that really use ARA by now.

PD: I still used the JSON prefix to define the API structs. We already have a follow up ticket at: #412

@arbulu89 arbulu89 added enhancement Improvement of existing features api labels Nov 2, 2021
@arbulu89 arbulu89 marked this pull request as ready for review November 2, 2021 13:00
Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! LGTM except minor cosmetical issues. Feel free to sort them out in a different PR if you agree with them (or here if you prefer)

// @Router /api/clusters/{cluster_id}/results [get]
func ApiClusterCheckResultsHandler(client consul.Client, s services.ChecksService) gin.HandlerFunc {
// @Router /api/checks/{id}/results [post]
func ApiCreateChecksResultstaHandler(s services.ChecksService) gin.HandlerFunc {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the function seems to have a typo: ApiCreateChecksResultstaHandler -> ApiCreateChecksResultsHandler

mockChecksService := new(services.MockChecksService)
mockChecksService.On(
"GetChecksResultAndMetadataByCluster", "47d1190ffb4f781974c8356d7f863b03").Return(
&models.ClusterCheckResults{}, fmt.Errorf("kaboom"))
"GetChecksResultAndMetadataById", "47d1190ffb4f781974c8356d7f863b03").Return(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that sometimes you use "CheckResults" and others you move the plural: "ChecksResult". Is this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also sometimes I see "ChecksResults". There might be a reason I'm missing but if not, I'd try to keep it constant across the code.

assert.Equal(t, 404, resp.Code)
}

func TestApiCreateChecksResultstaHandler(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here ofc :-)

GetChecksResultAndMetadataByCluster(clusterId string) (*models.ClusterCheckResults, error)
GetAggregatedChecksResultByHost(clusterId string) (map[string]*AggregatedCheckData, error)
GetAggregatedChecksResultByCluster(clusterId string) (*AggregatedCheckData, error)
GetChecksResultById(id string) (*models.Results, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the same as already commented

@stefanotorresi
Copy link
Member

To unblock this, for the time being, let's use the public api Gin instance, which was a quandary left unsolved since the block.

@arbulu89
Copy link
Contributor Author

Closing this as the conflict resolution looks more difficult than opening a new fresh PR.
I will leverage most of the content, but based in the new upstream code

@arbulu89 arbulu89 closed this Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api enhancement Improvement of existing features
Development

Successfully merging this pull request may close these issues.

3 participants