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

WIP: Update vendored gopls to version 0.4.2 #181

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.17.5/go.mod h1:0zV5/ungglgy2Rlm3QK8fbxkXVs+BSJWpJP/+8gUVLY=
k8s.io/apimachinery v0.17.5 h1:QAjfgeTtSGksdkgyaPrIb4lhU16FWMIzxKejYD5S0gc=
k8s.io/apimachinery v0.17.5/go.mod h1:ioIo1G/a+uONV7Tv+ZmCbMG1/a3kVw5YcDdncd8ugQ0=
k8s.io/client-go v0.17.5/go.mod h1:S8uZpBpjJJdEH/fEyxcqg7Rn0P5jH+ilkgBHjriSmNo=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
Expand Down
3 changes: 3 additions & 0 deletions internal/vendored/go-tools.dirs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
event
fakenet
jsonrpc2
lsp/debug/tag
lsp/protocol
span
stack
telemetry
xcontext
2 changes: 1 addition & 1 deletion internal/vendored/go-tools.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gopls/v0.4.0-pre2
gopls/v0.4.2
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package telemetry_test
package event_test

import (
"context"
"io/ioutil"
"log"
"testing"

"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/telemetry/event"
"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/telemetry/export"
"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event"
"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/core"
"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/export"
"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/keys"
"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/label"
)

