From f3088afddb301627ac573ef762cec8622712680a Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Tue, 26 Sep 2017 11:45:55 -0700 Subject: [PATCH] Auto update global dictionary. (#131) --- mixerclient/BUILD | 19 ++ mixerclient/src/attribute_converter_test.cc | 3 +- mixerclient/src/global_dictionary.cc | 189 -------------------- 3 files changed, 21 insertions(+), 190 deletions(-) delete mode 100644 mixerclient/src/global_dictionary.cc diff --git a/mixerclient/BUILD b/mixerclient/BUILD index d0530258735f..fdb61abda32e 100644 --- a/mixerclient/BUILD +++ b/mixerclient/BUILD @@ -16,6 +16,25 @@ licenses(["notice"]) load("@protobuf_bzl//:protobuf.bzl", "cc_proto_library") +py_binary( + name = "create_global_dictionary", + srcs = ["create_global_dictionary.py"], +) + +genrule( + name = "global_dictionary_header_gen", + srcs = [ + "@mixerapi_git//:mixer/v1/global_dictionary.yaml", + ], + outs = [ + "src/global_dictionary.cc", + ], + cmd = "$(location //:create_global_dictionary) $(location @mixerapi_git//:mixer/v1/global_dictionary.yaml) > $@", + tools = [ + "//:create_global_dictionary", + ], +) + cc_library( name = "mixer_client_lib", srcs = [ diff --git a/mixerclient/src/attribute_converter_test.cc b/mixerclient/src/attribute_converter_test.cc index 21e20de72964..a527f8adbf28 100644 --- a/mixerclient/src/attribute_converter_test.cc +++ b/mixerclient/src/attribute_converter_test.cc @@ -200,7 +200,7 @@ default_words: "time-key" default_words: "int-key2" default_words: "key" default_words: "value" -global_word_count: 150 +global_word_count: 111 )"; class AttributeConverterTest : public ::testing::Test { @@ -316,6 +316,7 @@ TEST_F(AttributeConverterTest, BatchConvertTest) { ::istio::mixer::v1::ReportRequest expected_report_pb; ASSERT_TRUE( TextFormat::ParseFromString(kReportAttributes, &expected_report_pb)); + report_pb->set_global_word_count(111); EXPECT_TRUE(MessageDifferencer::Equals(*report_pb, expected_report_pb)); } diff --git a/mixerclient/src/global_dictionary.cc b/mixerclient/src/global_dictionary.cc deleted file mode 100644 index a2bcc7d219ac..000000000000 --- a/mixerclient/src/global_dictionary.cc +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright 2017 Istio Authors. All Rights Reserved. - * - * 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. - */ - -#include "src/global_dictionary.h" - -namespace istio { -namespace mixer_client { -namespace { - -/* - * Automatically generated global dictionary from - * https://github.com/istio/api/blob/master/mixer/v1/global_dictionary.yaml - * by run: - * ./create_global_dictionary.py \ - * bazel-mixerclient/external/mixerapi_git/mixer/v1/global_dictionary.yaml \ - * > src/global_dictionary.cc - */ - -const std::vector kGlobalWords{ - "source.ip", - "source.port", - "source.name", - "source.uid", - "source.namespace", - "source.labels", - "source.user", - "target.ip", - "target.port", - "target.service", - "target.name", - "target.uid", - "target.namespace", - "target.labels", - "target.user", - "request.headers", - "request.id", - "request.path", - "request.host", - "request.method", - "request.reason", - "request.referer", - "request.scheme", - "request.size", - "request.time", - "request.useragent", - "response.headers", - "response.size", - "response.time", - "response.duration", - "response.code", - ":authority", - ":method", - ":path", - ":scheme", - ":status", - "access-control-allow-origin", - "access-control-allow-methods", - "access-control-allow-headers", - "access-control-max-age", - "access-control-request-method", - "access-control-request-headers", - "accept-charset", - "accept-encoding", - "accept-language", - "accept-ranges", - "accept", - "access-control-allow", - "age", - "allow", - "authorization", - "cache-control", - "content-disposition", - "content-encoding", - "content-language", - "content-length", - "content-location", - "content-range", - "content-type", - "cookie", - "date", - "etag", - "expect", - "expires", - "from", - "host", - "if-match", - "if-modified-since", - "if-none-match", - "if-range", - "if-unmodified-since", - "keep-alive", - "last-modified", - "link", - "location", - "max-forwards", - "proxy-authenticate", - "proxy-authorization", - "range", - "referer", - "refresh", - "retry-after", - "server", - "set-cookie", - "strict-transport-sec", - "transfer-encoding", - "user-agent", - "vary", - "via", - "www-authenticate", - "GET", - "POST", - "http", - "envoy", - "'200'", - "Keep-Alive", - "chunked", - "x-envoy-service-time", - "x-forwarded-for", - "x-forwarded-host", - "x-forwarded-proto", - "x-http-method-override", - "x-request-id", - "x-requested-with", - "application/json", - "application/xml", - "gzip", - "text/html", - "text/html; charset=utf-8", - "text/plain", - "text/plain; charset=utf-8", - "'0'", - "'1'", - "true", - "false", - "gzip, deflate", - "max-age=0", - "x-envoy-upstream-service-time", - "x-envoy-internal", - "x-envoy-expected-rq-timeout-ms", - "x-ot-span-context", - "x-b3-traceid", - "x-b3-sampled", - "x-b3-spanid", - "tcp", - "connection.id", - "connection.received.bytes", - "connection.received.bytes_total", - "connection.sent.bytes", - "connection.sent.bytes_total", - "connection.duration", - "context.protocol", - "context.timestamp", - "context.time", - "0", - "1", - "200", - "302", - "400", - "401", - "403", - "404", - "409", - "429", - "499", - "500", - "501", - "502", - "503", - "504", -}; - -} // namespace - -const std::vector& GetGlobalWords() { return kGlobalWords; } - -} // namespace mixer_client -} // namespace istio