Skip to content

Does MessageLite::SerializeAsString generate unique string for same proto ? #5668

@quanjielin

Description

@quanjielin
  1. In blow code, we used SerializeAsString with the hope that it generates unique string for same proto (so that it could be used as mapkey)
const std::string map_key = sds_config_source.SerializeAsString() + config_name;
  1. However from logs from commit; the result from SerializeAsString for same proto are different
[2019-02-01 23:03:12.792][14][debug][upstream] [external/envoy/source/common/upstream/cds_api_impl.cc:57] cds: add/update cluster 'outbound|443||kubernetes.default.svc.cluster.local'
[2019-02-01 23:03:12.796][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:57] ***config name default
[2019-02-01 23:03:12.796][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:58] ***sds_config_source api_config_source {
  api_type: GRPC
  grpc_services {
    google_grpc {
      target_uri: "unix:/var/run/sds/uds_path"
      channel_credentials {
        local_credentials {
        }
      }
      call_credentials {
        from_plugin {
          name: "envoy.grpc_credentials.file_based_metadata"
          config {
            fields {
              key: "header_key"
              value {
                string_value: "istio_sds_credentail_header-bin"
              }
            }
            fields {
              key: "secret_data"
              value {
                struct_value {
                  fields {
                    key: "filename"
                    value {
                      string_value: "/var/run/secrets/kubernetes.io/serviceaccount/token"
                    }
                  }
                }
              }
            }
          }
        }
      }
      stat_prefix: "sdsstat"
      credentials_factory_name: "envoy.grpc_credentials.file_based_metadata"
    }
  }
}

[2019-02-01 23:03:12.796][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:60] ***sds_config_source binary 
EpkCCAIilAISkQIKGnVuaXg6L3Zhci9ydW4vc2RzL3Vkc19wYXRoEgIaABq5ATK2AQoqZW52b3kuZ3JwY19jcmVkZW50aWFscy5maWxlX2Jhc2VkX21ldGFkYXRhEocBCi8KCmhlYWRlcl9rZXkSIRofaXN0aW9fc2RzX2NyZWRlbnRhaWxfaGVhZGVyLWJpbgpUCgtzZWNyZXRfZGF0YRJFKkMKQQoIZmlsZW5hbWUSNRozL3Zhci9ydW4vc2VjcmV0cy9rdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3Rva2VuIgdzZHNzdGF0KiplbnZveS5ncnBjX2NyZWRlbnRpYWxzLmZpbGVfYmFzZWRfbWV0YWRhdGE=

[2019-02-01 23:03:12.796][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:61] ***mapkey hash_key 462951205992374496

[2019-02-01 23:03:12.796][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:73] ***add secret provider for default

...
[2019-02-01 23:03:12.829][14][debug][upstream] [external/envoy/source/common/upstream/cds_api_impl.cc:57] cds: add/update cluster 'outbound|9901||istio-galley.istio-system.svc.cluster.local'
[2019-02-01 23:03:12.831][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:57] ***config name default
[2019-02-01 23:03:12.831][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:58] ***sds_config_source api_config_source {
  api_type: GRPC
  grpc_services {
    google_grpc {
      target_uri: "unix:/var/run/sds/uds_path"
      channel_credentials {
        local_credentials {
        }
      }
      call_credentials {
        from_plugin {
          name: "envoy.grpc_credentials.file_based_metadata"
          config {
            fields {
              key: "header_key"
              value {
                string_value: "istio_sds_credentail_header-bin"
              }
            }
            fields {
              key: "secret_data"
              value {
                struct_value {
                  fields {
                    key: "filename"
                    value {
                      string_value: "/var/run/secrets/kubernetes.io/serviceaccount/token"
                    }
                  }
                }
              }
            }
          }
        }
      }
      stat_prefix: "sdsstat"
      credentials_factory_name: "envoy.grpc_credentials.file_based_metadata"
    }
  }
}

[2019-02-01 23:03:12.832][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:60] ***sds_config_source binary 
EpkCCAIilAISkQIKGnVuaXg6L3Zhci9ydW4vc2RzL3Vkc19wYXRoEgIaABq5ATK2AQoqZW52b3kuZ3JwY19jcmVkZW50aWFscy5maWxlX2Jhc2VkX21ldGFkYXRhEocBClQKC3NlY3JldF9kYXRhEkUqQwpBCghmaWxlbmFtZRI1GjMvdmFyL3J1bi9zZWNyZXRzL2t1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvdG9rZW4KLwoKaGVhZGVyX2tleRIhGh9pc3Rpb19zZHNfY3JlZGVudGFpbF9oZWFkZXItYmluIgdzZHNzdGF0KiplbnZveS5ncnBjX2NyZWRlbnRpYWxzLmZpbGVfYmFzZWRfbWV0YWRhdGE=

[2019-02-01 23:03:12.832][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:61] ***mapkey hash_key 12493521696261848690

[2019-02-01 23:03:12.832][14][info][secret] [bazel-out/k8-fastbuild/bin/external/envoy/source/common/secret/_virtual_includes/secret_manager_impl_lib/common/secret/secret_manager_impl.h:73] ***add secret provider for default
  1. If SerializeAsString doesn't grantee uniqueness, is there any other function to generate unique key for same proto ?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions