Two different contents of same struct give the same hash
jerome-laforge opened this issue · 3 comments
Hello,
I have the same hash with this:
package main
import (
"fmt"
"github.com/mitchellh/hashstructure"
)
type bar struct {
stuf string
}
type foobarbar map[string][4][]string
type (
foo []bar
)
type cacheData struct {
foobar foo
foobar1 foobarbar
}
func main() {
{
hash, err := hashstructure.Hash(cacheData{}, nil)
if err != nil {
panic(err)
}
fmt.Println(hash) // => 9141985097084809465
}
{
hash, err := hashstructure.Hash(cacheData{
foobar1: foobarbar{
"hello": [4][]string{[]string{"world"}, nil, nil, nil},
},
}, nil)
if err != nil {
panic(err)
}
fmt.Println(hash) // => 9141985097084809465 !!!! this the same of hashstructure.Hash(cacheData{}, nil)
}
}
go version
go version go1.7.5 linux/amd64
go env
go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/johndoe/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build521523302=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
Ok, I found the pb.
the visibility of foobar & foobar1.
Sorry for the noise...
Ok, I found the pb. the visibility of foobar & foobar1. Sorry for the noise...
@jerome-laforge - I am seeing a similar problem when I am trying to create a hash for 2 prometheus configs specifially for the regex field. What was the fix for your issue?
cfg1 -
scrape_configs:
- job_name: kube-proxy
scrape_interval: 30s
label_limit: 63
label_name_length_limit: 511
label_value_length_limit: 1023
kubernetes_sd_configs:
- role: pod
relabel_configs:
- action: keep
source_labels:
- __meta_kubernetes_namespace
- __meta_kubernetes_pod_name
separator: "/"
regex: kube-system/kube-proxy.+
- source_labels:
- address
action: replace
target_label: address
regex: "regex1"
replacement: "$$1:10249"
cfg1 -
scrape_configs:
- job_name: kube-proxy
scrape_interval: 30s
label_limit: 63
label_name_length_limit: 511
label_value_length_limit: 1023
kubernetes_sd_configs:
- role: pod
relabel_configs:
- action: keep
source_labels:
- __meta_kubernetes_namespace
- __meta_kubernetes_pod_name
separator: "/"
regex: kube-system/kube-proxy.+
- source_labels:
- address
action: replace
target_label: address
regex: "regex2"
replacement: "$$1:10249"
@mitchellh - May be you could help? I am referencing the regex field from the prometheus config which is indeed exported, but this results in the same hash.
https://github.com/prometheus/prometheus/blob/0e12f11d6112585415140bcdf0fd30c42e4255fe/config/config.go#L525
https://github.com/prometheus/prometheus/blob/0e12f11d6112585415140bcdf0fd30c42e4255fe/model/relabel/relabel.go#L89C2-L89C8