Skip to content
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

[Fleet] Modify Agent policy and agent upgrades to handle custom source_uri #135629

Merged
merged 17 commits into from
Jul 12, 2022

Conversation

criamico
Copy link
Contributor

@criamico criamico commented Jul 4, 2022

Summary

Part of #133828

  • Allow to set a specific download_source object per agent policy. download_source.host is then set as source_uri in the agent policy
  • Modify the agent policy compilation logic to include agent.download.source_uri. If download_ source_id is set on the policy, the agent policy will have a specific source_uri, otherwise the default will be used
  • Revert changes introduced in [Fleet] Disable custom source_uri option on upgrade APIs by default #123464; source_uri can now be passed in the Agent upgrade logic (both single agent and bulk upgrade).
    • If passed in the route, it will be written to the actions (this logic is already in main but it's prevented)
    • If not passed, the source_uri in the agent policy will be used
Tests

Verify that any agent policy has the default value for source_uri

  • Navigate to agent policies, select any agent policy and click on "view policy"
    • Under agent.download.source_uri you should see the default source_uri (if you didn't set one, it should be https://artifacts.elastic.co)

Create an agent policy with a custom source_uri

  • Create a new download_source object (something different than the default artifacts.elastic.co) and get the id:

    POST kbn:/api/fleet/agent_download_sources
    {
      "name": "custom source_uri for policy",
      "host": "http://custom-registry-per-policy",
      "is_default": "false"
    }
    
    {
      "item": {
        "id": "b5112840-fdf8-11ec-93d1-01bd67999927",
        "name": "custom source_uri for policy",
        "host": "http://custom-registry-per-policy",
        "is_default": false
      }
    }
    
  • Create also a new agent policy and get the id (in my case was 1dcaf600-fdf8-11ec-93d1-01bd67999927)

  • Set download_source_id to the id of the previously created download_source object:

    PUT kbn:/api/fleet/agent_policies/1dcaf600-fdf8-11ec-93d1-01bd67999927
    { 
      "name": "Agent policy with custom registry",
      "namespace": "default",
      "description": "",
      "monitoring_enabled": [
        "logs",
        "metrics"
      ],
      "download_source_id": "b5112840-fdf8-11ec-93d1-01bd67999927"
    }
    
  • click on view policy on agent policies page and check that the agent.download.source_uri has http://custom-registry-per-policy

Screenshot 2022-07-07 at 15 34 19

Specify source_uri when upgrading an agent

  • The POST upgrade endpoint it should accept source_uri parameter:
  • POST kbn:/api/fleet/agents/e73868ac-94cf-4e9d-8630-906a8a53caf3/upgrade
    {
      "source_uri": "https://my-registry-test",
      "version": "8.4.0",
      "force": true
    }
    

Specify source_uri when bulk upgrading agents:

  • POST kbn:/api/fleet/agents/bulk_upgrade
    {
      "agents": [
        "e73868ac-94cf-4e9d-8630-906a8a53caf3", 
        "9bcd329e-4890-4353-b8dc-882000553bab"
        ],
      "source_uri": "https://my-registry-test",
      "version": "8.3.0"
    }
    
  • For now there's no way to test this locally, but I added some integration tests to cover this part.

@criamico criamico self-assigned this Jul 4, 2022
@criamico
Copy link
Contributor Author

criamico commented Jul 6, 2022

@elasticmachine merge upstream

@criamico criamico changed the title Download source/update agent policies [Fleet] Modify Agent policy and agent upgrades to handle custom source_uri Jul 7, 2022
@criamico criamico added Team:Fleet Team label for Observability Data Collection Fleet team v8.4.0 release_note:skip Skip the PR/issue when compiling release notes labels Jul 7, 2022
@criamico criamico marked this pull request as ready for review July 7, 2022 14:10
@criamico criamico requested a review from a team as a code owner July 7, 2022 14:10
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@criamico
Copy link
Contributor Author

criamico commented Jul 8, 2022

@elasticmachine merge upstream

@criamico criamico requested a review from kpollich July 8, 2022 13:51
@criamico
Copy link
Contributor Author

@elasticmachine merge upstream

import { downloadSourceService, agentPolicyService } from '../../services';
import type { Agent, AgentPolicy } from '../../types';

export const getSourceUriForAgent = async (soClient: SavedObjectsClientContract, agent: Agent) => {
Copy link
Member

Choose a reason for hiding this comment

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

I do not think this one is used anywhere

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚀

@criamico criamico enabled auto-merge (squash) July 12, 2022 15:18
Copy link
Member

@kpollich kpollich 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 all your work here!

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
fleet 1389 1390 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
fleet 111.6KB 111.6KB +17.0B

Saved Objects .kibana field count

Every field in each saved object type adds overhead to Elasticsearch. Kibana needs to keep the total field count below Elasticsearch's default limit of 1000 fields. Only specify field mappings for the fields you wish to search on or query. See https://www.elastic.co/guide/en/kibana/master/development-plugin-saved-objects.html#_mappings

id before after diff
ingest-agent-policies 17 18 +1
Unknown metric groups

API count

id before after diff
fleet 1521 1522 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @criamico

@criamico criamico merged commit d533e8e into elastic:main Jul 12, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants