Skip to content

Commit

Permalink
Merge pull request envoyproxy#9 from qiwzhang/version
Browse files Browse the repository at this point in the history
Add utils::Version object to remove version file in api_manager
  • Loading branch information
qiwzhang authored Dec 7, 2016
2 parents 51ae063 + 22546df commit 4ac0064
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 99 deletions.
17 changes: 1 addition & 16 deletions contrib/endpoints/include/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#
################################################################################
#
exports_files(["version"])

cc_library(
name = "api_manager",
Expand Down Expand Up @@ -53,20 +52,6 @@ filegroup(
"api_manager/response.h",
"api_manager/service_control.h",
"api_manager/utils/status.h",
"api_manager/version.h",
],
)

genrule(
name = "api_manager_version_header",
srcs = [
":version",
],
outs = [
"api_manager/version.h",
],
cmd = "$(location //contrib/endpoints/tools:create_version) $(location :version) > $@",
tools = [
"//contrib/endpoints/tools:create_version",
"api_manager/utils/version.h",
],
)
50 changes: 50 additions & 0 deletions contrib/endpoints/include/api_manager/utils/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright 2016 Google Inc. 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.
*/

#ifndef API_MANAGER_UTILS_VERSION_H_
#define API_MANAGER_UTILS_VERSION_H_

#include <string>

namespace google {
namespace api_manager {
namespace utils {

// The version is used by Endpoint cloud trace and service control
// when sending service agent.
class Version final {
public:
// Fetch singleton.
static Version& instance();

// Get the version.
const std::string& get() const { return version_; }

// Set the version. Default is empty.
void set(const std::string& v) { version_ = v; }

private:
// The version.
std::string version_;

// public construct not allowed
Version() {}
};

} // namespace utils
} // namespace api_manager
} // namespace google

#endif // API_MANAGER_UTILS_VERSION_H_
1 change: 0 additions & 1 deletion contrib/endpoints/include/version

This file was deleted.

8 changes: 5 additions & 3 deletions contrib/endpoints/src/api_manager/cloud_trace/cloud_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <sstream>
#include <string>
#include "contrib/endpoints/include/api_manager/utils/status.h"
#include "contrib/endpoints/include/api_manager/version.h"
#include "contrib/endpoints/include/api_manager/utils/version.h"
#include "contrib/endpoints/src/api_manager/utils/marshalling.h"
#include "google/protobuf/timestamp.pb.h"

Expand All @@ -43,7 +43,7 @@ const char kCloudTraceService[] = "/google.devtools.cloudtrace.v1.TraceService";
// Cloud Trace agent label key
const char kCloudTraceAgentKey[] = "trace.cloud.google.com/agent";
// Cloud Trace agent label value
const char kServiceAgent[] = "esp/" API_MANAGER_VERSION_STRING;
const char kServiceAgentPrefix[] = "esp/";
// Default trace options
const char kDefaultTraceOptions[] = "o=1";

Expand Down Expand Up @@ -332,7 +332,9 @@ void GetNewTrace(std::string trace_id_str, const std::string &root_span_name,
root_span->set_span_id(RandomUInt64());
root_span->set_name(root_span_name);
// Agent label is defined as "<agent>/<version>".
root_span->mutable_labels()->insert({kCloudTraceAgentKey, kServiceAgent});
root_span->mutable_labels()->insert(
{kCloudTraceAgentKey,
kServiceAgentPrefix + utils::Version::instance().get()});
GetNow(root_span->mutable_start_time());
}

Expand Down
9 changes: 5 additions & 4 deletions contrib/endpoints/src/api_manager/service_control/proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <chrono>

#include "contrib/endpoints/include/api_manager/service_control.h"
#include "contrib/endpoints/include/api_manager/version.h"
#include "contrib/endpoints/include/api_manager/utils/version.h"
#include "contrib/endpoints/src/api_manager/auth/lib/auth_token.h"
#include "contrib/endpoints/src/api_manager/auth/lib/base64.h"
#include "google/api/metric.pb.h"
Expand Down Expand Up @@ -427,7 +427,7 @@ const char kServiceControlPlatform[] = "servicecontrol.googleapis.com/platform";
const char kUserAgent[] = "ESP";

// Service agent label value
const char kServiceAgent[] = "ESP/" API_MANAGER_VERSION_STRING;
const char kServiceAgentPrefix[] = "ESP/";

// /credential_id
Status set_credential_id(const SupportedLabel& l, const ReportRequestInfo& info,
Expand Down Expand Up @@ -569,7 +569,7 @@ Status set_platform(const SupportedLabel& l, const ReportRequestInfo& info,
// servicecontrol.googleapis.com/service_agent
Status set_service_agent(const SupportedLabel& l, const ReportRequestInfo& info,
Map<std::string, std::string>* labels) {
(*labels)[l.name] = kServiceAgent;
(*labels)[l.name] = kServiceAgentPrefix + utils::Version::instance().get();
return Status::OK;
}

Expand Down Expand Up @@ -926,7 +926,8 @@ Status Proto::FillCheckRequest(const CheckRequestInfo& info,
(*labels)[kServiceControlReferer] = info.referer;
}
(*labels)[kServiceControlUserAgent] = kUserAgent;
(*labels)[kServiceControlServiceAgent] = kServiceAgent;
(*labels)[kServiceControlServiceAgent] =
kServiceAgentPrefix + utils::Version::instance().get();
return Status::OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <fstream>
#include <string>

#include "contrib/endpoints/include/api_manager/version.h"
#include "contrib/endpoints/include/api_manager/utils/version.h"
#include "google/protobuf/struct.pb.h"
#include "google/protobuf/text_format.h"

Expand Down Expand Up @@ -55,7 +55,7 @@ std::string ReadTestBaseline(const char* input_file_name) {
// Replace instances of {{service_agent_version}} with the expected service
// agent version.
std::string placeholder = "{{service_agent_version}}";
std::string value = API_MANAGER_VERSION_STRING;
std::string value = utils::Version::instance().get();
size_t current = 0;
while ((current = contents.find(placeholder, current)) != std::string::npos) {
contents.replace(current, placeholder.length(), value);
Expand Down
1 change: 1 addition & 0 deletions contrib/endpoints/src/api_manager/utils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cc_library(
"marshalling.cc",
"status.cc",
"url_util.cc",
"version.cc",
],
hdrs = [
"marshalling.h",
Expand Down
30 changes: 30 additions & 0 deletions contrib/endpoints/src/api_manager/utils/version.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2016 Google Inc. 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 "contrib/endpoints/include/api_manager/utils/version.h"

namespace google {
namespace api_manager {
namespace utils {

Version& Version::instance() {
static Version v;
return v;
}

} // namespace utils
} // namespace api_manager
} // namespace google
23 changes: 0 additions & 23 deletions contrib/endpoints/tools/BUILD

This file was deleted.

50 changes: 0 additions & 50 deletions contrib/endpoints/tools/create_version.sh

This file was deleted.

0 comments on commit 4ac0064

Please sign in to comment.