hack/verify fixes

This commit is contained in:
Pat Christopher 2021-07-28 19:26:44 -07:00
parent 4549573a44
commit f720c4fd44
No known key found for this signature in database
GPG Key ID: F8BCFE8CB1484819
4 changed files with 22 additions and 6 deletions

View File

@ -188,7 +188,7 @@ func (c *metricDecoder) decodeOpts(expr ast.Expr) (metric, error) {
return m, newDecodeErrorf(expr, errExprNotIdent, v.X)
}
variableExpr, found := c.variables[strings.Join([]string{s.Name,v.Sel.Name}, ".")]
variableExpr, found := c.variables[strings.Join([]string{s.Name, v.Sel.Name}, ".")]
if !found {
return m, newDecodeErrorf(expr, errBadImportedVariableAttribute)
}

View File

@ -30,7 +30,7 @@ const (
errInvalidNewMetricCall = "Invalid new metric call, please ensure code compiles"
errNonStringAttribute = "Non string attribute is not supported"
errBadVariableAttribute = "Metric attribute was not correctly set. Please use only global consts in same file"
errBadImportedVariableAttribute = "Metric attribute was not correctly set. Please use only global consts in correclty impoprted same file"
errBadImportedVariableAttribute = "Metric attribute was not correctly set. Please use only global consts in correctly impoprted same file"
errFieldNotSupported = "Field %s is not supported"
errBuckets = "Buckets should be set to list of floats, result from function call of prometheus.LinearBuckets or prometheus.ExponentialBuckets"
errLabels = "Labels were not set to list of strings"

View File

@ -191,7 +191,7 @@ func globalVariableDeclarations(tree *ast.File) map[string]ast.Expr {
func localImportPath(importExpr string) (string, error) {
// parse directory path
pathPrefix := "unknown"
var pathPrefix string
if strings.Contains(importExpr, kubeURLRoot) {
// search k/k local checkout
pathPrefix = KUBE_ROOT
@ -212,7 +212,7 @@ func localImportPath(importExpr string) (string, error) {
pathPrefix = strings.Join([]string{GOROOT, "src"}, string(os.PathSeparator))
} // ToDo: support non go mod
crossPlatformImportExpr := strings.Replace(importExpr, "/", string(os.PathSeparator), 0)
crossPlatformImportExpr := strings.Replace(importExpr, "/", string(os.PathSeparator), -1)
importDirectory := strings.Join([]string{pathPrefix, strings.Trim(crossPlatformImportExpr, "\"")}, string(os.PathSeparator))
return importDirectory, nil
@ -221,7 +221,7 @@ func localImportPath(importExpr string) (string, error) {
func importedGlobalVariableDeclaration(localVariables map[string]ast.Expr, imports []*ast.ImportSpec) (map[string]ast.Expr, error) {
for _, im := range imports {
// get imported label
importAlias := "unknown"
var importAlias string
if im.Name == nil {
pathSegments := strings.Split(im.Path.Value, "/")
importAlias = strings.Trim(pathSegments[len(pathSegments)-1], "\"")

View File

@ -1,3 +1,19 @@
/*
Copyright 2021 The Kubernetes 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 metrics
const OKGO = "ThisIsNotTheSoundOfTheTrain"
const OKGO = "ThisIsNotTheSoundOfTheTrain"