Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Replace all occurrences found
  • Loading branch information
mrodm committed Sep 10, 2025
commit 5d46bddd1d13fdc3b63b34fe84752571ee6600cc
12 changes: 8 additions & 4 deletions internal/testrunner/runners/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ var uniqueOtelComponentIDReplace = policyEntryReplace{
// - endpoints:
// - https://epr.elastic.co
// method: GET
// service:
// pipelines:
// logs:
// receivers/6b7f1379-dcb9-4ac7-b253-4df6d088b3ff:
// - httpcheck/b0f518d6-4e2d-4c5d-bda7-f9808df537b7
//
// The regex captures the whole section, so it can be processed line by line to replace the IDs.
var otelComponentIDsRegexp = regexp.MustCompile(`(?m)^(?:extensions|receivers|processors|connectors|exporters|service):(?:\s\{\}\n|\n(?:\s{2,}.+\n)+)`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included the service map into this regex in order to take into account these kind of definitions too to find pipelines IDs like (metrics/<some_id>):

service:
  pipelines:
    logs:
      receivers/6b7f1379-dcb9-4ac7-b253-4df6d088b3ff:
        - httpcheck/b0f518d6-4e2d-4c5d-bda7-f9808df537b7


// cleanPolicy prepares a policy YAML as returned by the download API to be compared with other
Expand Down Expand Up @@ -248,10 +255,7 @@ func replaceOtelComponentIDs(policy []byte) []byte {
// service.extensions
// service.pipelines.<signal>.(receivers|processors|exporters)
for original, replacement := range replacementsDone {
originalArrayItem := fmt.Sprintf("- %s", original)
replacedArrayItem := fmt.Sprintf("- %s", replacement)

policy = bytes.ReplaceAll(policy, []byte(originalArrayItem), []byte(replacedArrayItem))
policy = bytes.ReplaceAll(policy, []byte(original), []byte(replacement))
Copy link
Member

Choose a reason for hiding this comment

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

👍

}
return policy
}
Expand Down
2 changes: 1 addition & 1 deletion internal/testrunner/runners/policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ receivers:
- endpoints:
- https://epr.elastic.co
method: GET
httpcheck/httpcheck/otelcol-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-otelcol-httpcheck-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd:
httpcheck/otelcol-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-otelcol-httpcheck-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd:
collection_interval: 2m
targets:
- endpoints:
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once these PRs are merged:

Testing with the current changes of those branches, this file should be like (it could change):

connectors:
    forward: {}
exporters:
    elasticsearch/componentid-0:
        endpoints:
            - http://localhost:9200
inputs: []
output_permissions:
    default:
        _elastic_agent_checks:
            cluster:
                - monitor
        _elastic_agent_monitoring:
            indices: []
        uuid-for-permissions-on-related-indices:
            indices:
                - names:
                    - metrics-*-*
                  privileges:
                    - auto_configure
                    - create_doc
processors:
    transform/componentid-0:
        metric_statements:
            - context: datapoint
              statements:
                - set(attributes["data_stream.type"], "metrics")
                - set(attributes["data_stream.dataset"], "httpcheck.check")
                - set(attributes["data_stream.namespace"], "ep")
receivers:
    httpcheck/componentid-0:
        collection_interval: 1m
        targets:
            - endpoints:
                - https://epr.elastic.co
              method: GET
secret_references: []
service:
    pipelines:
        metrics:
            exporters:
                - elasticsearch/componentid-0
            receivers:
                - forward
        metrics/componentid-0:
            exporters:
                - forward
            processors:
                - transform/componentid-0
            receivers:
                - httpcheck/componentid-0

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ output_permissions:
- auto_configure
- create_doc
receivers:
httpcheck/componentid:
httpcheck/componentid-0:
collection_interval: 1m
targets:
- endpoints:
Expand All @@ -25,4 +25,4 @@ service:
pipelines:
metrics:
receivers:
- httpcheck/componentid
- httpcheck/componentid-0