Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Remove deprecated APIs (#667)
Browse files Browse the repository at this point in the history
Fixes #494.
  • Loading branch information
rakyll committed Apr 4, 2018
1 parent 2a1d4f6 commit 076344b
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 85 deletions.
2 changes: 1 addition & 1 deletion exporter/prometheus/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
// Create view to see the amount of video processed
// Subscribe will allow view data to be exported.
// Once no longer needed, you can unsubscribe from the view.
if err = view.Subscribe(
if err = view.Register(
&view.View{
Name: "video_count",
Description: "number of videos processed over time",
Expand Down
2 changes: 1 addition & 1 deletion exporter/stackdriver/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Example() {
view.RegisterExporter(exporter)

// Subscribe views to see stats in Stackdriver Monitoring.
if err := view.Subscribe(
if err := view.Register(
ochttp.ClientLatencyView,
ochttp.ClientResponseBytesView,
); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion exporter/stackdriver/examples/stats/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
// Create view to see the processed video size cumulatively.
// Subscribe will allow view data to be exported.
// Once no longer need, you can unsubscribe from the view.
if err := view.Subscribe(&view.View{
if err := view.Register(&view.View{
Name: "my.org/views/video_size_cum",
Description: "processed video size over time",
Measure: videoSize,
Expand Down
4 changes: 2 additions & 2 deletions exporter/stackdriver/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ func TestExporter_makeReq_withCustomMonitoredResource(t *testing.T) {
Measure: m,
Aggregation: view.Count(),
}
if err := view.Subscribe(v); err != nil {
if err := view.Register(v); err != nil {
t.Fatal(err)
}
defer view.Unsubscribe(v)
defer view.Unregister(v)

start := time.Now()
end := start.Add(time.Minute)
Expand Down
2 changes: 1 addition & 1 deletion internal/readme/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func statsExamples() {
_, _, _ = distAgg, countAgg, sumAgg

// START view
if err := view.Subscribe(&view.View{
if err := view.Register(&view.View{
Name: "my.org/video_size_distribution",
Description: "distribution of processed video size over time",
Measure: videoSize,
Expand Down
4 changes: 2 additions & 2 deletions plugin/ocgrpc/client_stats_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestClientDefaultCollections(t *testing.T) {

for _, tc := range tcs {
// Register views.
if err := view.Subscribe(DefaultClientViews...); err != nil {
if err := view.Register(DefaultClientViews...); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -349,7 +349,7 @@ func TestClientDefaultCollections(t *testing.T) {
}

// Unregister views to cleanup.
view.Unsubscribe(DefaultClientViews...)
view.Unregister(DefaultClientViews...)
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/ocgrpc/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func ExampleClientHandler() {
// Subscribe views to collect data.
if err := view.Subscribe(ocgrpc.DefaultClientViews...); err != nil {
if err := view.Register(ocgrpc.DefaultClientViews...); err != nil {
log.Fatal(err)
}

Expand All @@ -39,7 +39,7 @@ func ExampleClientHandler() {

func ExampleServerHandler() {
// Subscribe to views to collect data.
if err := view.Subscribe(ocgrpc.DefaultServerViews...); err != nil {
if err := view.Register(ocgrpc.DefaultServerViews...); err != nil {
log.Fatal(err)
}

Expand Down
8 changes: 4 additions & 4 deletions plugin/ocgrpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestClientHandler(t *testing.T) {
ctx := context.Background()
te := &traceExporter{}
trace.RegisterExporter(te)
if err := ClientRequestCountView.Subscribe(); err != nil {
if err := view.Register(ClientRequestCountView); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func TestClientHandler(t *testing.T) {
}

// Cleanup.
view.Unsubscribe(ClientErrorCountView)
view.Unregister(ClientErrorCountView)
}

func TestServerHandler(t *testing.T) {
Expand All @@ -94,7 +94,7 @@ func TestServerHandler(t *testing.T) {

te := &traceExporter{}
trace.RegisterExporter(te)
if err := ServerRequestCountView.Subscribe(); err != nil {
if err := view.Register(ServerRequestCountView); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func TestServerHandler(t *testing.T) {
}

// Cleanup.
view.Unsubscribe(ServerRequestCountView)
view.Unregister(ServerRequestCountView)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/ocgrpc/server_stats_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func TestServerDefaultCollections(t *testing.T) {
}

for _, tc := range tcs {
if err := view.Subscribe(DefaultServerViews...); err != nil {
if err := view.Register(DefaultServerViews...); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -349,7 +349,7 @@ func TestServerDefaultCollections(t *testing.T) {
}

// Unregister views to cleanup.
view.Unsubscribe(DefaultServerViews...)
view.Unregister(DefaultServerViews...)
}
}

Expand Down
19 changes: 9 additions & 10 deletions plugin/ochttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestClient(t *testing.T) {
}))
defer server.Close()

for _, v := range ochttp.DefaultClientViews {
v.Subscribe()
if err := view.Register(ochttp.DefaultClientViews...); err != nil {
t.Fatalf("Failed to register ochttp.DefaultClientViews error: %v", err)
}

views := []string{
Expand All @@ -54,15 +54,14 @@ func TestClient(t *testing.T) {
}
}

var (
w sync.WaitGroup
tr ochttp.Transport
errs = make(chan error, reqCount)
)
w.Add(reqCount)
var wg sync.WaitGroup
var tr ochttp.Transport
errs := make(chan error, reqCount)
wg.Add(reqCount)

for i := 0; i < reqCount; i++ {
go func() {
defer w.Done()
defer wg.Done()
req, err := http.NewRequest("POST", server.URL, strings.NewReader("req-body"))
if err != nil {
errs <- fmt.Errorf("error creating request: %v", err)
Expand All @@ -81,7 +80,7 @@ func TestClient(t *testing.T) {
}

go func() {
w.Wait()
wg.Wait()
close(errs)
}()

Expand Down
6 changes: 3 additions & 3 deletions plugin/ochttp/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
)

func ExampleTransport() {
if err := view.Subscribe(
// Subscribe to a few default views.
if err := view.Register(
// Register to a few default views.
ochttp.ClientRequestCountByMethod,
ochttp.ClientResponseCountByStatusCode,
ochttp.ClientLatencyView,

// Subscribe to a custom view.
// Register to a custom view.
&view.View{
Name: "httpclient_latency_by_hostpath",
TagKeys: []tag.Key{ochttp.Host, ochttp.Path},
Expand Down
4 changes: 2 additions & 2 deletions plugin/ochttp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func updateMean(mean float64, sample, count int) float64 {
}

func TestHandlerStatsCollection(t *testing.T) {
for _, v := range DefaultServerViews {
v.Subscribe()
if err := view.Register(DefaultServerViews...); err != nil {
t.Fatalf("Failed to register ochttp.DefaultServerViews error: %v", err)
}

views := []string{
Expand Down
14 changes: 0 additions & 14 deletions stats/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ type View struct {
Aggregation *Aggregation
}

// Deprecated: Use &View{}.
func New(name, description string, keys []tag.Key, measure stats.Measure, agg *Aggregation) (*View, error) {
if measure == nil {
panic("measure may not be nil")
}
return &View{
Name: name,
Description: description,
TagKeys: keys,
Measure: measure,
Aggregation: agg,
}, nil
}

// WithName returns a copy of the View with a new name. This is useful for
// renaming views to cope with limitations placed on metric names by various
// backends.
Expand Down
2 changes: 1 addition & 1 deletion stats/view/view_measure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMeasureFloat64AndInt64(t *testing.T) {
Measure: fm,
Aggregation: Sum(),
}
Subscribe(v1, v2)
Register(v1, v2)

stats.Record(context.Background(), im.M(5))
stats.Record(context.Background(), fm.M(2.2))
Expand Down
25 changes: 0 additions & 25 deletions stats/view/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ func Find(name string) (v *View) {
return resp.v
}

// Deprecated: Use the Register function
func Subscribe(v ...*View) error {
return Register(v...)
}

// Deprecated: Use the Unregister function
func Unsubscribe(v ...*View) error {
Unregister(v...)
return nil
}

// Deprecated: Use the Register function.
func (v *View) Subscribe() error {
return Register(v)
}

// Register begins collecting data for the given views.
// Once a view is subscribed, it reports data to the registered exporters.
func Register(views ...*View) error {
Expand Down Expand Up @@ -110,15 +94,6 @@ func Unregister(views ...*View) {
<-req.done
}

// Deprecated: Use the Unregister function instead.
func (v *View) Unsubscribe() error {
if v == nil {
return nil
}
Unregister(v)
return nil
}

func RetrieveData(viewName string) ([]*Row, error) {
req := &retrieveDataReq{
now: time.Now(),
Expand Down
7 changes: 6 additions & 1 deletion stats/view/worker_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ type getViewByNameResp struct {
}

func (cmd *getViewByNameReq) handleCommand(w *worker) {
cmd.c <- &getViewByNameResp{w.views[cmd.name].view}
v := w.views[cmd.name]
if v == nil {
cmd.c <- &getViewByNameResp{nil}
return
}
cmd.c <- &getViewByNameResp{v.view}
}

// registerViewReq is the command to register a view.
Expand Down
14 changes: 7 additions & 7 deletions stats/view/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,8 @@ func Test_Worker_RecordFloat64(t *testing.T) {
}
}

// cleaning up
for _, v := range tc.registrations {
if err := v.Unsubscribe(); err != nil {
t.Fatalf("%v: Unregistering from view %v errored with %v; want no error", tc.label, v.Name, err)
}
}
// Cleaning up.
Unregister(tc.registrations...)
}
}

Expand Down Expand Up @@ -320,7 +316,11 @@ func TestWorkerStarttime(t *testing.T) {

ctx := context.Background()
m := stats.Int64("measure/TestWorkerStarttime", "desc", "unit")
v, _ := New("testview", "", nil, m, Count())
v := &View{
Name: "testview",
Measure: m,
Aggregation: Count(),
}

SetReportingPeriod(25 * time.Millisecond)
if err := Register(v); err != nil {
Expand Down
6 changes: 0 additions & 6 deletions trace/sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ func newDefaultSampler() Sampler {
return ProbabilitySampler(defaultSamplingProbability)
}

// SetDefaultSampler sets the default sampler used when creating new spans.
//
// Deprecated: Use ApplyConfig.
func SetDefaultSampler(sampler Sampler) {
}

// Sampler decides whether a trace should be sampled and exported.
type Sampler func(SamplingParameters) SamplingDecision

Expand Down

0 comments on commit 076344b

Please sign in to comment.