Repository: envoyproxy/envoy
File: source/extensions/filters/common/expr/context.cc (C++)

Code before:
             }

             const StreamInfo::UpstreamInfo& upstream_info = wrapper.info_.upstreamInfo().value();
             const absl::optional<std::chrono::nanoseconds> connection_pool_callback_latency =
                 upstream_info.upstreamTiming().connectionPoolCallbackLatency();
             if (connection_pool_callback_latency.has_value()) {
               return CelValue::CreateDuration(
                   absl::FromChrono(connection_pool_callback_latency.value()));
             }
             return {};
           }},
          {UpstreamRequestAttemptCount,
           [](const UpstreamWrapper& wrapper) -> absl::optional<CelValue> {
             return CelValue::CreateUint64(wrapper.info_.attemptCount().value_or(0));
          }},
          {UpstreamNumEndpoints,
           [](const UpstreamWrapper& wrapper) -> absl::optional<CelValue> {
             if (wrapper.info_.upstreamClusterInfo().value_or(nullptr) !=
                 nullptr) {
               return CelValue::CreateUint64(wrapper.info_.upstreamClusterInfo()
                                               .value()
                                               .get()
                                               ->endpointStats()
                                               .membership_total_.value());
             }
             return CelValue::CreateUint64(0);
           }}});
}

// XDS lookup implementation
const XDSLookupValues& XDSLookupValues::get() {
  CONSTRUCT_ON_FIRST_USE(
      XDSLookupValues,
      absl::flat_hash_map<absl::string_view, XDSValueExtractor>{
          {Node,
           [](const XDSWrapper& wrapper) -> absl::optional<CelValue> {
             if (wrapper.local_info_) {
               return CelProtoWrapper::CreateMessage(&wrapper.local_info_->node(), &wrapper.arena_);
             }
             return {};
           }},
          {ClusterName,
           [](const XDSWrapper& wrapper) -> absl::optional<CelValue> {
             if (wrapper.info_ == nullptr) {
               return {};
             }
             const auto cluster_info = wrapper.info_->upstreamClusterInfo();
             if (cluster_info && cluster_info.value()) {
               return CelValue::CreateString(&cluster_info.value()->name());
             }
             return {};

Review comment (suggestion):
Will `return {}` works here? If so, it is better than returning 0 to represent non-existence 

Code after:
             }

             const StreamInfo::UpstreamInfo& upstream_info = wrapper.info_.upstreamInfo().value();
             const absl::optional<std::chrono::nanoseconds> connection_pool_callback_latency =
                 upstream_info.upstreamTiming().connectionPoolCallbackLatency();
             if (connection_pool_callback_latency.has_value()) {
               return CelValue::CreateDuration(
                   absl::FromChrono(connection_pool_callback_latency.value()));
             }
             return {};
           }},
          {UpstreamRequestAttemptCount,
           [](const UpstreamWrapper& wrapper) -> absl::optional<CelValue> {
             return CelValue::CreateUint64(wrapper.info_.attemptCount().value_or(0));
           }},
          {UpstreamNumEndpoints, [](const UpstreamWrapper& wrapper) -> absl::optional<CelValue> {
             if (wrapper.info_.upstreamClusterInfo().value_or(nullptr) != nullptr) {
               return CelValue::CreateUint64(wrapper.info_.upstreamClusterInfo()
                                                 .value()
                                                 .get()
                                                 ->endpointStats()
                                                 .membership_total_.value());
             }
             return {};
           }}});
}

// XDS lookup implementation
const XDSLookupValues& XDSLookupValues::get() {
  CONSTRUCT_ON_FIRST_USE(
      XDSLookupValues,
      absl::flat_hash_map<absl::string_view, XDSValueExtractor>{
          {Node,
           [](const XDSWrapper& wrapper) -> absl::optional<CelValue> {
             if (wrapper.local_info_) {
               return CelProtoWrapper::CreateMessage(&wrapper.local_info_->node(), &wrapper.arena_);
             }
             return {};
           }},
          {ClusterName,
           [](const XDSWrapper& wrapper) -> absl::optional<CelValue> {
             if (wrapper.info_ == nullptr) {
               return {};
             }
             const auto cluster_info = wrapper.info_->upstreamClusterInfo();
             if (cluster_info && cluster_info.value()) {
               return CelValue::CreateString(&cluster_info.value()->name());
             }
             return {};
           }},
          {ClusterMetadata,