Merge pull request #955 from crazy-max/vendor-buildkit
vendor: update buildkit to 1e6032cpull/958/head
						commit
						893d505803
					
				@ -1,10 +0,0 @@
 | 
				
			|||||||
// 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.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// +build !go1.10
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package flags
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// AtLeastGo110 reports whether the Go toolchain is at least Go 1.10.
 | 
					 | 
				
			||||||
const AtLeastGo110 = false
 | 
					 | 
				
			||||||
@ -1,10 +0,0 @@
 | 
				
			|||||||
// 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.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// +build go1.10
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package flags
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// AtLeastGo110 reports whether the Go toolchain is at least Go 1.10.
 | 
					 | 
				
			||||||
const AtLeastGo110 = true
 | 
					 | 
				
			||||||
								
									
										
											
										
									
									
										
											39
										
									
									vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/transport.go
									
										generated
									
									
										vendored
									
								
								
							
							
										
											39
										
									
									vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/transport.go
									
										generated
									
									
										vendored
									
								
								
									
										
											
										
									
									
										
											2
										
									
									vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/version.go
									
										generated
									
									
										vendored
									
								
								
							
							
										
											2
										
									
									vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/version.go
									
										generated
									
									
										vendored
									
								
								
									
										
											
										
									
									
										
											87
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig/options.go
									
										generated
									
									
										vendored
									
								
								
							
							
										
											87
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig/options.go
									
										generated
									
									
										vendored
									
								
								
									
										
											
										
									
									
										
											21
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/options.go
									
										generated
									
									
										vendored
									
								
								
							
							
										
											21
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/options.go
									
										generated
									
									
										vendored
									
								
								
									
										
											
										
									
									
										
											4
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client.go
									
										generated
									
									
										vendored
									
								
								
							
							
										
											4
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client.go
									
										generated
									
									
										vendored
									
								
								
									
										
											
										
									
									
										
											6
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/options.go
									
										generated
									
									
										vendored
									
								
								
							
							
										
											6
										
									
									vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/options.go
									
										generated
									
									
										vendored
									
								@ -1,95 +0,0 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# 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.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set -e
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
help()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
   printf "\n"
 | 
					 | 
				
			||||||
   printf "Usage: $0 -t tag\n"
 | 
					 | 
				
			||||||
   printf "\t-t Unreleased tag. Update all go.mod with this tag.\n"
 | 
					 | 
				
			||||||
   exit 1 # Exit script after printing help
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
while getopts "t:" opt
 | 
					 | 
				
			||||||
do
 | 
					 | 
				
			||||||
   case "$opt" in
 | 
					 | 
				
			||||||
      t ) TAG="$OPTARG" ;;
 | 
					 | 
				
			||||||
      ? ) help ;; # Print help
 | 
					 | 
				
			||||||
   esac
 | 
					 | 
				
			||||||
done
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Print help in case parameters are empty
 | 
					 | 
				
			||||||
if [ -z "$TAG" ]
 | 
					 | 
				
			||||||
then
 | 
					 | 
				
			||||||
   printf "Tag is missing\n";
 | 
					 | 
				
			||||||
   help
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Validate semver
 | 
					 | 
				
			||||||
SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
 | 
					 | 
				
			||||||
if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then
 | 
					 | 
				
			||||||
	printf "${TAG} is valid semver tag.\n"
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
	printf "${TAG} is not a valid semver tag.\n"
 | 
					 | 
				
			||||||
	exit -1
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TAG_FOUND=`git tag --list ${TAG}`
 | 
					 | 
				
			||||||
if [[ ${TAG_FOUND} = ${TAG} ]] ; then
 | 
					 | 
				
			||||||
        printf "Tag ${TAG} already exists\n"
 | 
					 | 
				
			||||||
        exit -1
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Get version for version.go
 | 
					 | 
				
			||||||
