From dc28ec1575ab6a91289afdebf5b2dc2e15a0cd46 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 7 Dec 2023 09:32:12 -0800 Subject: [PATCH 1/5] [chore] update versions of go (#9052) Signed-off-by: Alex Boten --- .github/workflows/api-compatibility.yml | 2 +- .github/workflows/build-and-test-windows.yaml | 2 +- .github/workflows/build-and-test.yml | 12 ++++++------ .github/workflows/builder-integration-test.yaml | 2 +- .github/workflows/builder-release.yaml | 2 +- .github/workflows/changelog.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/contrib-tests.yml | 2 +- .github/workflows/perf.yml | 2 +- .github/workflows/prepare-release.yml | 2 +- .github/workflows/tidy-dependencies.yml | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/api-compatibility.yml b/.github/workflows/api-compatibility.yml index 1872911b271..de8bc0cd469 100644 --- a/.github/workflows/api-compatibility.yml +++ b/.github/workflows/api-compatibility.yml @@ -34,7 +34,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 # Generate apidiff states of Main - name: Generate-States diff --git a/.github/workflows/build-and-test-windows.yaml b/.github/workflows/build-and-test-windows.yaml index b78e5e25018..1a8f6115569 100644 --- a/.github/workflows/build-and-test-windows.yaml +++ b/.github/workflows/build-and-test-windows.yaml @@ -19,7 +19,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Cache Go uses: actions/cache@v3 diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a9ee407ea3f..089b02668b8 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Cache Go id: go-cache @@ -42,7 +42,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Cache Go id: go-cache @@ -66,7 +66,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Cache Go id: go-cache @@ -91,7 +91,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Cache Go id: go-cache @@ -133,7 +133,7 @@ jobs: unittest-matrix: strategy: matrix: - go-version: ["~1.21.4", "~1.20.11"] # 1.20 needs quotes otherwise it's interpreted as 1.2 + go-version: ["~1.21.5", "~1.20.12"] # 1.20 needs quotes otherwise it's interpreted as 1.2 runs-on: ubuntu-latest needs: [setup-environment] steps: @@ -253,7 +253,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Cache Go id: go-cache diff --git a/.github/workflows/builder-integration-test.yaml b/.github/workflows/builder-integration-test.yaml index 981897de5c6..d6689b1a8de 100644 --- a/.github/workflows/builder-integration-test.yaml +++ b/.github/workflows/builder-integration-test.yaml @@ -30,6 +30,6 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 - name: Test run: make builder-integration-test diff --git a/.github/workflows/builder-release.yaml b/.github/workflows/builder-release.yaml index 42a8df6df47..51d560f1985 100644 --- a/.github/workflows/builder-release.yaml +++ b/.github/workflows/builder-release.yaml @@ -16,7 +16,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 with: diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 9e9873b2364..64c11b27d92 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -29,7 +29,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 - name: Cache Go id: go-cache uses: actions/cache@v3 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 75b68eb7559..166d65343af 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.yml index 7003881e264..c305af13cda 100644 --- a/.github/workflows/contrib-tests.yml +++ b/.github/workflows/contrib-tests.yml @@ -23,7 +23,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Run Contrib Tests run: | diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index c56e2e6f7ef..515f56fe4e2 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -13,7 +13,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 - name: Run benchmark run: make gobenchmark diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index b0e7f5bdb06..6b7d6d9448c 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -53,7 +53,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 # Prepare Core for release. # - Update CHANGELOG.md file, this is done via chloggen # - Run make prepare-release PREVIOUS_VERSION=1.0.0 RELEASE_CANDIDATE=1.1.0 MODSET=stable diff --git a/.github/workflows/tidy-dependencies.yml b/.github/workflows/tidy-dependencies.yml index df374853a40..e4473a3a291 100644 --- a/.github/workflows/tidy-dependencies.yml +++ b/.github/workflows/tidy-dependencies.yml @@ -16,7 +16,7 @@ jobs: ref: ${{ github.head_ref }} - uses: actions/setup-go@v4 with: - go-version: ~1.20.11 + go-version: ~1.20.12 cache: false - name: Cache Go id: go-cache From f9a38b29c7f35f9eb8f4ea00844ef96b8091e14b Mon Sep 17 00:00:00 2001 From: Dani Louca <59848726+dloucasfx@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:10:04 -0500 Subject: [PATCH 2/5] Introduce HTTP2 health check transport options (#9022) **Description:** This PR introduces options to enable `http/2` health check by exposing `HTTP2ReadIdleTimeout` and `HTTP2PingTimeout` The golang issues are: https://github.com/golang/go/issues/59690 https://github.com/golang/go/issues/36026 In summary, if due to environmental issue the underlying tcp connection used by the http/2 client in the exporter became unstable/unusable/unreachable, unlike http/1, the http/2 client does not forcibly close the connection and redial a new one, instead it keeps using it for 15 minutes (default value of OS `tcp_retries2` ) until the OS cleans it up and a new tcp connection gets established. From OTEL user perspective, one will see a spike in export failures/timeouts for ~15 minutes, this will happen for every connection that got into a bad state, after 15 minutes things will recover until next time the tcp connection gets into a bad state. **Testing:** - Run OTEL with one of the exporters that uses HTTP/2 client, example `signalfx` exporter - For simplicity use a single pipeline/exporter - In a different shell, run this to watch the tcp state of the established connection ``` while (true); do echo date; sudo netstat -anp | grep -E '' | sort -k 5; sleep 2; done ``` - From the netstat, take a note of the source port and the source IP address - replace <> from previous step `sudo iptables -A OUTPUT -s -p tcp --sport -j DROP` - Note how the OTEL exporter export starts timing out Expected Result: - A new connection should be established, similarly to http/1 and exports should succeed Actual Result: - The exports keep failing for ~ 15 minutes or for whatever the OS `tcp_retries2` is configured to - After 15 minutes, a new tcp connection is created and exports start working **Documentation:** Readme is updated with new settings Signed-off-by: Dani Louca --- .chloggen/http2ping.yaml | 25 +++++++++ config/confighttp/README.md | 2 + config/confighttp/confighttp.go | 20 +++++++ config/confighttp/confighttp_test.go | 82 +++++++++++++++++++--------- 4 files changed, 102 insertions(+), 27 deletions(-) create mode 100755 .chloggen/http2ping.yaml diff --git a/.chloggen/http2ping.yaml b/.chloggen/http2ping.yaml new file mode 100755 index 00000000000..b6f2223ed7d --- /dev/null +++ b/.chloggen/http2ping.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: config/confighttp + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Exposes http/2 transport settings to enable health check and workaround golang http/2 issue https://github.com/golang/go/issues/59690 + +# One or more tracking issues or pull requests related to the change +issues: [9022] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] \ No newline at end of file diff --git a/config/confighttp/README.md b/config/confighttp/README.md index a3794ceeed1..0cc0503f539 100644 --- a/config/confighttp/README.md +++ b/config/confighttp/README.md @@ -29,6 +29,8 @@ README](../configtls/README.md). - [`idle_conn_timeout`](https://golang.org/pkg/net/http/#Transport) - [`auth`](../configauth/README.md) - [`disable_keep_alives`](https://golang.org/pkg/net/http/#Transport) +- [`http2_read_idle_timeout`](https://pkg.go.dev/golang.org/x/net/http2#Transport) +- [`http2_ping_timeout`](https://pkg.go.dev/golang.org/x/net/http2#Transport) Example: diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index c83db25d4b6..e41a64cc124 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -6,6 +6,7 @@ package confighttp // import "go.opentelemetry.io/collector/config/confighttp" import ( "crypto/tls" "errors" + "fmt" "io" "net" "net/http" @@ -86,6 +87,16 @@ type HTTPClientSettings struct { // connection for every request. Before enabling this option please consider whether changes // to idle connection settings can achieve your goal. DisableKeepAlives bool `mapstructure:"disable_keep_alives"` + + // This is needed in case you run into + // https://github.com/golang/go/issues/59690 + // https://github.com/golang/go/issues/36026 + // HTTP2ReadIdleTimeout if the connection has been idle for the configured value send a ping frame for health check + // 0s means no health check will be performed. + HTTP2ReadIdleTimeout time.Duration `mapstructure:"http2_read_idle_timeout"` + // HTTP2PingTimeout if there's no response to the ping within the configured value, the connection will be closed. + // If not set or set to 0, it defaults to 15s. + HTTP2PingTimeout time.Duration `mapstructure:"http2_ping_timeout"` } // NewDefaultHTTPClientSettings returns HTTPClientSettings type object with @@ -147,6 +158,15 @@ func (hcs *HTTPClientSettings) ToClient(host component.Host, settings component. transport.DisableKeepAlives = hcs.DisableKeepAlives + if hcs.HTTP2ReadIdleTimeout > 0 { + transport2, transportErr := http2.ConfigureTransports(transport) + if transportErr != nil { + return nil, fmt.Errorf("failed to configure http2 transport: %w", transportErr) + } + transport2.ReadIdleTimeout = hcs.HTTP2ReadIdleTimeout + transport2.PingTimeout = hcs.HTTP2PingTimeout + } + clientTransport := (http.RoundTripper)(transport) // The Auth RoundTripper should always be the innermost to ensure that diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 43a9b865010..3d3bc6d8bc7 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -53,6 +53,7 @@ func TestAllHTTPClientSettings(t *testing.T) { maxIdleConnsPerHost := 40 maxConnsPerHost := 45 idleConnTimeout := 30 * time.Second + http2PingTimeout := 5 * time.Second tests := []struct { name string settings HTTPClientSettings @@ -65,15 +66,17 @@ func TestAllHTTPClientSettings(t *testing.T) { TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, - ReadBufferSize: 1024, - WriteBufferSize: 512, - MaxIdleConns: &maxIdleConns, - MaxIdleConnsPerHost: &maxIdleConnsPerHost, - MaxConnsPerHost: &maxConnsPerHost, - IdleConnTimeout: &idleConnTimeout, - CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, - Compression: "", - DisableKeepAlives: true, + ReadBufferSize: 1024, + WriteBufferSize: 512, + MaxIdleConns: &maxIdleConns, + MaxIdleConnsPerHost: &maxIdleConnsPerHost, + MaxConnsPerHost: &maxConnsPerHost, + IdleConnTimeout: &idleConnTimeout, + CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, + Compression: "", + DisableKeepAlives: true, + HTTP2ReadIdleTimeout: idleConnTimeout, + HTTP2PingTimeout: http2PingTimeout, }, shouldError: false, }, @@ -84,15 +87,17 @@ func TestAllHTTPClientSettings(t *testing.T) { TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, - ReadBufferSize: 1024, - WriteBufferSize: 512, - MaxIdleConns: &maxIdleConns, - MaxIdleConnsPerHost: &maxIdleConnsPerHost, - MaxConnsPerHost: &maxConnsPerHost, - IdleConnTimeout: &idleConnTimeout, - CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, - Compression: "none", - DisableKeepAlives: true, + ReadBufferSize: 1024, + WriteBufferSize: 512, + MaxIdleConns: &maxIdleConns, + MaxIdleConnsPerHost: &maxIdleConnsPerHost, + MaxConnsPerHost: &maxConnsPerHost, + IdleConnTimeout: &idleConnTimeout, + CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, + Compression: "none", + DisableKeepAlives: true, + HTTP2ReadIdleTimeout: idleConnTimeout, + HTTP2PingTimeout: http2PingTimeout, }, shouldError: false, }, @@ -103,15 +108,38 @@ func TestAllHTTPClientSettings(t *testing.T) { TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, - ReadBufferSize: 1024, - WriteBufferSize: 512, - MaxIdleConns: &maxIdleConns, - MaxIdleConnsPerHost: &maxIdleConnsPerHost, - MaxConnsPerHost: &maxConnsPerHost, - IdleConnTimeout: &idleConnTimeout, - CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, - Compression: "gzip", - DisableKeepAlives: true, + ReadBufferSize: 1024, + WriteBufferSize: 512, + MaxIdleConns: &maxIdleConns, + MaxIdleConnsPerHost: &maxIdleConnsPerHost, + MaxConnsPerHost: &maxConnsPerHost, + IdleConnTimeout: &idleConnTimeout, + CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, + Compression: "gzip", + DisableKeepAlives: true, + HTTP2ReadIdleTimeout: idleConnTimeout, + HTTP2PingTimeout: http2PingTimeout, + }, + shouldError: false, + }, + { + name: "all_valid_settings_http2_health_check", + settings: HTTPClientSettings{ + Endpoint: "localhost:1234", + TLSSetting: configtls.TLSClientSetting{ + Insecure: false, + }, + ReadBufferSize: 1024, + WriteBufferSize: 512, + MaxIdleConns: &maxIdleConns, + MaxIdleConnsPerHost: &maxIdleConnsPerHost, + MaxConnsPerHost: &maxConnsPerHost, + IdleConnTimeout: &idleConnTimeout, + CustomRoundTripper: func(next http.RoundTripper) (http.RoundTripper, error) { return next, nil }, + Compression: "gzip", + DisableKeepAlives: true, + HTTP2ReadIdleTimeout: idleConnTimeout, + HTTP2PingTimeout: http2PingTimeout, }, shouldError: false, }, From eed3b4e9c5efaf6d6e5073d13fbd3d57991d4d0f Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Fri, 8 Dec 2023 10:32:06 -0800 Subject: [PATCH 3/5] [chore] update gensemconv to use .tools (#9055) Also updating documentation to specify the semantic-conventions repository instead of the spec repo. Signed-off-by: Alex Boten --- Makefile | 8 ++++---- Makefile.Common | 1 + semconv/README.md | 11 ++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 426af0d5224..c80861ea4d5 100644 --- a/Makefile +++ b/Makefile @@ -227,13 +227,13 @@ genpdata: $(MAKE) fmt # Generate semantic convention constants. Requires a clone of the opentelemetry-specification repo -gensemconv: +gensemconv: $(SEMCONVGEN) @[ "${SPECPATH}" ] || ( echo ">> env var SPECPATH is not set"; exit 1 ) @[ "${SPECTAG}" ] || ( echo ">> env var SPECTAG is not set"; exit 1 ) @echo "Generating semantic convention constants from specification version ${SPECTAG} at ${SPECPATH}" - semconvgen -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/semantic_conventions/. --only=resource -p conventionType=resource -f generated_resource.go - semconvgen -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/semantic_conventions/. --only=event -p conventionType=event -f generated_event.go - semconvgen -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/semantic_conventions/. --only=span -p conventionType=trace -f generated_trace.go + $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=resource -p conventionType=resource -f generated_resource.go + $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=event -p conventionType=event -f generated_event.go + $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=span -p conventionType=trace -f generated_trace.go # Checks that the HEAD of the contrib repo checked out in CONTRIB_PATH compiles # against the current version of this repo. diff --git a/Makefile.Common b/Makefile.Common index 36e0b527bf1..f6095aea562 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -31,6 +31,7 @@ IMPI := $(TOOLS_BIN_DIR)/impi MISSPELL := $(TOOLS_BIN_DIR)/misspell MULTIMOD := $(TOOLS_BIN_DIR)/multimod PORTO := $(TOOLS_BIN_DIR)/porto +SEMCONVGEN := $(TOOLS_BIN_DIR)/semconvgen YQ := $(TOOLS_BIN_DIR)/yq .PHONY: install-tools diff --git a/semconv/README.md b/semconv/README.md index dcbcc71c797..6c9aea8b422 100644 --- a/semconv/README.md +++ b/semconv/README.md @@ -6,14 +6,15 @@ from definitions in the specification. ## Generation To generate the constants you can use the `gensemconv` make target. You must provide the path to the root of a clone of -the `opentelemetry-specification` repository in the `SPECPATH` variable and the version of the conventions to generate +the `semantic-conventions` repository in the `SPECPATH` variable and the version of the conventions to generate in the `SPECTAG` variable. ```console -$ make gensemconv SPECPATH=~/dev/opentelemetry-specification SPECTAG=v1.5.0 -Generating semantic convention constants from specification version v1.5.0 at ~/dev/opentelemetry-specification -semconvgen -o semconv/v1.5.0 -t semconv/template.j2 -s v1.5.0 -i ~/dev/opentelemetry-specification/semantic_conventions/resource -p conventionType=resource -semconvgen -o semconv/v1.5.0 -t semconv/template.j2 -s v1.5.0 -i ~/dev/opentelemetry-specification/semantic_conventions/trace -p conventionType=trace +$ make gensemconv SPECPATH=/tmp/semantic-conventions SPECTAG=v1.22.0 +Generating semantic convention constants from specification version v1.22.0 at /tmp/semantic-conventions +.tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=resource -p conventionType=resource -f generated_resource.go +.tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=event -p conventionType=event -f generated_event.go +.tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=span -p conventionType=trace -f generated_trace.go ``` When generating the constants for a new version ot the specification it is important to note that only From a9ce74ba59b38b5c00f1cf4a070d43f57f0a9ae5 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Fri, 8 Dec 2023 13:59:17 -0800 Subject: [PATCH 4/5] [chore] add semconvkit to reduce toil (#9057) This code, copied from the opentelemetry-go repo, allows to generate schema.go automatically as well, reducing effort needed to generate semantic convention packages in the future --------- Signed-off-by: Alex Boten --- Makefile | 3 +- Makefile.Common | 1 + internal/tools/semconvkit/main.go | 70 +++++++++++++++++++ .../tools/semconvkit/templates/doc.go.tmpl | 9 +++ .../tools/semconvkit/templates/schema.go.tmpl | 9 +++ internal/tools/tools.go | 2 + semconv/README.md | 5 -- 7 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 internal/tools/semconvkit/main.go create mode 100644 internal/tools/semconvkit/templates/doc.go.tmpl create mode 100644 internal/tools/semconvkit/templates/schema.go.tmpl diff --git a/Makefile b/Makefile index c80861ea4d5..764e89a05ec 100644 --- a/Makefile +++ b/Makefile @@ -227,13 +227,14 @@ genpdata: $(MAKE) fmt # Generate semantic convention constants. Requires a clone of the opentelemetry-specification repo -gensemconv: $(SEMCONVGEN) +gensemconv: $(SEMCONVGEN) $(SEMCONVKIT) @[ "${SPECPATH}" ] || ( echo ">> env var SPECPATH is not set"; exit 1 ) @[ "${SPECTAG}" ] || ( echo ">> env var SPECTAG is not set"; exit 1 ) @echo "Generating semantic convention constants from specification version ${SPECTAG} at ${SPECPATH}" $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=resource -p conventionType=resource -f generated_resource.go $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=event -p conventionType=event -f generated_event.go $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=span -p conventionType=trace -f generated_trace.go + $(SEMCONVKIT) -output "semconv/$(SPECTAG)" -tag "$(SPECTAG)" # Checks that the HEAD of the contrib repo checked out in CONTRIB_PATH compiles # against the current version of this repo. diff --git a/Makefile.Common b/Makefile.Common index f6095aea562..82c2dcced4a 100644 --- a/Makefile.Common +++ b/Makefile.Common @@ -32,6 +32,7 @@ MISSPELL := $(TOOLS_BIN_DIR)/misspell MULTIMOD := $(TOOLS_BIN_DIR)/multimod PORTO := $(TOOLS_BIN_DIR)/porto SEMCONVGEN := $(TOOLS_BIN_DIR)/semconvgen +SEMCONVKIT := $(TOOLS_BIN_DIR)/semconvkit YQ := $(TOOLS_BIN_DIR)/yq .PHONY: install-tools diff --git a/internal/tools/semconvkit/main.go b/internal/tools/semconvkit/main.go new file mode 100644 index 00000000000..2dc73c37c05 --- /dev/null +++ b/internal/tools/semconvkit/main.go @@ -0,0 +1,70 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "embed" + "flag" + "log" + "os" + "path/filepath" + "strings" + "text/template" +) + +var ( + out = flag.String("output", "./", "output directory") + tag = flag.String("tag", "", "OpenTelemetry tagged version") + + //go:embed templates/*.tmpl + rootFS embed.FS +) + +// SemanticConventions are information about the semantic conventions being +// generated. +type SemanticConventions struct { + // TagVer is the tagged version (i.e. v1.7.0 and not 1.7.0). + TagVer string +} + +func (sc SemanticConventions) SemVer() string { + return strings.TrimPrefix(*tag, "v") +} + +// render renders all templates to the dest directory using the data. +func render(src, dest string, data *SemanticConventions) error { + tmpls, err := template.ParseFS(rootFS, src) + if err != nil { + return err + } + for _, tmpl := range tmpls.Templates() { + target := filepath.Join(dest, strings.TrimSuffix(tmpl.Name(), ".tmpl")) + // nolint: gosec + wr, err := os.Create(target) + if err != nil { + return err + } + + err = tmpl.Execute(wr, data) + if err != nil { + return err + } + } + + return nil +} + +func main() { + flag.Parse() + + if *tag == "" { + log.Fatalf("invalid tag: %q", *tag) + } + + sc := &SemanticConventions{TagVer: *tag} + + if err := render("templates/*.tmpl", *out, sc); err != nil { + log.Fatal(err) + } +} diff --git a/internal/tools/semconvkit/templates/doc.go.tmpl b/internal/tools/semconvkit/templates/doc.go.tmpl new file mode 100644 index 00000000000..0085e604fae --- /dev/null +++ b/internal/tools/semconvkit/templates/doc.go.tmpl @@ -0,0 +1,9 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +// Package semconv implements OpenTelemetry semantic conventions. +// +// OpenTelemetry semantic conventions are agreed standardized naming +// patterns for OpenTelemetry things. This package represents the {{.TagVer}} +// version of the OpenTelemetry semantic conventions. +package semconv // import "go.opentelemetry.io/collector/semconv/{{.TagVer}}" diff --git a/internal/tools/semconvkit/templates/schema.go.tmpl b/internal/tools/semconvkit/templates/schema.go.tmpl new file mode 100644 index 00000000000..41006fa206b --- /dev/null +++ b/internal/tools/semconvkit/templates/schema.go.tmpl @@ -0,0 +1,9 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package semconv // import "go.opentelemetry.io/collector/semconv/{{.TagVer}}" + +// SchemaURL is the schema URL that matches the version of the semantic conventions +// that this package defines. Semconv packages starting from v1.4.0 must declare +// non-empty schema URL in the form https://opentelemetry.io/schemas/ +const SchemaURL = "https://opentelemetry.io/schemas/{{.SemVer}}" diff --git a/internal/tools/tools.go b/internal/tools/tools.go index 07b2eaf7c54..1756f92b3ef 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -27,4 +27,6 @@ import ( _ "golang.org/x/exp/cmd/apidiff" _ "golang.org/x/tools/cmd/goimports" _ "golang.org/x/vuln/cmd/govulncheck" + + _ "go.opentelemetry.io/collector/internal/tools/semconvkit" ) diff --git a/semconv/README.md b/semconv/README.md index 6c9aea8b422..a453bbafd27 100644 --- a/semconv/README.md +++ b/semconv/README.md @@ -16,8 +16,3 @@ Generating semantic convention constants from specification version v1.22.0 at / .tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=event -p conventionType=event -f generated_event.go .tools/semconvgen -o semconv/v1.22.0 -t semconv/template.j2 -s v1.22.0 -i /tmp/semantic-conventions/model/. --only=span -p conventionType=trace -f generated_trace.go ``` - -When generating the constants for a new version ot the specification it is important to note that only -`generated_trace.go` and `generated_resource.go` are generated automatically. The `schema.go` and `nonstandard.go` -files should be copied from a prior version's package and updated as appropriate. Most important will be to update -the `SchemaURL` constant in `schema.go`. From b79a7c9e4c1d3d0372dff4529a247e19036ffd5b Mon Sep 17 00:00:00 2001 From: Dmitrii Anoshin Date: Fri, 8 Dec 2023 14:01:08 -0800 Subject: [PATCH 5/5] [chore] Remove an outdated changelog entry (#9058) This changelog entry is already rendered as part of 0.90.1 release. Missed to be removed on the merge of release/0.90.x branch into main branch --- .chloggen/remove_noisy_log.yaml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100755 .chloggen/remove_noisy_log.yaml diff --git a/.chloggen/remove_noisy_log.yaml b/.chloggen/remove_noisy_log.yaml deleted file mode 100755 index f9e3e1beb02..00000000000 --- a/.chloggen/remove_noisy_log.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# Use this changelog template to create an entry for release notes. - -# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: bug_fix - -# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) -component: exporterhelper - -# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Remove noisy log - -# One or more tracking issues or pull requests related to the change -issues: [9017] - -# (Optional) One or more lines of additional information to render under the primary note. -# These lines will be padded with 2 spaces and then inserted directly into the document. -# Use pipe (|) for multiline entries. -subtext: - -# Optional: The change log or logs in which this entry should be included. -# e.g. '[user]' or '[user, api]' -# Include 'user' if the change is relevant to end users. -# Include 'api' if there is a change to a library API. -# Default: '[user]' -change_logs: [] \ No newline at end of file