Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added tests/apm-managed-service/pgo/pgo.log
Binary file not shown.
5 changes: 5 additions & 0 deletions updatecli-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ policies:
values:
- updatecli/policies/updatecli/version/testdata/values.yaml

- name: Handle apm-managed-service/pgo (e2e tests)
policy: ghcr.io/elastic/oblt-updatecli-policies/apm-managed-service/pgo:latest
values:
- updatecli/policies/apm-managed-service/pgo/testdata/values.yaml

- name: Handle updatecli update
policy: ghcr.io/elastic/oblt-updatecli-policies/updatecli/version:latest
values:
Expand Down
5 changes: 5 additions & 0 deletions updatecli/policies/apm-managed-service/pgo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.1.0

* Init policy
15 changes: 15 additions & 0 deletions updatecli/policies/apm-managed-service/pgo/Policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
authors:
- Victor Martinez <[email protected]>

url: "https://github.com/elastic/oblt-updatecli-policies/"
changelog: "https://github.com/elastic/oblt-updatecli-policies/tree/main/updatecli/policies/apm-managed-service/pgo/CHANGELOG.md"
documentation: "https://github.com/elastic/oblt-updatecli-policies/tree/main/updatecli/policies/apm-managed-service/pgo/README.md"
source: "https://github.com/elastic/oblt-updatecli-policies/tree/main/updatecli/policies/apm-managed-service/pgo/"
version: 0.1.0
vendor: Elastic Project

licenses:
- "Apache-2.0 license"

description: |
PGO build in MIS update policy
3 changes: 3 additions & 0 deletions updatecli/policies/apm-managed-service/pgo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# README

This policy updates the PGO file defined in `elastic/apm-managed-service`
12 changes: 12 additions & 0 deletions updatecli/policies/apm-managed-service/pgo/testdata/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
scm:
enabled: true
owner: elastic
repository: oblt-updatecli-policies
username: obltmachine
branch: main
commitusingapi: true

# use one existing file until the pgo file is in the repository.
pgo_file: pgo.log
pgo_target_path: ./tests/apm-managed-service/pgo
pgo_source_repo: observability-robots-playground
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
# Helpers
# {{ $GitHubRepositoryList := env "GITHUB_REPOSITORY" | split "/"}}
# {{ $GitHubPAT := env "GITHUB_TOKEN"}}
# {{ $GitHubUsername := env "GITHUB_ACTOR"}}

name: '{{ .name }}'
pipelineid: '{{ .pipelineid }}'

sources:
sha:
kind: shell
spec:
command: gh api /repos/{{ default $GitHubRepositoryList._0 .scm.owner }}/{{ .pgo_source_repo}}/commits/main --jq '.sha'
environments:
- name: GITHUB_TOKEN
- name: PATH
pull_request:
kind: shell
dependson:
- sha
spec:
command: gh api /repos/{{ default $GitHubRepositoryList._0 .scm.owner }}/{{ .pgo_source_repo}}/commits/{{ source "sha" }}/pulls --jq '.[].html_url'
environments:
- name: GITHUB_TOKEN
- name: PATH
pgo-file:
kind: shell
scmid: apm-managed-service
dependson:
- sha
spec:
command: tar cvzf {{ requiredEnv "GITHUB_WORKSPACE" }}/pgo.tgz {{ .pgo_file }}
environments:
- name: PATH
workdir: "{{ .pgo_source_path }}"

targets:
pgo:
name: PGO file {{ source "sha" }}
disablesourceinput: true
kind: shell
dependson:
- source#pgo-file
spec:
# git diff helps to print what it changed, If it is empty, then updatecli report a success with no changes applied.
# See https://www.updatecli.io/docs/plugins/resource/shell/#_shell_target
command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/pgo.tgz && git --no-pager diff'
workdir: "{{ .pgo_target_path }}"
#{{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
scmid: default
# {{ end }}

{{ if or (.scm.enabled) (env "GITHUB_REPOSITORY") }}
scms:
default:
kind: "github"
spec:
# Priority set to the environment variable
user: '{{ default $GitHubUsername .scm.username}}'
owner: '{{ default $GitHubRepositoryList._0 .scm.owner }}'
repository: '{{ default $GitHubRepositoryList._1 .scm.repository}}'
token: '{{ default $GitHubPAT .scm.token }}'
username: '{{ default $GitHubUsername .scm.username }}'
branch: '{{ .scm.branch }}'
#{{ if .scm.commitusingapi }}
commitusingapi: {{ .scm.commitusingapi }}
# {{ end }}

apm-managed-service:
kind: github
spec:
user: '{{ default $GitHubUsername .scm.username }}'
owner: '{{ default $GitHubRepositoryList._0 .scm.owner }}'
repository: '{{ .pgo_source_repo }}'
token: '{{ default $GitHubPAT .scm.token }}'
username: '{{ default $GitHubUsername .scm.username }}'
branch: 'main'

actions:
default:
title: '[Automation] Update default.pgo'
kind: "github/pullrequest"
scmid: default
sourceid: sha
spec:
automerge: {{ .automerge }}
labels:
- dependencies
description: |-
Copy link

Choose a reason for hiding this comment

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

For description we actually need something more fancy, we want to print a small diff summary between old version of the PGO file and the new version that is getting raised in the PR. So it's easy to quickly preview what has changed and sanity check the differences. Right now it's done with the go tool pprof in https://github.com/elastic/apm-managed-service/pull/1365/files#diff-fc41f706e66d7e247dec9daa0e605237c1abcb49144cc0685892d82ab165279bR7, we will need to do something similar here as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

We use gh api to collect the PR reference, so the PRs in the MIS projects will contain a reference in the PR description. I was thinking we could use the git commit title, but IIUC, go tool pprof needs to run for each specific MIS project.

Therefore, I need to figure out whether we can use something in the updatecli to run the diff, let me figure out if I can support that.

Do you happen to have two pgo files I can use to run go tool pprof and test if my implementation with the diff works as expected?

Copy link

Choose a reason for hiding this comment

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

Here few PGO files from the apm-server

new.pgo.log
old.pgo.log

go tool pprof -top -base=old.pgo.log new.pgo.log

### What
Update default.pgo automatic sync

### Why
*Changeset*
* {{ source "pull_request" }}
* https://github.com/{{ default $GitHubRepositoryList._0 .scm.owner }}/{{ .pgo_source_repo }}/commit/{{ source "sha" }}

{{ end }}
17 changes: 17 additions & 0 deletions updatecli/policies/apm-managed-service/pgo/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'automation: update PGO'
pipelineid: apm-managed-service/pgo
automerge: false

pgo_file: default.pgo
pgo_source_repo: apm-managed-service
pgo_source_path: ./
pgo_target_path: ./

scm:
enabled: false
# owner: v1v
# repository: updatecli-demo
# token: "xxx"
# username: "v1v-bot"
# branch: main
# commitusingapi: false
Loading