OTEL_VERSION=$(echo "${TAG}" | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+')
 | 
					 | 
				
			||||||
# Strip leading v
 | 
					 | 
				
			||||||
OTEL_VERSION="${OTEL_VERSION#v}"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
cd $(dirname $0)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if ! git diff --quiet; then \
 | 
					 | 
				
			||||||
	printf "Working tree is not clean, can't proceed with the release process\n"
 | 
					 | 
				
			||||||
	git status
 | 
					 | 
				
			||||||
	git diff
 | 
					 | 
				
			||||||
	exit 1
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Update version.go
 | 
					 | 
				
			||||||
cp ./version.go ./version.go.bak
 | 
					 | 
				
			||||||
sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_VERSION}\"/" ./version.go.bak >./version.go
 | 
					 | 
				
			||||||
rm -f ./version.go.bak
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Update go.mod
 | 
					 | 
				
			||||||
git checkout -b pre_release_${TAG} main
 | 
					 | 
				
			||||||
PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for dir in $PACKAGE_DIRS; do
 | 
					 | 
				
			||||||
	cp "${dir}/go.mod" "${dir}/go.mod.bak"
 | 
					 | 
				
			||||||
	sed "s/opentelemetry.io\/otel\([^ ]*\) v[0-9]*\.[0-9]*\.[0-9]/opentelemetry.io\/otel\1 ${TAG}/" "${dir}/go.mod.bak" >"${dir}/go.mod"
 | 
					 | 
				
			||||||
	rm -f "${dir}/go.mod.bak"
 | 
					 | 
				
			||||||
done
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Run lint to update go.sum
 | 
					 | 
				
			||||||
make lint
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Add changes and commit.
 | 
					 | 
				
			||||||
git add .
 | 
					 | 
				
			||||||
make ci
 | 
					 | 
				
			||||||
git commit -m "Prepare for releasing $TAG"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
printf "Now run following to verify the changes.\ngit diff main\n"
 | 
					 | 
				
			||||||
printf "\nThen push the changes to upstream\n"
 | 
					 | 
				
			||||||
