Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade otel version to v1.11.2 #333

Merged
merged 17 commits into from
Dec 9, 2022
Next Next commit
wip, progress so far
  • Loading branch information
Kristina Pathak committed Nov 30, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 000667f186db2a3218c7c78a6471fb1235029d3f
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ Thumbs.db
coverage.*
go.work
go.work.sum
vendor/
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@ require (
go.opentelemetry.io/contrib/propagators/b3 v1.11.1 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1 // indirect
go.opentelemetry.io/otel/sdk/metric v0.31.1-0.20220826135333-55b49c407e07 // indirect
go.opentelemetry.io/otel/sdk/metric v0.33.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -200,10 +199,10 @@ go.opentelemetry.io/otel v1.11.1 h1:4WLLAmcfkmDk2ukNXJyq3/kiz/3UzCaYq6PskJsaou4=
go.opentelemetry.io/otel v1.11.1/go.mod h1:1nNhXBbWSD0nsL38H6btgnFN2k4i0sNLHNNMZMSbUGE=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 h1:X2GndnMCsUPh6CiY2a+frAbNsXaPLbB0soHRYhAZ5Ig=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1/go.mod h1:i8vjiSzbiUC7wOQplijSXMYUpNM93DtlS5CbUT+C6oQ=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.31.0 h1:H0+xwv4shKw0gfj/ZqR13qO2N/dBQogB1OcRjJjV39Y=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.31.0/go.mod h1:nkenGD8vcvs0uN6WhR90ZVHQlgDsRmXicnNadMnk+XQ=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.31.0 h1:BaQ2xM5cPmldVCMvbLoy5tcLUhXCtIhItDYBNw83B7Y=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.31.0/go.mod h1:VRr8tlXQEsTdesDCh0qBe2iKDWhpi3ZqDYw6VlZ8MhI=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.33.0 h1:OT/UjHcjog4A1s1UMCtyehIKS+vpjM5Du0r7KGsH6TE=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.33.0/go.mod h1:0XctNDHEWmiSDIU8NPbJElrK05gBJFcYlGP4FMGo4g4=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.33.0 h1:1SVtGtRsNyGgv1fRfNXfh+sJowIwzF0gkf+61lvTgdg=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.33.0/go.mod h1:ryB27ubOBXsiqfh6MwtSdx5knzbSZtjvPnMMmt3AykQ=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1 h1:MEQNafcNCB0uQIti/oHgU7CZpUMYQ7qigBwMVKycHvc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1/go.mod h1:19O5I2U5iys38SsmT2uDJja/300woyzE1KPIQxEUBUc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1 h1:LYyG/f1W/jzAix16jbksJfMQFpOH/Ma6T639pVPMgfI=
@@ -212,8 +211,8 @@ go.opentelemetry.io/otel/metric v0.33.0 h1:xQAyl7uGEYvrLAiV/09iTJlp1pZnQ9Wl793qb
go.opentelemetry.io/otel/metric v0.33.0/go.mod h1:QlTYc+EnYNq/M2mNk1qDDMRLpqCOj2f/r5c7Fd5FYaI=
go.opentelemetry.io/otel/sdk v1.11.1 h1:F7KmQgoHljhUuJyA+9BiU+EkJfyX5nVVF4wyzWZpKxs=
go.opentelemetry.io/otel/sdk v1.11.1/go.mod h1:/l3FE4SupHJ12TduVjUkZtlfFqDCQJlOlithYrdktys=
go.opentelemetry.io/otel/sdk/metric v0.31.1-0.20220826135333-55b49c407e07 h1:nOHjEUsL5x134vpNDPwCZdp+EmvVE6qcPp9g7gWbf2E=
go.opentelemetry.io/otel/sdk/metric v0.31.1-0.20220826135333-55b49c407e07/go.mod h1:Wx4hLV+yy0fBWE4doK+3sK8O6gcaVHRf0BRvwOzl+jI=
go.opentelemetry.io/otel/sdk/metric v0.33.0 h1:oTqyWfksgKoJmbrs2q7O7ahkJzt+Ipekihf8vhpa9qo=
go.opentelemetry.io/otel/sdk/metric v0.33.0/go.mod h1:xdypMeA21JBOvjjzDUtD0kzIcHO/SPez+a8HOzJPGp0=
go.opentelemetry.io/otel/trace v1.11.1 h1:ofxdnzsNrGBYXbP7t7zpUK281+go5rF7dvdIZXF8gdQ=
go.opentelemetry.io/otel/trace v1.11.1/go.mod h1:f/Q9G7vzk5u91PhbmKbg1Qn0rzH1LJ4vbPHFGkTPtOk=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
316 changes: 158 additions & 158 deletions lightstep/instrumentation/cputime/cputime_test.go
Original file line number Diff line number Diff line change
@@ -1,161 +1,161 @@
// Copyright The OpenTelemetry Authors
// // Copyright The OpenTelemetry Authors
// //
// // Licensed under the Apache License, Version 2.0 (the "License");
// // you may not use this file except in compliance with the License.
// // You may obtain a copy of the License at
// //
// // http://www.apache.org/licenses/LICENSE-2.0
// //
// // Unless required by applicable law or agreed to in writing, software
// // distributed under the License is distributed on an "AS IS" BASIS,
// // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// // See the License for the specific language governing permissions and
// // limitations under the License.
package cputime

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//import (
// "context"
// "fmt"
// "runtime"
// "testing"
// "time"
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cputime

import (
"context"
"fmt"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/export/aggregation"
"go.opentelemetry.io/otel/sdk/metric/metrictest"
)

func getMetric(exp *metrictest.Exporter, name string, lbl attribute.KeyValue) float64 {
for _, r := range exp.GetRecords() {
if r.InstrumentName != name {
continue
}

if lbl.Key != "" {
foundAttribute := false
for _, haveLabel := range r.Attributes {
if haveLabel != lbl {
continue
}
foundAttribute = true
break
}
if !foundAttribute {
continue
}
}

switch r.AggregationKind {
case aggregation.SumKind, aggregation.HistogramKind:
return r.Sum.CoerceToFloat64(r.NumberKind)
case aggregation.LastValueKind:
return r.LastValue.CoerceToFloat64(r.NumberKind)
default:
panic(fmt.Sprintf("invalid aggregation type: %v", r.AggregationKind))
}
}
panic("Could not locate a metric in test output")
}

func TestProcessCPU(t *testing.T) {
provider, exp := metrictest.NewTestMeterProvider()
err := Start(
WithMeterProvider(provider),
)
require.NoError(t, err)

ctx := context.Background()

// This is a second copy of the same source of information.
// We ultimately have to trust the information source, the
// test here is to be sure the information is correctly
// translated into metrics.
c, err := newCputime(config{
MeterProvider: provider,
})
require.NoError(t, err)

start := time.Now()
for time.Since(start) < time.Second {
// This has a mix of user and system time, so serves
// the purpose of advancing both process and host,
// user and system CPU usage.
_, _, _, _ = c.getProcessTimes(ctx)
}

beforeUser, beforeSystem, _, _ := c.getProcessTimes(ctx)

require.NoError(t, exp.Collect(ctx))

processUser := getMetric(exp, "process.cpu.time", AttributeCPUTimeUser[0])
processSystem := getMetric(exp, "process.cpu.time", AttributeCPUTimeSystem[0])

afterUser, afterSystem, _, _ := c.getProcessTimes(ctx)

// Validate process times:
// User times are in range
require.LessOrEqual(t, beforeUser, processUser)
require.GreaterOrEqual(t, afterUser, processUser)
// System times are in range
require.LessOrEqual(t, beforeSystem, processSystem)
require.GreaterOrEqual(t, afterSystem, processSystem)
}

func TestProcessUptime(t *testing.T) {
ctx := context.Background()
y2k, err := time.Parse(time.RFC3339, "2000-01-01T00:00:00Z")
require.NoError(t, err)
expectUptime := time.Since(y2k).Seconds()

var save time.Time
processStartTime, save = y2k, processStartTime
defer func() {
processStartTime = save
}()

provider, exp := metrictest.NewTestMeterProvider()
c, err := newCputime(config{MeterProvider: provider})
require.NoError(t, err)
require.NoError(t, c.register())

require.NoError(t, exp.Collect(ctx))
procUptime := getMetric(exp, "process.uptime", attribute.KeyValue{})

require.LessOrEqual(t, expectUptime, procUptime)
}

func TestProcessGCCPUTime(t *testing.T) {
ctx := context.Background()

provider, exp := metrictest.NewTestMeterProvider()
c, err := newCputime(config{
MeterProvider: provider,
})
require.NoError(t, err)
require.NoError(t, c.register())

require.NoError(t, exp.Collect(ctx))
initialUtime := getMetric(exp, "process.cpu.time", AttributeCPUTimeUser[0])
initialStime := getMetric(exp, "process.cpu.time", AttributeCPUTimeSystem[0])
initialGCtime := getMetric(exp, "process.runtime.go.gc.cpu.time", attribute.KeyValue{})

// Make garbage
for i := 0; i < 2; i++ {
var garbage []struct{}
for start := time.Now(); time.Since(start) < time.Second/16; {
garbage = append(garbage, struct{}{})
}
require.Less(t, 0, len(garbage))
runtime.GC()

require.NoError(t, exp.Collect(ctx))
utime := -initialUtime + getMetric(exp, "process.cpu.time", AttributeCPUTimeUser[0])
stime := -initialStime + getMetric(exp, "process.cpu.time", AttributeCPUTimeSystem[0])
gctime := -initialGCtime + getMetric(exp, "process.runtime.go.gc.cpu.time", attribute.KeyValue{})

require.LessOrEqual(t, gctime, utime+stime)
}
}
// "github.com/stretchr/testify/require"
//
// "go.opentelemetry.io/otel/attribute"
// "go.opentelemetry.io/otel/sdk/metric/export/aggregation"
//)
//
//func getMetric(exp *metrictest.Exporter, name string, lbl attribute.KeyValue) float64 {
// for _, r := range exp.GetRecords() {
// if r.InstrumentName != name {
// continue
// }
//
// if lbl.Key != "" {
// foundAttribute := false
// for _, haveLabel := range r.Attributes {
// if haveLabel != lbl {
// continue
// }
// foundAttribute = true
// break
// }
// if !foundAttribute {
// continue
// }
// }
//
// switch r.AggregationKind {
// case aggregation.SumKind, aggregation.HistogramKind:
// return r.Sum.CoerceToFloat64(r.NumberKind)
// case aggregation.LastValueKind:
// return r.LastValue.CoerceToFloat64(r.NumberKind)
// default:
// panic(fmt.Sprintf("invalid aggregation type: %v", r.AggregationKind))
// }
// }
// panic("Could not locate a metric in test output")
//}
//
//func TestProcessCPU(t *testing.T) {
// provider, exp := metrictest.NewTestMeterProvider()
// err := Start(
// WithMeterProvider(provider),
// )
// require.NoError(t, err)
//
// ctx := context.Background()
//
// // This is a second copy of the same source of information.
// // We ultimately have to trust the information source, the
// // test here is to be sure the information is correctly
// // translated into metrics.
// c, err := newCputime(config{
// MeterProvider: provider,
// })
// require.NoError(t, err)
//
// start := time.Now()
// for time.Since(start) < time.Second {
// // This has a mix of user and system time, so serves
// // the purpose of advancing both process and host,
// // user and system CPU usage.
// _, _, _, _ = c.getProcessTimes(ctx)
// }
//
// beforeUser, beforeSystem, _, _ := c.getProcessTimes(ctx)
//
// require.NoError(t, exp.Collect(ctx))
//
// processUser := getMetric(exp, "process.cpu.time", AttributeCPUTimeUser[0])
// processSystem := getMetric(exp, "process.cpu.time", AttributeCPUTimeSystem[0])
//
// afterUser, afterSystem, _, _ := c.getProcessTimes(ctx)
//
// // Validate process times:
// // User times are in range
// require.LessOrEqual(t, beforeUser, processUser)
// require.GreaterOrEqual(t, afterUser, processUser)
// // System times are in range
// require.LessOrEqual(t, beforeSystem, processSystem)
// require.GreaterOrEqual(t, afterSystem, processSystem)
//}
//
//func TestProcessUptime(t *testing.T) {
// ctx := context.Background()
// y2k, err := time.Parse(time.RFC3339, "2000-01-01T00:00:00Z")
// require.NoError(t, err)
// expectUptime := time.Since(y2k).Seconds()
//
// var save time.Time
// processStartTime, save = y2k, processStartTime
// defer func() {
// processStartTime = save
// }()
//
// provider, exp := metrictest.NewTestMeterProvider()
// c, err := newCputime(config{MeterProvider: provider})
// require.NoError(t, err)
// require.NoError(t, c.register())
//
// require.NoError(t, exp.Collect(ctx))
// procUptime := getMetric(exp, "process.uptime", attribute.KeyValue{})
//
// require.LessOrEqual(t, expectUptime, procUptime)
//}
//
//func TestProcessGCCPUTime(t *testing.T) {
// ctx := context.Background()
//
// provider, exp := metrictest.NewTestMeterProvider()
// c, err := newCputime(config{
// MeterProvider: provider,
// })
// require.NoError(t, err)
// require.NoError(t, c.register())
//
// require.NoError(t, exp.Collect(ctx))
// initialUtime := getMetric(exp, "process.cpu.time", AttributeCPUTimeUser[0])
// initialStime := getMetric(exp, "process.cpu.time", AttributeCPUTimeSystem[0])
// initialGCtime := getMetric(exp, "process.runtime.go.gc.cpu.time", attribute.KeyValue{})
//
// // Make garbage
// for i := 0; i < 2; i++ {
// var garbage []struct{}
// for start := time.Now(); time.Since(start) < time.Second/16; {
// garbage = append(garbage, struct{}{})
// }
// require.Less(t, 0, len(garbage))
// runtime.GC()
//
// require.NoError(t, exp.Collect(ctx))
// utime := -initialUtime + getMetric(exp, "process.cpu.time", AttributeCPUTimeUser[0])
// stime := -initialStime + getMetric(exp, "process.cpu.time", AttributeCPUTimeSystem[0])
// gctime := -initialGCtime + getMetric(exp, "process.runtime.go.gc.cpu.time", attribute.KeyValue{})
//
// require.LessOrEqual(t, gctime, utime+stime)
// }
//}
Loading