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
14 changes: 9 additions & 5 deletions internal/testrunner/runners/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,14 @@ var uniqueOtelComponentIDReplace = policyEntryReplace{
// - endpoints:
// - https://epr.elastic.co
// method: GET
var otelComponentIDsRegexp = regexp.MustCompile(`(?m)^(?:extensions|receivers|processors|connectors|exporters):(?:\s\{\}\n|\n(?:\s{2,}.+\n)+)`)
// 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
// policies. This preparation is based on removing contents that are generated, or replace them
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
88 changes: 88 additions & 0 deletions internal/testrunner/runners/policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,40 @@ processors:
batch/e6e379c5-6446-4090-af10-a9e5f8fc4640:
send_batch_size: 10000
timeout: 10s
transform/otelcol-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-otelcol-httpcheck-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-routing:
metric_statements:
- context: datapoint
statements:
- set(attributes["data_stream.type"], "metrics")
- set(attributes["data_stream.dataset"], "httpcheck.check")
- set(attributes["data_stream.namespace"], "ep")
connectors:
forward: {}
receivers:
httpcheck/4bae34b3-8f66-49c1-b04f-d58af1b5f743:
collection_interval: 1m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
httpcheck/otelcol-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-otelcol-httpcheck-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd:
collection_interval: 2m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
secret_references: []
service:
extensions:
- health_check/31c94f44-214a-4778-8a36-acc2634096f7
pipelines:
metrics/otelcol-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-otelcol-httpcheck-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd:
receivers:
- >-
httpcheck/otelcol-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-otelcol-httpcheck-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd
processors:
- >-
transform/otelcol-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-otelcol-httpcheck-check-9987a1b9-3a12-43e8-a0a2-e83fa9deebfd-routing
logs:
receivers:
- httpcheck/4bae34b3-8f66-49c1-b04f-d58af1b5f743
Expand Down Expand Up @@ -357,18 +379,40 @@ processors:
batch/8ec6ee99-2176-4231-9668-908069c77784:
send_batch_size: 10000
timeout: 10s
transform/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-routing:
metric_statements:
- context: datapoint
statements:
- set(attributes["data_stream.type"], "metrics")
- set(attributes["data_stream.dataset"], "httpcheck.check")
- set(attributes["data_stream.namespace"], "ep")
connectors:
forward: {}
receivers:
httpcheck/b0f518d6-4e2d-4c5d-bda7-f9808df537b7:
collection_interval: 1m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
httpcheck/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77:
collection_interval: 2m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
secret_references: []
service:
extensions:
- health_check/4391d954-1ffe-4014-a256-5eda78a71829
pipelines:
metrics/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77:
receivers:
- >-
httpcheck/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77
processors:
- >-
transform/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-routing
logs:
receivers:
- httpcheck/b0f518d6-4e2d-4c5d-bda7-f9808df537b7
Expand Down Expand Up @@ -406,18 +450,40 @@ processors:
batch/componentid-1:
send_batch_size: 10000
timeout: 10s
transform/componentid-2:
metric_statements:
- context: datapoint
statements:
- set(attributes["data_stream.type"], "metrics")
- set(attributes["data_stream.dataset"], "httpcheck.check")
- set(attributes["data_stream.namespace"], "ep")
connectors:
forward: {}
receivers:
httpcheck/componentid-0:
collection_interval: 1m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
httpcheck/componentid-1:
collection_interval: 2m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
secret_references: []
service:
extensions:
- health_check/componentid-0
pipelines:
metrics/componentid-0:
receivers:
- >-
httpcheck/componentid-1
processors:
- >-
transform/componentid-2
logs:
receivers:
- httpcheck/componentid-0
Expand Down Expand Up @@ -451,18 +517,40 @@ processors:
batch/8ec6ee99-2176-4231-9668-908069c77784:
send_batch_size: 10000
timeout: 10s
transform/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-routing:
metric_statements:
- context: datapoint
statements:
- set(attributes["data_stream.type"], "metrics")
- set(attributes["data_stream.dataset"], "httpcheck.check")
- set(attributes["data_stream.namespace"], "ep")
connectors:
forward: {}
receivers:
httpcheck/b0f518d6-4e2d-4c5d-bda7-f9808df537b7:
collection_interval: 1m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
httpcheck/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77:
collection_interval: 2m
targets:
- endpoints:
- https://epr.elastic.co
method: GET
secret_references: []
service:
extensions:
- health_check/4391d954-1ffe-4014-a256-5eda78a71828
pipelines:
metrics/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added example with a service pipeline containing a suffix in order to be able to define several pipelines of the same signal.

receivers:
- >-
httpcheck/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77
Comment on lines +549 to +550
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added example with the syntax - >- to set an array element.

processors:
- >-
transform/otelcol-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-otelcol-httpcheck-check-12bd7179-ea83-494b-9f2c-5bf818cd6a77-routing
logs:
receivers:
- httpcheck/b0f518d6-4e2d-4c5d-bda7-f9808df537b7
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