add ob configserver (#943)

This commit is contained in:
chris-sun-star
2022-05-30 16:44:36 +08:00
committed by GitHub
parent bd06e657c6
commit e12438aa76
64 changed files with 9587 additions and 0 deletions

View File

@ -0,0 +1,39 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
package trace
import (
"context"
"crypto/rand"
"fmt"
"github.com/oceanbase/configserver/logger"
)
func RandomTraceId() string {
n := 8
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
return ""
}
return fmt.Sprintf("%x", b)
}
func ContextWithRandomTraceId() context.Context {
return context.WithValue(context.Background(), logger.TraceIdKey{}, RandomTraceId())
}
func ContextWithTraceId(traceId string) context.Context {
return context.WithValue(context.Background(), logger.TraceIdKey{}, traceId)
}