1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-06-27 00:21:15 +02:00
Files
opentelemetry-go/schema/v1.1/parser_test.go

174 lines
5.1 KiB
Go
Raw Normal View History

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package schema
import (
"testing"
"github.com/stretchr/testify/assert"
ast10 "go.opentelemetry.io/otel/schema/v1.0/ast"
types10 "go.opentelemetry.io/otel/schema/v1.0/types"
ast11 "go.opentelemetry.io/otel/schema/v1.1/ast"
types11 "go.opentelemetry.io/otel/schema/v1.1/types"
)
func TestParseSchemaFile(t *testing.T) {
ts, err := ParseFile("testdata/valid-example.yaml")
assert.NoError(t, err)
assert.NotNil(t, ts)
chore(deps): update module github.com/antonboom/testifylint to v1.6.0 (#6440) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/Antonboom/testifylint](https://redirect.github.com/Antonboom/testifylint) | `v1.5.2` -> `v1.6.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fAntonboom%2ftestifylint/v1.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fAntonboom%2ftestifylint/v1.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fAntonboom%2ftestifylint/v1.5.2/v1.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fAntonboom%2ftestifylint/v1.5.2/v1.6.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>Antonboom/testifylint (github.com/Antonboom/testifylint)</summary> ### [`v1.6.0`](https://redirect.github.com/Antonboom/testifylint/releases/tag/v1.6.0): – new `equal-values` and `suite-method-signature` [Compare Source](https://redirect.github.com/Antonboom/testifylint/compare/v1.5.2...v1.6.0) #### What's Changed ##### New checkers - new checker `equal-values` by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/223](https://redirect.github.com/Antonboom/testifylint/pull/223) - new checker `suite-method-signature` by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/228](https://redirect.github.com/Antonboom/testifylint/pull/228) ##### New features - `len`: support len-len and value-len cases by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/204](https://redirect.github.com/Antonboom/testifylint/pull/204) - `error-is-as`: support NotErrorAs by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/219](https://redirect.github.com/Antonboom/testifylint/pull/219) - `useless-assert`: add NotElementsMatch and NotErrorAs by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/220](https://redirect.github.com/Antonboom/testifylint/pull/220) - `formatter`: support non-string-message checks by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/221](https://redirect.github.com/Antonboom/testifylint/pull/221) - `formatter`: warn on empty message by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/225](https://redirect.github.com/Antonboom/testifylint/pull/225) - `empty`: support empty strings, Zero for strings and len + bubbled useless-assert cases by [@&#8203;ccoVeille](https://redirect.github.com/ccoVeille) in [https://github.com/Antonboom/testifylint/pull/129](https://redirect.github.com/Antonboom/testifylint/pull/129) ##### New fixes - `negative-positive`: remove untyping, ignore Negative for len comparisons by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/226](https://redirect.github.com/Antonboom/testifylint/pull/226) - fixes: support `assert.CollectT` by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/233](https://redirect.github.com/Antonboom/testifylint/pull/233) ##### Bump deps - Upgrade testdata to v1.10.0 of testify by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/218](https://redirect.github.com/Antonboom/testifylint/pull/218) - Go 1.24 by [@&#8203;Antonboom](https://redirect.github.com/Antonboom) in [https://github.com/Antonboom/testifylint/pull/234](https://redirect.github.com/Antonboom/testifylint/pull/234) - build(deps): bump golang.org/x/tools from 0.26.0 to 0.27.0 by [@&#8203;dependabot](https://redirect.github.com/dependabot) in [https://github.com/Antonboom/testifylint/pull/206](https://redirect.github.com/Antonboom/testifylint/pull/206) - build(deps): bump rlespinasse/github-slug-action from 4.4.1 to 5.0.0 by [@&#8203;dependabot](https://redirect.github.com/dependabot) in [https://github.com/Antonboom/testifylint/pull/207](https://redirect.github.com/Antonboom/testifylint/pull/207) - build(deps): bump golang.org/x/tools from 0.27.0 to 0.29.0 by [@&#8203;dependabot](https://redirect.github.com/dependabot) in [https://github.com/Antonboom/testifylint/pull/214](https://redirect.github.com/Antonboom/testifylint/pull/214) **Full Changelog**: https://github.com/Antonboom/testifylint/compare/v1.5.2...v1.6.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-go). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMDAuMiIsInVwZGF0ZWRJblZlciI6IjM5LjIwMC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJTa2lwIENoYW5nZWxvZyIsImRlcGVuZGVuY2llcyJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com>
2025-03-13 14:31:12 -07:00
assert.Equal(
t, &ast11.Schema{
FileFormat: "1.1.0",
SchemaURL: "https://opentelemetry.io/schemas/1.1.0",
Versions: map[types11.TelemetryVersion]ast11.VersionDef{
"1.0.0": {},
"1.1.0": {
All: ast10.Attributes{
Changes: []ast10.AttributeChange{
{
RenameAttributes: &ast10.RenameAttributes{
AttributeMap: ast10.AttributeMap{
"k8s.cluster.name": "kubernetes.cluster.name",
"k8s.namespace.name": "kubernetes.namespace.name",
"k8s.node.name": "kubernetes.node.name",
"k8s.node.uid": "kubernetes.node.uid",
"k8s.pod.name": "kubernetes.pod.name",
"k8s.pod.uid": "kubernetes.pod.uid",
"k8s.container.name": "kubernetes.container.name",
"k8s.replicaset.name": "kubernetes.replicaset.name",
"k8s.replicaset.uid": "kubernetes.replicaset.uid",
"k8s.cronjob.name": "kubernetes.cronjob.name",
"k8s.cronjob.uid": "kubernetes.cronjob.uid",
"k8s.job.name": "kubernetes.job.name",
"k8s.job.uid": "kubernetes.job.uid",
"k8s.statefulset.name": "kubernetes.statefulset.name",
"k8s.statefulset.uid": "kubernetes.statefulset.uid",
"k8s.daemonset.name": "kubernetes.daemonset.name",
"k8s.daemonset.uid": "kubernetes.daemonset.uid",
"k8s.deployment.name": "kubernetes.deployment.name",
"k8s.deployment.uid": "kubernetes.deployment.uid",
"service.namespace": "service.namespace.name",
},
},
},
},
},
Resources: ast10.Attributes{
Changes: []ast10.AttributeChange{
{
RenameAttributes: &ast10.RenameAttributes{
AttributeMap: ast10.AttributeMap{
"telemetry.auto.version": "telemetry.auto_instr.version",
},
},
},
},
},
Spans: ast10.Spans{
Changes: []ast10.SpansChange{
{
RenameAttributes: &ast10.AttributeMapForSpans{
AttributeMap: ast10.AttributeMap{
"peer.service": "peer.service.name",
},
ApplyToSpans: []types10.SpanName{"HTTP GET"},
},
},
},
},
SpanEvents: ast10.SpanEvents{
Changes: []ast10.SpanEventsChange{
{
RenameEvents: &ast10.RenameSpanEvents{
EventNameMap: map[string]string{
"exception.stacktrace": "exception.stack_trace",
},
},
},
{
RenameAttributes: &ast10.RenameSpanEventAttributes{
ApplyToEvents: []types10.EventName{"exception.stack_trace"},
AttributeMap: ast10.AttributeMap{
"peer.service": "peer.service.name",
},
},
},
},
},
Logs: ast10.Logs{
Changes: []ast10.LogsChange{
{
RenameAttributes: &ast10.RenameAttributes{
AttributeMap: map[string]string{
"process.executable_name": "process.executable.name",
},
},
},
},
},
Metrics: ast11.Metrics{
Changes: []ast11.MetricsChange{
{
RenameAttributes: &ast10.AttributeMapForMetrics{
AttributeMap: map[string]string{
"http.status_code": "http.response_status_code",
},
},
},
{
RenameMetrics: map[types10.MetricName]types10.MetricName{
"container.cpu.usage.total": "cpu.usage.total",
"container.memory.usage.max": "memory.usage.max",
},
},
{
RenameAttributes: &ast10.AttributeMapForMetrics{
ApplyToMetrics: []types10.MetricName{
"system.cpu.utilization",
"system.memory.usage",
"system.memory.utilization",
"system.paging.usage",
},
AttributeMap: map[string]string{
"status": "state",
},
},
},
{
Split: &ast11.SplitMetric{
ApplyToMetric: "system.paging.operations",
ByAttribute: "direction",
MetricsFromAttributes: map[types10.MetricName]types11.AttributeValue{
"system.paging.operations.in": "in",
"system.paging.operations.out": "out",
},
},
},
},
},
},
},
}, ts,
)
}
func TestFailParseFileUnsupportedFileFormat(t *testing.T) {
ts, err := ParseFile("testdata/unsupported-file-format.yaml")
assert.ErrorContains(t, err, "unsupported schema file format minor version number")
assert.Nil(t, ts)
}
func TestFailParseFileUnknownField(t *testing.T) {
ts, err := ParseFile("testdata/unknown-field.yaml")
assert.ErrorContains(t, err, "field Resources not found in type ast.VersionDef")
assert.Nil(t, ts)
}