github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/ruler/storage/util/compare_yaml.go (about) 1 // This directory was copied and adapted from https://github.com/grafana/agent/tree/main/pkg/metrics. 2 // We cannot vendor the agent in since the agent vendors loki in, which would cause a cyclic dependency. 3 // NOTE: many changes have been made to the original code for our use-case. 4 package util 5 6 import ( 7 "bytes" 8 9 "gopkg.in/yaml.v2" 10 ) 11 12 // CompareYAML marshals a and b to YAML and ensures that their contents are 13 // equal. If either Marshal fails, CompareYAML returns false. 14 func CompareYAML(a, b interface{}) bool { 15 aBytes, err := yaml.Marshal(a) 16 if err != nil { 17 return false 18 } 19 bBytes, err := yaml.Marshal(b) 20 if err != nil { 21 return false 22 } 23 return bytes.Equal(aBytes, bBytes) 24 }