Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7dc68e8
Rough draft pre-comments
Jul 1, 2020
8838618
Comments and restoring order
Jul 1, 2020
907f253
Remove gen.go
Jul 1, 2020
01cdd17
metric_descriptor->descriptor
Jul 2, 2020
538e599
whitespace
Jul 2, 2020
5700d38
Define structure
Jul 2, 2020
58ecfab
Comments after @bogdandrutu and @MrAlias feedback
Jul 8, 2020
67f20c4
Revert data point changes, keep Kind & ValueType changes
Jul 14, 2020
e577247
Comment gen.go
Jul 14, 2020
50e0331
Checkpoint
Jul 14, 2020
0c3a7f6
Document each kind
Jul 15, 2020
c5f291a
Fix numbering
Jul 15, 2020
39e7967
One more #159 TODO
Jul 15, 2020
5e7fa7f
One more #159 TODO
Jul 15, 2020
88acc0c
Formatting
Jul 15, 2020
92ddee2
Undo generated files
Jul 15, 2020
82322a2
Upstream
Jul 15, 2020
e89503f
Remove go.mod
Jul 15, 2020
d870316
Comments
Jul 15, 2020
4a823d7
More comments on Kind
Jul 15, 2020
306d559
Format me
Jul 15, 2020
18271f2
Comments
Jul 16, 2020
d0186b0
Spelling
Jul 16, 2020
d081712
Grouping comment
Jul 16, 2020
20654a8
Asynchronous->Chronological
Jul 18, 2020
35bc2ba
Add missing comments
Jul 18, 2020
9d6210f
More comment on CHRONOLOGICAL
Jul 18, 2020
2855cec
More on CHRONOLOGICAL
Jul 18, 2020
9970a8b
Clarify ADDING|INSTANTANEOUS vs ADDING|DELTA
Jul 18, 2020
a551fb8
Clarify ADDING|INSTANTANEOUS vs ADDING|DELTA
Jul 18, 2020
ca17a32
Restore int64/double data points
Jul 20, 2020
bad082b
Restore int64/double data points
Jul 20, 2020
eeb489c
Make Monotonic a Structure
Jul 20, 2020
d0283cf
Generate code
Jul 20, 2020
ced5068
Upstream
Jul 20, 2020
fbcf615
Top of KindElement
Jul 23, 2020
376d80e
Rewrite KindElementdocs
Jul 23, 2020
bb9689f
Improve comments
Jul 23, 2020
15c7f92
Comment all Kind values
Jul 23, 2020
ab75b67
Merge 178
Jul 23, 2020
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
106 changes: 106 additions & 0 deletions opentelemetry/proto/metrics/v1/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2020, 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.

// Notes: This code generates the Kind enum hex in metrics.proto. To
// run this code, execute:
//
// go run gen.go > out.go && go run out.go
//
// The output of this program MUST be tested in an external module,
// using the output of protoc.

package main

import (
"bytes"
"fmt"
"go/format"
"os"
"strconv"
"strings"
)

var (
cumulativeProps = []string{"Instantaneous", "Delta", "Cumulative"}
structureProps = []string{"Adding_Monotonic", "Adding", "Grouping"}
syncProps = []string{"Continuous", "Snapshot"}
)

func main() {
var buf bytes.Buffer
buf.WriteString(`package main

import "fmt"


type (
Kind int
)

const (
INVALID = 0

// One of the following three MUST be set. There are 3 exclusive Temporality kinds.
INSTANTANEOUS = 1 << 0
DELTA = 2 << 0
CUMULATIVE = 3 << 0

// One of the following three MUST be set. There are 3 exclusive Structure kinds.
GROUPING = 1 << 2
ADDING = 2 << 2
ADDING_MONOTONIC = 3 << 2

// May be set for any instrument.
SNAPSHOT = 1 << 4
)

var (
`)
var fullnames []string
var fullvalues []string

for _, c := range cumulativeProps {
for _, a := range structureProps {
for _, s := range syncProps {
sfrag := ""
if s == "Snapshot" {
sfrag = fmt.Sprint("|", strings.ToUpper(s))
}
fullname := fmt.Sprint(strings.ToUpper(c), "_", strings.ToUpper(a), "_", strings.ToUpper(s))
fullnames = append(fullnames, fullname)
fullvalue := fmt.Sprint(strings.ToUpper(c), "|", strings.ToUpper(a), sfrag)
fullvalues = append(fullvalues, fullvalue)
buf.WriteString(fmt.Sprint(fullname, " Kind = ", fullvalue, "\n"))
}
}
}
buf.WriteString(`)

func main() {
Comment thread
jmacd marked this conversation as resolved.
`)

for i, fn := range fullnames {
buf.WriteString(fmt.Sprint(`fmt.Printf(" %s = %s; // %s\n", `, strconv.Quote(fn), ",", `fmt.Sprintf("%#x",`, fn, `)`, ",", strconv.Quote(fullvalues[i]), ")\n"))
}
buf.WriteRune('}')

src, err := format.Source(buf.Bytes())
if err != nil {
fmt.Println("SOURCE WAS\n", string(buf.Bytes()))
panic(err)
}
if nwritten, err := os.Stdout.Write(src); err != nil || nwritten != len(src) {
panic(err)
}
}
Loading