From 87e92536fd944779e4e26a40867aebff9ffa4c0f Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Mon, 15 Jul 2019 14:37:23 -0400 Subject: [PATCH] internal/lsp: the json wire format of the open cencus agent These are hand written structs that when passed through the standard json encoder produce output that mathches the json form of the open census protobuf messages. This allows us to talk to the agent without any extra dependancies. Change-Id: I23d617018009520aad3832e0425ed0a53c51fd1f Reviewed-on: https://go-review.googlesource.com/c/tools/+/186678 Run-TryBot: Ian Cottrell Reviewed-by: Emmanuel Odeke Reviewed-by: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/telemetry/ocagent/wire/common.go | 101 ++++++++++++++ internal/lsp/telemetry/ocagent/wire/core.go | 17 +++ .../lsp/telemetry/ocagent/wire/metrics.go | 130 ++++++++++++++++++ internal/lsp/telemetry/ocagent/wire/trace.go | 112 +++++++++++++++ 4 files changed, 360 insertions(+) create mode 100644 internal/lsp/telemetry/ocagent/wire/common.go create mode 100644 internal/lsp/telemetry/ocagent/wire/core.go create mode 100644 internal/lsp/telemetry/ocagent/wire/metrics.go create mode 100644 internal/lsp/telemetry/ocagent/wire/trace.go diff --git a/internal/lsp/telemetry/ocagent/wire/common.go b/internal/lsp/telemetry/ocagent/wire/common.go new file mode 100644 index 0000000000..b53fb8159f --- /dev/null +++ b/internal/lsp/telemetry/ocagent/wire/common.go @@ -0,0 +1,101 @@ +// 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 wire + +// This file holds common ocagent types + +type Node struct { + Identifier *ProcessIdentifier `json:"identifier,omitempty"` + LibraryInfo *LibraryInfo `json:"library_info,omitempty"` + ServiceInfo *ServiceInfo `json:"service_info,omitempty"` + Attributes map[string]string `json:"attributes,omitempty"` +} + +type Resource struct { + Type string `json:"type,omitempty"` + Labels map[string]string `json:"labels,omitempty"` +} + +type TruncatableString struct { + Value string `json:"value,omitempty"` + TruncatedByteCount int32 `json:"truncated_byte_count,omitempty"` +} + +type Attributes struct { + AttributeMap map[string]Attribute `json:"attributeMap,omitempty"` + DroppedAttributesCount int32 `json:"dropped_attributes_count,omitempty"` +} + +type StringAttribute struct { + StringValue *TruncatableString `json:"stringValue,omitempty"` +} + +type IntAttribute struct { + IntValue int64 `json:"intValue,omitempty"` +} + +type BoolAttribute struct { + BoolValue bool `json:"boolValue,omitempty"` +} + +type DoubleAttribute struct { + DoubleValue float64 `json:"doubleValue,omitempty"` +} + +type Attribute interface { + tagAttribute() +} + +func (StringAttribute) tagAttribute() {} +func (IntAttribute) tagAttribute() {} +func (BoolAttribute) tagAttribute() {} +func (DoubleAttribute) tagAttribute() {} + +type StackTrace struct { + StackFrames *StackFrames `json:"stack_frames,omitempty"` + StackTraceHashId uint64 `json:"stack_trace_hash_id,omitempty"` +} + +type StackFrames struct { + Frame []*StackFrame `json:"frame,omitempty"` + DroppedFramesCount int32 `json:"dropped_frames_count,omitempty"` +} + +type StackFrame struct { + FunctionName *TruncatableString `json:"function_name,omitempty"` + OriginalFunctionName *TruncatableString `json:"original_function_name,omitempty"` + FileName *TruncatableString `json:"file_name,omitempty"` + LineNumber int64 `json:"line_number,omitempty"` + ColumnNumber int64 `json:"column_number,omitempty"` + LoadModule *Module `json:"load_module,omitempty"` + SourceVersion *TruncatableString `json:"source_version,omitempty"` +} + +type Module struct { + Module *TruncatableString `json:"module,omitempty"` + BuildId *TruncatableString `json:"build_id,omitempty"` +} + +type ProcessIdentifier struct { + HostName string `json:"host_name,omitempty"` + Pid uint32 `json:"pid,omitempty"` + StartTimestamp Timestamp `json:"start_timestamp,omitempty"` +} + +type LibraryInfo struct { + Language Language `json:"language,omitempty"` + ExporterVersion string `json:"exporter_version,omitempty"` + CoreLibraryVersion string `json:"core_library_version,omitempty"` +} + +type Language int32 + +const ( + LanguageGo Language = 4 +) + +type ServiceInfo struct { + Name string `json:"name,omitempty"` +} diff --git a/internal/lsp/telemetry/ocagent/wire/core.go b/internal/lsp/telemetry/ocagent/wire/core.go new file mode 100644 index 0000000000..95c05d6690 --- /dev/null +++ b/internal/lsp/telemetry/ocagent/wire/core.go @@ -0,0 +1,17 @@ +// 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 wire + +// This file contains type that match core proto types + +type Timestamp = string + +type Int64Value struct { + Value int64 `json:"value,omitempty"` +} + +type DoubleValue struct { + Value float64 `json:"value,omitempty"` +} diff --git a/internal/lsp/telemetry/ocagent/wire/metrics.go b/internal/lsp/telemetry/ocagent/wire/metrics.go new file mode 100644 index 0000000000..ea82becfd2 --- /dev/null +++ b/internal/lsp/telemetry/ocagent/wire/metrics.go @@ -0,0 +1,130 @@ +// 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 wire + +type ExportMetricsServiceRequest struct { + Node *Node `json:"node,omitempty"` + Metrics []*Metric `json:"metrics,omitempty"` + Resource *Resource `json:"resource,omitempty"` +} + +type Metric struct { + MetricDescriptor *MetricDescriptor `json:"metric_descriptor,omitempty"` + Timeseries []*TimeSeries `json:"timeseries,omitempty"` + Resource *Resource `json:"resource,omitempty"` +} + +type MetricDescriptor struct { + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Unit string `json:"unit,omitempty"` + Type MetricDescriptor_Type `json:"type,omitempty"` + LabelKeys []*LabelKey `json:"label_keys,omitempty"` +} + +type MetricDescriptor_Type int32 + +const ( + MetricDescriptor_UNSPECIFIED MetricDescriptor_Type = 0 + MetricDescriptor_GAUGE_INT64 MetricDescriptor_Type = 1 + MetricDescriptor_GAUGE_DOUBLE MetricDescriptor_Type = 2 + MetricDescriptor_GAUGE_DISTRIBUTION MetricDescriptor_Type = 3 + MetricDescriptor_CUMULATIVE_INT64 MetricDescriptor_Type = 4 + MetricDescriptor_CUMULATIVE_DOUBLE MetricDescriptor_Type = 5 + MetricDescriptor_CUMULATIVE_DISTRIBUTION MetricDescriptor_Type = 6 + MetricDescriptor_SUMMARY MetricDescriptor_Type = 7 +) + +type LabelKey struct { + Key string `json:"key,omitempty"` + Description string `json:"description,omitempty"` +} + +type TimeSeries struct { + StartTimestamp *Timestamp `json:"start_timestamp,omitempty"` + LabelValues []*LabelValue `json:"label_values,omitempty"` + Points []*Point `json:"points,omitempty"` +} + +type LabelValue struct { + Value string `json:"value,omitempty"` + HasValue bool `json:"has_value,omitempty"` +} + +type Point struct { + Timestamp *Timestamp `json:"timestamp,omitempty"` + Value PointValue `json:"value,omitempty"` +} + +type PointInt64Value struct { + Int64Value int64 `json:"int64Value,omitempty"` +} + +type PointDoubleValue struct { + DoubleValue float64 `json:"doubleValue,omitempty"` +} + +type PointDistributionValue struct { + DistributionValue *DistributionValue `json:"distributionValue,omitempty"` +} + +type PointSummaryValue struct { + SummaryValue *SummaryValue `json:"summaryValue,omitempty"` +} + +type PointValue interface { + tagPointValue() +} + +func (PointInt64Value) tagPointValue() {} +func (PointDoubleValue) tagPointValue() {} +func (PointDistributionValue) tagPointValue() {} +func (PointSummaryValue) tagPointValue() {} + +type DistributionValue struct { + Count int64 `json:"count,omitempty"` + Sum float64 `json:"sum,omitempty"` + SumOfSquaredDeviation float64 `json:"sum_of_squared_deviation,omitempty"` + BucketOptions BucketOptions `json:"bucket_options,omitempty"` + Buckets []*Bucket `json:"buckets,omitempty"` +} + +type BucketOptionsExplicit struct { + Bounds []float64 `json:"bounds,omitempty"` +} + +type BucketOptions interface { + tagBucketOptions() +} + +func (BucketOptionsExplicit) tagBucketOptions() {} + +type Bucket struct { + Count int64 `json:"count,omitempty"` + Exemplar *Exemplar `json:"exemplar,omitempty"` +} + +type Exemplar struct { + Value float64 `json:"value,omitempty"` + Timestamp *Timestamp `json:"timestamp,omitempty"` + Attachments map[string]string `json:"attachments,omitempty"` +} + +type SummaryValue struct { + Count *Int64Value `json:"count,omitempty"` + Sum *DoubleValue `json:"sum,omitempty"` + Snapshot *Snapshot `json:"snapshot,omitempty"` +} + +type Snapshot struct { + Count *Int64Value `json:"count,omitempty"` + Sum *DoubleValue `json:"sum,omitempty"` + PercentileValues []*SnapshotValueAtPercentile `json:"percentile_values,omitempty"` +} + +type SnapshotValueAtPercentile struct { + Percentile float64 `json:"percentile,omitempty"` + Value float64 `json:"value,omitempty"` +} diff --git a/internal/lsp/telemetry/ocagent/wire/trace.go b/internal/lsp/telemetry/ocagent/wire/trace.go new file mode 100644 index 0000000000..fb737430a1 --- /dev/null +++ b/internal/lsp/telemetry/ocagent/wire/trace.go @@ -0,0 +1,112 @@ +// 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 wire + +type ExportTraceServiceRequest struct { + Node *Node `json:"node,omitempty"` + Spans []*Span `json:"spans,omitempty"` + Resource *Resource `json:"resource,omitempty"` +} + +type Span struct { + TraceId []byte `json:"trace_id,omitempty"` + SpanId []byte `json:"span_id,omitempty"` + TraceState *TraceState `json:"tracestate,omitempty"` + ParentSpanId []byte `json:"parent_span_id,omitempty"` + Name *TruncatableString `json:"name,omitempty"` + Kind SpanKind `json:"kind,omitempty"` + StartTime Timestamp `json:"start_time,omitempty"` + EndTime Timestamp `json:"end_time,omitempty"` + Attributes *Attributes `json:"attributes,omitempty"` + StackTrace *StackTrace `json:"stack_trace,omitempty"` + TimeEvents *TimeEvents `json:"time_events,omitempty"` + Links *Links `json:"links,omitempty"` + Status *Status `json:"status,omitempty"` + Resource *Resource `json:"resource,omitempty"` + SameProcessAsParentSpan bool `json:"same_process_as_parent_span,omitempty"` + ChildSpanCount bool `json:"child_span_count,omitempty"` +} + +type TraceState struct { + Entries []*TraceStateEntry `json:"entries,omitempty"` +} + +type TraceStateEntry struct { + Key string `json:"key,omitempty"` + Value string `json:"value,omitempty"` +} + +type SpanKind int32 + +const ( + UnspecifiedSpanKind SpanKind = 0 + ServerSpanKind SpanKind = 1 + ClientSpanKind SpanKind = 2 +) + +type TimeEvents struct { + TimeEvent []TimeEvent `json:"timeEvent,omitempty"` + DroppedAnnotationsCount int32 `json:"dropped_annotations_count,omitempty"` + DroppedMessageEventsCount int32 `json:"dropped_message_events_count,omitempty"` +} + +type TimeEvent struct { + Time Timestamp `json:"time,omitempty"` + MessageEvent *MessageEvent `json:"messageEvent,omitempty"` + Annotation *Annotation `json:"annotation,omitempty"` +} + +type Annotation struct { + Description *TruncatableString `json:"description,omitempty"` + Attributes *Attributes `json:"attributes,omitempty"` +} + +type MessageEvent struct { + Type MessageEventType `json:"type,omitempty"` + Id uint64 `json:"id,omitempty"` + UncompressedSize uint64 `json:"uncompressed_size,omitempty"` + CompressedSize uint64 `json:"compressed_size,omitempty"` +} + +type MessageEventType int32 + +const ( + UnspecifiedMessageEvent MessageEventType = iota + SentMessageEvent + ReceivedMessageEvent +) + +type TimeEventValue interface { + tagTimeEventValue() +} + +func (Annotation) tagTimeEventValue() {} +func (MessageEvent) tagTimeEventValue() {} + +type Links struct { + Link []*Link `json:"link,omitempty"` + DroppedLinksCount int32 `json:"dropped_links_count,omitempty"` +} + +type Link struct { + TraceId []byte `json:"trace_id,omitempty"` + SpanId []byte `json:"span_id,omitempty"` + Type LinkType `json:"type,omitempty"` + Attributes *Attributes `json:"attributes,omitempty"` + TraceState *TraceState `json:"tracestate,omitempty"` +} + +type LinkType int32 + +const ( + UnspecifiedLinkType LinkType = 0 + ChildLinkType LinkType = 1 + ParentLinkType LinkType = 2 +) + +type Status struct { + Code int32 `json:"code,omitempty"` + Message string `json:"message,omitempty"` +}