@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					// 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 env // import "go.opentelemetry.io/otel/sdk/internal/env"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/internal/global"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Environment variable names
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						// BatchSpanProcessorScheduleDelayKey
 | 
				
			||||||
 | 
						// Delay interval between two consecutive exports.
 | 
				
			||||||
 | 
						// i.e. 5000
 | 
				
			||||||
 | 
						BatchSpanProcessorScheduleDelayKey = "OTEL_BSP_SCHEDULE_DELAY"
 | 
				
			||||||
 | 
						// BatchSpanProcessorExportTimeoutKey
 | 
				
			||||||
 | 
						// Maximum allowed time to export data.
 | 
				
			||||||
 | 
						// i.e. 3000
 | 
				
			||||||
 | 
						BatchSpanProcessorExportTimeoutKey = "OTEL_BSP_EXPORT_TIMEOUT"
 | 
				
			||||||
 | 
						// BatchSpanProcessorMaxQueueSizeKey
 | 
				
			||||||
 | 
						// Maximum queue size
 | 
				
			||||||
 | 
						// i.e. 2048
 | 
				
			||||||
 | 
						BatchSpanProcessorMaxQueueSizeKey = "OTEL_BSP_MAX_QUEUE_SIZE"
 | 
				
			||||||
 | 
						// BatchSpanProcessorMaxExportBatchSizeKey
 | 
				
			||||||
 | 
						// Maximum batch size
 | 
				
			||||||
 | 
						// Note: Must be less than or equal to EnvBatchSpanProcessorMaxQueueSize
 | 
				
			||||||
 | 
						// i.e. 512
 | 
				
			||||||
 | 
						BatchSpanProcessorMaxExportBatchSizeKey = "OTEL_BSP_MAX_EXPORT_BATCH_SIZE"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// IntEnvOr returns the int value of the environment variable with name key if
 | 
				
			||||||
 | 
					// it exists and the value is an int. Otherwise, defaultValue is returned.
 | 
				
			||||||
 | 
					func IntEnvOr(key string, defaultValue int) int {
 | 
				
			||||||
 | 
						value, ok := os.LookupEnv(key)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return defaultValue
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						intValue, err := strconv.Atoi(value)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							global.Info("Got invalid value, number value expected.", key, value)
 | 
				
			||||||
 | 
							return defaultValue
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return intValue
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BatchSpanProcessorScheduleDelay returns the environment variable value for
 | 
				
			||||||
 | 
					// the OTEL_BSP_SCHEDULE_DELAY key if it exists, otherwise defaultValue is
 | 
				
			||||||
 | 
					// returned.
 | 
				
			||||||
 | 
					func BatchSpanProcessorScheduleDelay(defaultValue int) int {
 | 
				
			||||||
 | 
						return IntEnvOr(BatchSpanProcessorScheduleDelayKey, defaultValue)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BatchSpanProcessorExportTimeout returns the environment variable value for
 | 
				
			||||||
 | 
					// the OTEL_BSP_EXPORT_TIMEOUT key if it exists, otherwise defaultValue is
 | 
				
			||||||
 | 
					// returned.
 | 
				
			||||||
 | 
					func BatchSpanProcessorExportTimeout(defaultValue int) int {
 | 
				
			||||||
 | 
						return IntEnvOr(BatchSpanProcessorExportTimeoutKey, defaultValue)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BatchSpanProcessorMaxQueueSize returns the environment variable value for
 | 
				
			||||||
 | 
					// the OTEL_BSP_MAX_QUEUE_SIZE key if it exists, otherwise defaultValue is
 | 
				
			||||||
 | 
					// returned.
 | 
				
			||||||
 | 
					func BatchSpanProcessorMaxQueueSize(defaultValue int) int {
 | 
				
			||||||
 | 
						return IntEnvOr(BatchSpanProcessorMaxQueueSizeKey, defaultValue)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BatchSpanProcessorMaxExportBatchSize returns the environment variable value for
 | 
				
			||||||
 | 
					// the OTEL_BSP_MAX_EXPORT_BATCH_SIZE key if it exists, otherwise defaultValue
 | 
				
			||||||
 | 
					// is returned.
 | 
				
			||||||
 | 
					func BatchSpanProcessorMaxExportBatchSize(defaultValue int) int {
 | 
				
			||||||
 | 
						return IntEnvOr(BatchSpanProcessorMaxExportBatchSizeKey, defaultValue)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,50 +0,0 @@
 | 
				
			|||||||
// 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 internal // import "go.opentelemetry.io/otel/sdk/internal"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"unicode"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const labelKeySizeLimit = 100
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Sanitize returns a string that is trunacated to 100 characters if it's too
 | 
					 | 
				
			||||||
// long, and replaces non-alphanumeric characters to underscores.
 | 
					 | 
				
			||||||
func Sanitize(s string) string {
 | 
					 | 
				
			||||||
	if len(s) == 0 {
 | 
					 | 
				
			||||||
		return s
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(s) > labelKeySizeLimit {
 | 
					 | 
				
			||||||
		s = s[:labelKeySizeLimit]
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	s = strings.Map(sanitizeRune, s)
 | 
					 | 
				
			||||||
	if unicode.IsDigit(rune(s[0])) {
 | 
					 | 
				
			||||||
		s = "key_" + s
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if s[0] == '_' {
 | 
					 | 
				
			||||||
		s = "key" + s
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return s
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// converts anything that is not a letter or digit to an underscore
 | 
					 | 
				
			||||||
func sanitizeRune(r rune) rune {
 | 
					 | 
				
			||||||
	if unicode.IsLetter(r) || unicode.IsDigit(r) {
 | 
					 | 
				
			||||||
		return r
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// Everything else turns into an underscore
 | 
					 | 
				
			||||||
	return '_'
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,91 +0,0 @@
 | 
				
			|||||||
// 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 trace // import "go.opentelemetry.io/otel/sdk/trace"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"container/list"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"go.opentelemetry.io/otel/attribute"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// attributesMap is a capped map of attributes, holding the most recent attributes.
 | 
					 | 
				
			||||||
// Eviction is done via a LRU method, the oldest entry is removed to create room for a new entry.
 | 
					 | 
				
			||||||
// Updates are allowed and they refresh the usage of the key.
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// This is based from https://github.com/hashicorp/golang-lru/blob/master/simplelru/lru.go
 | 
					 | 
				
			||||||
// With a subset of the its operations and specific for holding attribute.KeyValue
 | 
					 | 
				
			||||||
type attributesMap struct {
 | 
					 | 
				
			||||||
	attributes   map[attribute.Key]*list.Element
 | 
					 | 
				
			||||||
	evictList    *list.List
 | 
					 | 
				
			||||||
	droppedCount int
 | 
					 | 
				
			||||||
	capacity     int
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func newAttributesMap(capacity int) *attributesMap {
 | 
					 | 
				
			||||||
	lm := &attributesMap{
 | 
					 | 
				
			||||||
		attributes: make(map[attribute.Key]*list.Element),
 | 
					 | 
				
			||||||
		evictList:  list.New(),
 | 
					 | 
				
			||||||
		capacity:   capacity,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return lm
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (am *attributesMap) add(kv attribute.KeyValue) {
 | 
					 | 
				
			||||||
	// Check for existing item
 | 
					 | 
				
			||||||
	if ent, ok := am.attributes[kv.Key]; ok {
 | 
					 | 
				
			||||||
		am.evictList.MoveToFront(ent)
 | 
					 | 
				
			||||||
		ent.Value = &kv
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Add new item
 | 
					 | 
				
			||||||
	entry := am.evictList.PushFront(&kv)
 | 
					 | 
				
			||||||
	am.attributes[kv.Key] = entry
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Verify size not exceeded
 | 
					 | 
				
			||||||
	if am.evictList.Len() > am.capacity {
 | 
					 | 
				
			||||||
		am.removeOldest()
 | 
					 | 
				
			||||||
		am.droppedCount++
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// toKeyValue copies the attributesMap into a slice of attribute.KeyValue and
 | 
					 | 
				
			||||||
// returns it. If the map is empty, a nil is returned.
 | 
					 | 
				
			||||||
// TODO: Is it more efficient to return a pointer to the slice?
 | 
					 | 
				
			||||||
func (am *attributesMap) toKeyValue() []attribute.KeyValue {
 | 
					 | 
				
			||||||
	len := am.evictList.Len()
 | 
					 | 
				
			||||||
	if len == 0 {
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	attributes := make([]attribute.KeyValue, 0, len)
 | 
					 | 
				
			||||||
	for ent := am.evictList.Back(); ent != nil; ent = ent.Prev() {
 | 
					 | 
				
			||||||
		if value, ok := ent.Value.(*attribute.KeyValue); ok {
 | 
					 | 
				
			||||||
			attributes = append(attributes, *value)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return attributes
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// removeOldest removes the oldest item from the cache.
 | 
					 | 
				
			||||||
func (am *attributesMap) removeOldest() {
 | 
					 | 
				
			||||||
	ent := am.evictList.Back()
 | 
					 | 
				
			||||||
	if ent != nil {
 | 
					 | 
				
			||||||
		am.evictList.Remove(ent)
 | 
					 | 
				
			||||||
		kv := ent.Value.(*attribute.KeyValue)
 | 
					 | 
				
			||||||
		delete(am.attributes, kv.Key)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,178 +0,0 @@
 | 
				
			|||||||
#!/usr/bin/env bash
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# 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.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
readonly PROGNAME=$(basename "$0")
 | 
					 | 
				
			||||||
readonly PROGDIR=$(readlink -m "$(dirname "$0")")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
readonly EXCLUDE_PACKAGES="internal/tools"
 | 
					 | 
				
			||||||
readonly SEMVER_REGEX="v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
usage() {
 | 
					 | 
				
			||||||
    cat <<- EOF
 | 
					 | 
				
			||||||
Usage: $PROGNAME [OPTIONS] SEMVER_TAG COMMIT_HASH
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Creates git tag for all Go packages in project.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
OPTIONS:
 | 
					 | 
				
			||||||
  -h --help        Show this help.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ARGUMENTS:
 | 
					 | 
				
			||||||
  SEMVER_TAG       Semantic version to tag with.
 | 
					 | 
				
			||||||
  COMMIT_HASH      Git commit hash to tag.
 | 
					 | 
				
			||||||
EOF
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
cmdline() {
 | 
					 | 
				
			||||||
    local arg commit
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for arg
 | 
					 | 
				
			||||||
    do
 | 
					 | 
				
			||||||
        local delim=""
 | 
					 | 
				
			||||||
        case "$arg" in
 | 
					 | 
				
			||||||
            # Translate long form options to short form.
 | 
					 | 
				
			||||||
            --help)           args="${args}-h ";;
 | 
					 | 
				
			||||||
            # Pass through for everything else.
 | 
					 | 
				
			||||||
            *) [[ "${arg:0:1}" == "-" ]] || delim="\""
 | 
					 | 
				
			||||||
                args="${args}${delim}${arg}${delim} ";;
 | 
					 | 
				
			||||||
        esac
 | 
					 | 
				
			||||||
    done
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Reset and process short form options.
 | 
					 | 
				
			||||||
    eval set -- "$args"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while getopts "h" OPTION
 | 
					 | 
				
			||||||
    do
 | 
					 | 
				
			||||||
         case $OPTION in
 | 
					 | 
				
			||||||
         h)
 | 
					 | 
				
			||||||
             usage
 | 
					 | 
				
			||||||
             exit 0
 | 
					 | 
				
			||||||
             ;;
 | 
					 | 
				
			||||||
         *)
 | 
					 | 
				
			||||||
             echo "unknown option: $OPTION"
 | 
					 | 
				
			||||||
             usage
 | 
					 | 
				
			||||||
             exit 1
 | 
					 | 
				
			||||||
             ;;
 | 
					 | 
				
			||||||
        esac
 | 
					 | 
				
			||||||
    done
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Positional arguments.
 | 
					 | 
				
			||||||
    shift $((OPTIND-1))
 | 
					 | 
				
			||||||
    readonly TAG="$1"
 | 
					 | 
				
			||||||
    if [ -z "$TAG" ]
 | 
					 | 
				
			||||||
    then
 | 
					 | 
				
			||||||
        echo "missing SEMVER_TAG"
 | 
					 | 
				
			||||||
        usage
 | 
					 | 
				
			||||||
        exit 1
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
    if [[ ! "$TAG" =~ $SEMVER_REGEX ]]
 | 
					 | 
				
			||||||
    then
 | 
					 | 
				
			||||||
        printf "invalid semantic version: %s\n" "$TAG"
 | 
					 | 
				
			||||||
        exit 2
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
    if [[ "$( git tag --list "$TAG" )" ]]
 | 
					 | 
				
			||||||
    then
 | 
					 | 
				
			||||||
        printf "tag already exists: %s\n" "$TAG"
 | 
					 | 
				
			||||||
        exit 2
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    shift
 | 
					 | 
				
			||||||
    commit="$1"
 | 
					 | 
				
			||||||
    if [ -z "$commit" ]
 | 
					 | 
				
			||||||
    then
 | 
					 | 
				
			||||||
        echo "missing COMMIT_HASH"
 | 
					 | 
				
			||||||
        usage
 | 
					 | 
				
			||||||
        exit 1
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
    # Verify rev is for a commit and unify hashes into a complete SHA1.
 | 
					 | 
				
			||||||
    readonly SHA="$( git rev-parse --quiet --verify "${commit}^{commit}" )"
 | 
					 | 
				
			||||||
    if [ -z "$SHA" ]
 | 
					 | 
				
			||||||
    then
 | 
					 | 
				
			||||||
        printf "invalid commit hash: %s\n" "$commit"
 | 
					 | 
				
			||||||
        exit 2
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
    if [ "$( git merge-base "$SHA" HEAD )" != "$SHA" ]
 | 
					 | 
				
			||||||
    then
 | 
					 | 
				
			||||||
        printf "commit '%s' not found on this branch\n" "$commit"
 | 
					 | 
				
			||||||
        exit 2
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package_dirs() {
 | 
					 | 
				
			||||||
    # Return a list of package directories in the form:
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    #  package/directory/a
 | 
					 | 
				
			||||||
    #  package/directory/b
 | 
					 | 
				
			||||||
    #  deeper/package/directory/a
 | 
					 | 
				
			||||||
    #  ...
 | 
					 | 
				
			||||||
    #
 | 
					 | 
				
			||||||
    # Making sure to exclude any packages in the EXCLUDE_PACKAGES regexp.
 | 
					 | 
				
			||||||
    find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \
 | 
					 | 
				
			||||||
        | grep -E -v "$EXCLUDE_PACKAGES" \
 | 
					 | 
				
			||||||
        | sed 's/^\.\///' \
 | 
					 | 
				
			||||||
        | sort
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
git_tag() {
 | 
					 | 
				
			||||||
    local tag="$1"
 | 
					 | 
				
			||||||
    local commit="$2"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    git tag -a "$tag" -s -m "Version $tag" "$commit"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
previous_version() {
 | 
					 | 
				
			||||||
    local current="$1"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Requires git > 2.0
 | 
					 | 
				
			||||||
    git tag -l --sort=v:refname \
 | 
					 | 
				
			||||||
        | grep -E "^${SEMVER_REGEX}$" \
 | 
					 | 
				
			||||||
        | grep -v "$current" \
 | 
					 | 
				
			||||||
        | tail -1
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print_changes() {
 | 
					 | 
				
			||||||
    local tag="$1"
 | 
					 | 
				
			||||||
    local previous
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    previous="$( previous_version "$tag" )"
 | 
					 | 
				
			||||||
    if [ -n "$previous" ]
 | 
					 | 
				
			||||||
    then
 | 
					 | 
				
			||||||
        printf "\nRaw changes made between %s and %s\n" "$previous" "$tag"
 | 
					 | 
				
			||||||
        printf "======================================\n"
 | 
					 | 
				
			||||||
        git --no-pager log --pretty=oneline "${previous}..$tag"
 | 
					 | 
				
			||||||
    fi
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
main() {
 | 
					 | 
				
			||||||
    local dir
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    cmdline "$@"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    cd "$PROGDIR" || exit 3
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Create tag for root package.
 | 
					 | 
				
			||||||
    git_tag "$TAG" "$SHA"
 | 
					 | 
				
			||||||
    printf "created tag: %s\n" "$TAG"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Create tag for all sub-packages.
 | 
					 | 
				
			||||||
    for dir in $( package_dirs )
 | 
					 | 
				
			||||||
    do
 | 
					 | 
				
			||||||
        git_tag "${dir}/$TAG" "$SHA"
 | 
					 | 
				
			||||||
        printf "created tag: %s\n" "${dir}/$TAG"
 | 
					 | 
				
			||||||
    done
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    print_changes "$TAG"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
main "$@"
 | 
					 | 
				
			||||||
					Loading…
					
					
				
		Reference in New Issue