|
| 1 | +## Developer documentation |
| 2 | + |
| 3 | +### ~Requirements |
| 4 | + |
| 5 | +- Checkout `elastic/package-registry`, `elastic/package-storage` and `elastic/beats` |
| 6 | +- Have `elastic/package-spec` at hand |
| 7 | + |
| 8 | +### Guide |
| 9 | + |
| 10 | +#### Update / fix a package |
| 11 | + |
| 12 | +1. Actual work |
| 13 | + - Make changes in `apmpackage/apm/<version>`, `apmpackage/docs/README.template.md` and/or code as needed |
| 14 | + - Run `make update`. That will update fields, pipeline and doc files based on apm-server fields and pipeline defs. |
| 15 | + |
| 16 | +2. Run the registry |
| 17 | + - Checkout a fresh master from the registry and run `mage build` |
| 18 | + - Copy `apmpackage/apm` in apm-server to `build/package-storage/packages` in the registry |
| 19 | + - `go run .` |
| 20 | + |
| 21 | +3. Run the stack |
| 22 | + - Update Kibana settings with `xpack.fleet.registryUrl: http://localhost:8080` |
| 23 | + - Start Kibana and Elasticsearch with X-Pack enabled. One way to do it is with a local Kibana: |
| 24 | + - `yarn es snapshot --license trial --ssl -E xpack.security.authc.api_key.enabled=true` |
| 25 | + - `yarn start --ssl` |
| 26 | + |
| 27 | +4. Test |
| 28 | + - Go to the Fleet UI, install the integration and test what you need. You generally will want to have a look at the |
| 29 | + installed assets (ie. templates and pipelines), and the generated `apm` input in the policy. |
| 30 | + - If you need to change the package, you *must* remove the installed integration first. You can use the UI |
| 31 | + or the API, eg: `curl -X DELETE -k -u elastic:changeme https://localhost:5601/abc/api/fleet/epm/packages/apm-0.1.0 -H 'kbn-xsrf: xyz'` |
| 32 | + See [API docs](https://github.com/elastic/kibana/tree/master/x-pack/plugins/fleet/dev_docs/api) for details. |
| 33 | + You normally don't need to restart the registry (an exception to this is eg. if you change a `hbs` template file). |
| 34 | + |
| 35 | +5. Upload to the snapshot registry |
| 36 | + - When everything works and `apmpackage/apm/` changes have been merged to `master`, copy the new package to |
| 37 | + `package-storage/packages` in the `package-storage` repo, `snapshot` branch. |
| 38 | + Do *NOT* override any existing packages. Instead, bump the qualifier version. Eg: rename `apm/0.1.0-dev.1` to `apm/0.1.0-dev.2` |
| 39 | + - Bump the qualifier in the contents too: `find . -type f -print0 | xargs -0 sed -i "" "s/0.1.0-dev.1/0.1.0-dev.2/g"` |
| 40 | + This step can be done in a separate commit to facilitate review. |
| 41 | + |
| 42 | + |
| 43 | +#### Create a new package version |
| 44 | + |
| 45 | +Follow steps described above, except: |
| 46 | + |
| 47 | +1. New local version |
| 48 | + - Copy `apmpackage/apm/<latest-version>` to `apmpackage/apm/<next-version>`. |
| 49 | + - Add a new version mapping in the `versionMapping` variable at the top of `apmpackage/cmd/gen-package/main.go`. |
| 50 | + Most likely this won't be needed in the future. |
| 51 | + - Then do any changes in the new folder. The rest of the steps are the same. |
| 52 | + |
| 53 | +2. First dev version |
| 54 | + - When copying to the `package-storage`, create the first version qualifier instead of bumping the last one. |
| 55 | + Eg: `apm/0.2.0` -> `apm/0.2.0-dev.1` |
| 56 | + |
| 57 | + |
| 58 | +#### Run the Elastic Agent |
| 59 | + |
| 60 | +If you do code changes or a whole new version, you need to run the Elastic Agent locally. |
| 61 | +Most of the work here is done in `beats/x-pack/elastic-agent` |
| 62 | + |
| 63 | +0. Optional: Update the spec |
| 64 | + |
| 65 | + The spec informs whether the Elastic Agent should or should not start apm-server based on the policy file, |
| 66 | + and what settings to pass via GRPC call. |
| 67 | + - Edit `spec/apm-server.yml` |
| 68 | + - `mage update` |
| 69 | + |
| 70 | +1. Build / Package |
| 71 | + |
| 72 | + *First time* |
| 73 | + - `DEV=true PLATFORMS=darwin mage package` (replace platform as needed) |
| 74 | + - Untar `build/distributions` contents |
| 75 | + |
| 76 | + *Every time after* |
| 77 | + - `DEV=true mage build` |
| 78 | + - Copy `build/elastic-agent` to `build/distributions/elastic-agent-<version>-<platform>/data/elastic-agent-<hash>/` |
| 79 | + |
| 80 | +2. Override policy / apm-server |
| 81 | + - Use the right `elastic-agent.yml` policy |
| 82 | + |
| 83 | + It might be one you just generated with the UI, or one you have at hand with an apm input. |
| 84 | + Copy to `build/distributions/elastic-agent-<version>-<platform>/elastic-agent.yml` |
| 85 | + |
| 86 | + - Override apm-server in `install` and `downloads` folders. Approximately: |
| 87 | + ``` |
| 88 | + # compile apm-server |
| 89 | + cd ~/<path>/apm-server |
| 90 | + make && make update |
| 91 | +
|
| 92 | + # tar and compress |
| 93 | + cp build/fields/fields.yml . |
| 94 | + tar cvf apm-server-<stack-version>-<platform>.tar apm-server LICENSE.txt NOTICE.txt README.md apm-server.yml ingest fields.yml |
| 95 | + gzip apm-server-<stack-version>-<platform>.tar |
| 96 | + sha512sum apm-server-<stack-version>-<platform>.tar.gz | tee apm-server-<stack-version>-<platform>.tar.gz.sha512 |
| 97 | +
|
| 98 | + # delete old stuff |
| 99 | + cd ~/<path>/beats/x-pack/elastic-agent/build/distributions/elastic-agent-<version>-<platform>/data/elastic-agent-<hash>/downloads |
| 100 | + rm apm* |
| 101 | + rm -rf ../install/apm* |
| 102 | +
|
| 103 | + # copy new files |
| 104 | + mv <path>/apm-server-<stack-version>-<platform>.tar* . |
| 105 | + mkdir -p ../install/apm-server-<stack-version>-<platform> |
| 106 | + tar zxvf apm-server-<stack-version>-<platform> -C ../install/apm-server-<stack-version>-<platform> |
| 107 | + ``` |
| 108 | +3. Run the Elastic Agent |
| 109 | + - `./build/distributions/<blablabla>/elastic-agent -e` |
| 110 | + - Check apm-server logs at `build/distributions/<blablabla>/data/<blablabla>/logs/default` |
| 111 | +
|
| 112 | + (The last default in the path comes from the namespace in the policy) |
| 113 | +
|
| 114 | +#### Promote a package |
| 115 | +
|
| 116 | +Generally it should be done between FF and release. |
| 117 | +1. Remove the qualifier version from the package |
| 118 | +2. Push to the corresponding production branch(es) |
| 119 | +
|
| 120 | +
|
| 121 | +### Caveats |
| 122 | +
|
| 123 | +Fleet is under active development and this guide might become obsolete quickly. |
| 124 | +
|
| 125 | +Take everything with a grain of salt. |
0 commit comments