type Hooks struct {
Expand All @@ -16,12 +19,12 @@ type Hooks struct {
}

var (
aValue = event.NewIntKey("a", "")
bValue = event.NewStringKey("b", "")
aCount = event.NewInt64Key("aCount", "Count of time A is called.")
aStat = event.NewIntKey("aValue", "A value.")
bCount = event.NewInt64Key("B", "Count of time B is called.")
bLength = event.NewIntKey("BLen", "B length.")
aValue = keys.NewInt("a", "")
bValue = keys.NewString("b", "")
aCount = keys.NewInt64("aCount", "Count of time A is called.")
aStat = keys.NewInt("aValue", "A value.")
bCount = keys.NewInt64("B", "Count of time B is called.")
bLength = keys.NewInt("BLen", "B length.")

Baseline = Hooks{
A: func(ctx context.Context, a int) (context.Context, func()) {
Expand All @@ -45,33 +48,33 @@ var (

Log = Hooks{
A: func(ctx context.Context, a int) (context.Context, func()) {
event.Print1(ctx, "A", aValue.Of(a))
core.Log1(ctx, "A", aValue.Of(a))
return ctx, func() {}
},
B: func(ctx context.Context, b string) (context.Context, func()) {
event.Print1(ctx, "B", bValue.Of(b))
core.Log1(ctx, "B", bValue.Of(b))
return ctx, func() {}
},
}

Trace = Hooks{
A: func(ctx context.Context, a int) (context.Context, func()) {
return event.StartSpan1(ctx, "A", aValue.Of(a))
return core.Start1(ctx, "A", aValue.Of(a))
},
B: func(ctx context.Context, b string) (context.Context, func()) {
return event.StartSpan1(ctx, "B", bValue.Of(b))
return core.Start1(ctx, "B", bValue.Of(b))
},
}

Stats = Hooks{
A: func(ctx context.Context, a int) (context.Context, func()) {
event.Record1(ctx, aStat.Of(a))
event.Record1(ctx, aCount.Of(1))
core.Metric1(ctx, aStat.Of(a))
core.Metric1(ctx, aCount.Of(1))
return ctx, func() {}
},
B: func(ctx context.Context, b string) (context.Context, func()) {
event.Record1(ctx, bLength.Of(len(b)))
event.Record1(ctx, bCount.Of(1))
core.Metric1(ctx, bLength.Of(len(b)))
core.Metric1(ctx, bCount.Of(1))
return ctx, func() {}
},
}
Expand Down Expand Up @@ -146,6 +149,6 @@ func init() {
log.SetOutput(ioutil.Discard)
}

func noopExporter(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context {
func noopExporter(ctx context.Context, ev core.Event, lm label.Map) context.Context {
return ctx
}
85 changes: 85 additions & 0 deletions internal/vendored/go-tools/event/core/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package core provides support for event based telemetry.
package core

import (
"fmt"
"time"

"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/label"
)

// Event holds the information about an event of note that ocurred.
type Event struct {
at time.Time

// As events are often on the stack, storing the first few labels directly
// in the event can avoid an allocation at all for the very common cases of
// simple events.
// The length needs to be large enough to cope with the majority of events
// but no so large as to cause undue stack pressure.
// A log message with two values will use 3 labels (one for each value and
// one for the message itself).

static [3]label.Label // inline storage for the first few labels
dynamic []label.Label // dynamically sized storage for remaining labels
}

// eventLabelMap implements label.Map for a the labels of an Event.
type eventLabelMap struct {
event Event
}

func (ev Event) At() time.Time { return ev.at }

func (ev Event) Format(f fmt.State, r rune) {
if !ev.at.IsZero() {
fmt.Fprint(f, ev.at.Format("2006/01/02 15:04:05 "))
}
for index := 0; ev.Valid(index); index++ {
if l := ev.Label(index); l.Valid() {
fmt.Fprintf(f, "\n\t%v", l)
}
}
}

func (ev Event) Valid(index int) bool {
return index >= 0 && index < len(ev.static)+len(ev.dynamic)
}

func (ev Event) Label(index int) label.Label {
if index < len(ev.static) {
return ev.static[index]
}
return ev.dynamic[index-len(ev.static)]
}

func (ev Event) Find(key label.Key) label.Label {
for _, l := range ev.static {
if l.Key() == key {
return l
}
}
for _, l := range ev.dynamic {
if l.Key() == key {
return l
}
}
return label.Label{}
}

func MakeEvent(static [3]label.Label, labels []label.Label) Event {
return Event{
static: static,
dynamic: labels,
}
}

// CloneEvent event returns a copy of the event with the time adjusted to at.
func CloneEvent(ev Event, at time.Time) Event {
ev.at = at
return ev
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package event
package core

import (
"context"
"sync/atomic"
"time"
"unsafe"

"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/label"
)

// Exporter is a function that handles events.
// It may return a modified context and event.
type Exporter func(context.Context, Event, TagMap) context.Context
type Exporter func(context.Context, Event, label.Map) context.Context

var (
exporter unsafe.Pointer
Expand All @@ -35,16 +37,16 @@ func SetExporter(e Exporter) {
}

// deliver is called to deliver an event to the supplied exporter.
// it will fill in the time and generate the basic tag source.
// it will fill in the time.
func deliver(ctx context.Context, exporter Exporter, ev Event) context.Context {
// add the current time to the event
ev.At = time.Now()
ev.at = time.Now()
// hand the event off to the current exporter
return exporter(ctx, ev, ev.Map())
return exporter(ctx, ev, ev)
}

// dispatch is called to deliver an event to the global exporter if set.
func dispatch(ctx context.Context, ev Event) context.Context {
// Export is called to deliver an event to the global exporter if set.
func Export(ctx context.Context, ev Event) context.Context {
// get the global exporter and abort early if there is not one
exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter))
if exporterPtr == nil {
Expand All @@ -53,11 +55,11 @@ func dispatch(ctx context.Context, ev Event) context.Context {
return deliver(ctx, *exporterPtr, ev)
}

// dispatchPair is called to deliver a start event to the supplied exporter.
// ExportPair is called to deliver a start event to the supplied exporter.
// It also returns a function that will deliver the end event to the same
// exporter.
// it will fill in the time and generate the basic tag source.
func dispatchPair(ctx context.Context, begin, end Event) (context.Context, func()) {
// It will fill in the time.
func ExportPair(ctx context.Context, begin, end Event) (context.Context, func()) {
// get the global exporter and abort early if there is not one
exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter))
if exporterPtr == nil {
Expand Down
77 changes: 77 additions & 0 deletions internal/vendored/go-tools/event/core/fast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package core

import (
"context"

"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/keys"
"github.com/prometheus-community/promql-langserver/internal/vendored/go-tools/event/label"
)

// Log1 takes a message and one label delivers a log event to the exporter.
// It is a customized version of Print that is faster and does no allocation.
func Log1(ctx context.Context, message string, t1 label.Label) {
Export(ctx, MakeEvent([3]label.Label{
keys.Msg.Of(message),
t1,
}, nil))
}

// Log2 takes a message and two labels and delivers a log event to the exporter.
// It is a customized version of Print that is faster and does no allocation.
func Log2(ctx context.Context, message string, t1 label.Label, t2 label.Label) {
Export(ctx, MakeEvent([3]label.Label{
keys.Msg.Of(message),
t1,
t2,
}, nil))
}

// Metric1 sends a label event to the exporter with the supplied labels.
func Metric1(ctx context.Context, t1 label.Label) context.Context {
return Export(ctx, MakeEvent([3]label.Label{
keys.Metric.New(),
t1,
}, nil))
}

// Metric2 sends a label event to the exporter with the supplied labels.
func Metric2(ctx context.Context, t1, t2 label.Label) context.Context {
return Export(ctx, MakeEvent([3]label.Label{
keys.Metric.New(),
t1,
t2,
}, nil))
}

// Start1 sends a span start event with the supplied label list to the exporter.
// It also returns a function that will end the span, which should normally be
// deferred.
func Start1(ctx context.Context, name string, t1 label.Label) (context.Context, func()) {
return ExportPair(ctx,
MakeEvent([3]label.Label{
keys.Start.Of(name),
t1,
}, nil),
MakeEvent([3]label.Label{
keys.End.New(),
}, nil))
}

// Start2 sends a span start event with the supplied label list to the exporter.
// It also returns a function that will end the span, which should normally be
// deferred.
func Start2(ctx context.Context, name string, t1, t2 label.Label) (context.Context, func()) {
return ExportPair(ctx,
MakeEvent([3]label.Label{
keys.Start.Of(name),
t1,
t2,
}, nil),
MakeEvent([3]label.Label{
keys.End.New(),
}, nil))
}
7 changes: 7 additions & 0 deletions internal/vendored/go-tools/event/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package event provides a set of packages that cover the main
// concepts of telemetry in an implementation agnostic way.
package event
Loading