Skip to content

Merging ingestmanager client into generic kibana client #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 6, 2021

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Dec 30, 2020

When the system tests feature was added to elastic-package, we created a client to communicate with the Kibana Ingest Manager API, ingestmanager.Client. Some time later, we created a more general Kibana client to communicate with the Kibana Saved Objects and Dashboard Export APIs, kibana.Client.

It makes sense to combine these two clients into one, as noted in #168 (comment). This PR attempts to do so.

@ycombinator ycombinator mentioned this pull request Dec 30, 2020
7 tasks
@ycombinator ycombinator requested a review from mtojek December 30, 2020 00:21
@elasticmachine
Copy link
Collaborator

elasticmachine commented Dec 30, 2020

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #210 updated

  • Start Time: 2021-01-05T23:29:03.178+0000

  • Duration: 9 min 58 sec

Test stats 🧪

Test Results
Failed 0
Passed 9
Skipped 0
Total 9

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. Apart from system tests, the part that can be tested only manually is export dashboards (as it uses the kibana client).

I'm worried about the failed Jenkins job:

[2020-12-30T00:43:26.104Z] Error: error running package system tests: could not complete test run: could not create test policy: could not create policy; API status code = 404; response body = {"statusCode":404,"error":"Not Found","message":"Not Found"}

I wonder if there was something missed during refactoring.

@@ -180,25 +180,25 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
}

// Step 2. Configure package (single data stream) via Ingest Manager APIs.
im, err := ingestmanager.NewClient(r.stackSettings.kibana.host, r.stackSettings.elasticsearch.username, r.stackSettings.elasticsearch.password)
Copy link
Contributor

Choose a reason for hiding this comment

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

I admit that I didn't analyze the source deeper, but are these Kibana/ES properties still required in stack settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, these are not required any more. Removed in 32fe1b2.

Type: ds.Type,
Dataset: fmt.Sprintf("%s.%s", pkg.Name, ds.Name),
},
},
}

// Add dataStream-level vars
dsVars := ingestmanager.Vars{}
dsVars := kibana.Vars{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking loud (nothing to be done immediately): The Vars structure may look to be a generic one. It may happen in the future that we need to handle another Vars structure, so some of these structs will require a relevant prefix added to their names.

@@ -52,7 +52,7 @@ func (c *Client) CreatePolicy(p Policy) (*Policy, error) {
func (c *Client) DeletePolicy(p Policy) error {
reqBody := `{ "agentPolicyId": "` + p.ID + `" }`

statusCode, respBody, err := c.post("agent_policies/delete", []byte(reqBody))
statusCode, respBody, err := c.post("/api/fleet/agent_policies/delete", []byte(reqBody))
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about extracting all URL prefixes to the common place? I know it's an improvement comparing to what we have now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but just want to clarify what you mean by URL prefixes: just the /api/fleet part (and similar prefixes from other API URLs) or something more?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I meant exactly that: '/api/fleet' or '/api/saved_objects' etc. Just to prevent missing mappings in the future (because they were hidden in multiple places in the source).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 17ab10c.

@ycombinator ycombinator requested a review from mtojek January 5, 2021 00:30
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Changes look good to me. I'm worried about the CI job output that revealed a couple of unknown errors: https://beats-ci.elastic.co/blue/organizations/jenkins/Ingest-manager%2Felastic-package/detail/PR-210/6/pipeline

Would you mind looking at them?

@@ -52,7 +52,7 @@ func (c *Client) CreatePolicy(p Policy) (*Policy, error) {
func (c *Client) DeletePolicy(p Policy) error {
reqBody := `{ "agentPolicyId": "` + p.ID + `" }`

statusCode, respBody, err := c.post("agent_policies/delete", []byte(reqBody))
statusCode, respBody, err := c.post(fmt.Sprintf("%s/agent_policies/delete", FleetAPI), []byte(reqBody))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Hm.. I'm wondering if it's not better to extract also the resource part (agent_policies, package_policies) as they appear in multiple places. Once it's changed, I think you can switch from fmt.Sprintf to a simple concatenation (URL prefix + operation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's more readable this way, actually. And while the prefixes are more likely to change (due to project name changes, etc.), I think the resource paths are less likely to change. So I would prefer to keep it as-is.


const (
// CoreAPI is the prefix for all Kibana Core API resources.
CoreAPI = "/api/kibana"
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about renaming it to api.go or url_prefixes.go? Prefixes sounds a bit vague.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 93223e5.

@mtojek
Copy link
Contributor

mtojek commented Jan 5, 2021

It seems to be an unnecessary t.Log() call. I must have missed it in previous reviews:

		t.Run(test.key, func(t *testing.T) {
			err := parseElementValue(test.key, test.definition, test.value)
			if err != nil {
				t.Log(err)
			}
			if test.fail {
				require.Error(t, err)
			} else {
				require.NoError(t, err)
			}
		})

You can leave as is or cleanup the test output - up to you :) It means that the problem is:

[2021-01-05T00:31:57.673Z] internal/kibana/dashboards.go:35:10: Sprintf format %s has arg query of wrong type strings.Builder

@ycombinator
Copy link
Contributor Author

It seems to be an unnecessary t.Log() call.

Removed in 7ce568b.

@ycombinator ycombinator merged commit 5a0293c into elastic:master Jan 6, 2021
@ycombinator ycombinator deleted the unify-kib-client branch January 6, 2021 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants