Lesson 35 - Get Compute Auth Token Working

This commit is contained in:
Norman Lansing
2026-02-28 12:32:28 -05:00
parent 1d477ee42a
commit 4fde462bce
7743 changed files with 1397833 additions and 18 deletions

View File

@@ -0,0 +1,46 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/utils/memory/stl/AWSMap.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <smithy/Smithy_EXPORTS.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* A container that starts a async measurement
* that has virtual function to stop it.
*/
class SMITHY_API GaugeHandle {
public:
virtual ~GaugeHandle() = default;
/**
* Stop the measurement of the gauge.
*/
virtual void Stop() = 0;
};
/**
* Measures the current instantaneous value. Is used in
* the implementation of a gauge handle to take an actual
* measurement.
*/
class SMITHY_API AsyncMeasurement {
public:
virtual ~AsyncMeasurement() = default;
/**
* A Functional interface of recording a value.
* @param value the value of the measurement.
* @param attributes the attributes or dimensions associate with this measurement.
*/
virtual void Record(double value, const Aws::Map<Aws::String, Aws::String> &attributes) = 0;
};
}
}
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSMap.h>
#include <smithy/Smithy_EXPORTS.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* Measures a value where the statistics are likely meaningful.
*/
class SMITHY_API Histogram {
public:
virtual ~Histogram() = default;
/**
* Records a value to the histogram.
*
* @param value the value that be recorded in a statistical distribution.
* @param attributes the attributes or dimensions associate with this measurement.
*/
virtual void record(double value, Aws::Map<Aws::String, Aws::String> attributes) = 0;
};
}
}
}

View File

@@ -0,0 +1,80 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <smithy/tracing/Gauge.h>
#include <smithy/tracing/MonotonicCounter.h>
#include <smithy/tracing/UpDownCounter.h>
#include <smithy/tracing/Histogram.h>
#include <smithy/Smithy_EXPORTS.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* Entry point to creating instruments. An Instrument is responsible for taking measurements.
* The returned entities will be responsible for taking measurements directly in code.
*/
class SMITHY_API Meter {
public:
virtual ~Meter() = default;
/**
* Create a Gauge instrument that will measure a provided callback function.
* @param name The metric name being recorded.
* @param callback The callback function that will be recording the measurement
* in a async runtime.
* @param units The units of the measurement being recorded.
* @param description The description of the measurement.
* @return A handle to the gauge that has been created that has access to the
* callback being used to record the metric.
*/
virtual Aws::UniquePtr<GaugeHandle> CreateGauge(Aws::String name,
std::function<void(Aws::UniquePtr<AsyncMeasurement>)> callback,
Aws::String units,
Aws::String description) const = 0;
/**
* Create a UpDownCounter that will measure a metric that can increase/decrease
* in count.
*
* @param name The metric name being recorded.
* @param units units The units of the measurement being recorded.
* @param description The description of the measurement.
* @return A UpDownCounter that can record the value of a count.
*/
virtual Aws::UniquePtr<UpDownCounter> CreateUpDownCounter(Aws::String name,
Aws::String units,
Aws::String description) const = 0;
/**
* Create a Counter that will measure a metric that can only increase
* in count.
*
* @param name The metric name being recorded.
* @param units units The units of the measurement being recorded.
* @param description The description of the measurement.
* @return A Counter that can record the value of a count.
*/
virtual Aws::UniquePtr<MonotonicCounter> CreateCounter(Aws::String name,
Aws::String units,
Aws::String description) const = 0;
/**
* Create a Histogram that will measure a metric that can be translated
* into a statistical measurement.
*
* @param name The metric name being recorded.
* @param units units The units of the measurement being recorded.
* @param description The description of the measurement.
* @return A Histogram that can measure a statistical value.
*/
virtual Aws::UniquePtr<Histogram> CreateHistogram(Aws::String name,
Aws::String units,
Aws::String description) const = 0;
};
}
}
}

View File

@@ -0,0 +1,34 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSMap.h>
#include <smithy/Smithy_EXPORTS.h>
#include <smithy/tracing/Meter.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* Entry point for metrics emission API. Will return a meter which in turn
* can provide specific metric taking instruments.
*/
class SMITHY_API MeterProvider {
public:
virtual ~MeterProvider() = default;
/**
* Provide a meter that will in turn provide instruments for metrics.
* @param scope The scope that meter is used for.
* @param attributes the attributes or dimensions associate with this measurement.
* @return A Meter.
*/
virtual std::shared_ptr<Meter> GetMeter(Aws::String scope,
Aws::Map<Aws::String, Aws::String> attributes) = 0;
};
}
}
}

View File

@@ -0,0 +1,30 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSMap.h>
#include <smithy/Smithy_EXPORTS.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* Measures a value that only ever increases.
*/
class SMITHY_API MonotonicCounter {
public:
virtual ~MonotonicCounter() = default;
/**
* Adds a value to counter.
* @param value the count to be added to the counter.
* @param attributes the attributes or dimensions associate with this measurement.
*/
virtual void add(long value, Aws::Map<Aws::String, Aws::String> attributes) = 0;
};
}
}
}

View File

@@ -0,0 +1,122 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <smithy/Smithy_EXPORTS.h>
#include <smithy/tracing/MeterProvider.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* A no-op implementation of the Gauge handle that
* is simply pass though
*/
class NoopGaugeHandle : public GaugeHandle {
public:
void Stop() override {}
};
/**
* A no-op implementation of the UpDownCounter that
* is simply pass though
*/
class NoopUpDownCounter : public UpDownCounter {
void add(long value, Aws::Map<Aws::String, Aws::String> attributes) override {
AWS_UNREFERENCED_PARAM(value);
AWS_UNREFERENCED_PARAM(attributes);
}
};
/**
* A no-op implementation of the MonotonicCounter that
* is simply pass though
*/
class NoopMonotonicCounter : public MonotonicCounter {
void add(long value, Aws::Map<Aws::String, Aws::String> attributes) override {
AWS_UNREFERENCED_PARAM(value);
AWS_UNREFERENCED_PARAM(attributes);
}
};
/**
* A no-op implementation of the Histogram that
* is simply pass though
*/
class NoopHistogram : public Histogram {
public:
void record(double value, Aws::Map<Aws::String, Aws::String> attributes) override {
AWS_UNREFERENCED_PARAM(value);
AWS_UNREFERENCED_PARAM(attributes);
}
};
/**
* A no-op implementation of the Meter that
* is simply pass though
*/
class NoopMeter : public Meter {
public:
Aws::UniquePtr<GaugeHandle> CreateGauge(Aws::String name,
std::function<void(Aws::UniquePtr<AsyncMeasurement>)> callback,
Aws::String units,
Aws::String description) const override
{
AWS_UNREFERENCED_PARAM(name);
AWS_UNREFERENCED_PARAM(callback);
AWS_UNREFERENCED_PARAM(units);
AWS_UNREFERENCED_PARAM(description);
return Aws::MakeUnique<NoopGaugeHandle>("NO_OP");
}
Aws::UniquePtr<UpDownCounter> CreateUpDownCounter(Aws::String name,
Aws::String units,
Aws::String description) const override
{
AWS_UNREFERENCED_PARAM(name);
AWS_UNREFERENCED_PARAM(units);
AWS_UNREFERENCED_PARAM(description);
return Aws::MakeUnique<NoopUpDownCounter>("NO_OP");
}
Aws::UniquePtr<MonotonicCounter> CreateCounter(Aws::String name,
Aws::String units,
Aws::String description) const override
{
AWS_UNREFERENCED_PARAM(name);
AWS_UNREFERENCED_PARAM(units);
AWS_UNREFERENCED_PARAM(description);
return Aws::MakeUnique<NoopMonotonicCounter>("NO_OP");
}
Aws::UniquePtr<Histogram> CreateHistogram(Aws::String name,
Aws::String units,
Aws::String description) const override
{
AWS_UNREFERENCED_PARAM(name);
AWS_UNREFERENCED_PARAM(units);
AWS_UNREFERENCED_PARAM(description);
return Aws::MakeUnique<NoopHistogram>("NO_OP");
}
};
/**
* A no-op implementation of the MeterProvider that
* is simply pass though
*/
class NoopMeterProvider : public MeterProvider {
public:
std::shared_ptr<Meter>
GetMeter(Aws::String scope,Aws::Map<Aws::String,Aws::String> attributes) override
{
AWS_UNREFERENCED_PARAM(scope);
AWS_UNREFERENCED_PARAM(attributes);
return Aws::MakeShared<NoopMeter>("NO_OP");
}
};
}
}
}

View File

@@ -0,0 +1,33 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <smithy/Smithy_EXPORTS.h>
#include <utility>
#include <smithy/tracing/NoopTracerProvider.h>
#include <smithy/tracing/NoopMeterProvider.h>
#include <smithy/tracing/TelemetryProvider.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* A no-op implementation of TelemetryProvider that
* is simply pass though container of telemetry functionality
*/
class SMITHY_API NoopTelemetryProvider {
public:
static Aws::UniquePtr<TelemetryProvider> CreateProvider() {
return Aws::MakeUnique<TelemetryProvider>("NO_OP",
Aws::MakeUnique<NoopTracerProvider>("NO_OP", Aws::MakeUnique<NoopTracer>("NO_OP")),
Aws::MakeUnique<NoopMeterProvider>("NO_OP"),
[]() -> void {},
[]() -> void {});
}
};
}
}
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <smithy/Smithy_EXPORTS.h>
#include <smithy/tracing/TracerProvider.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* A no-op implementation of TraceSpan that is pass through.
*/
class NoopTracerSpan : public TraceSpan {
public:
NoopTracerSpan(const Aws::String &name) : TraceSpan(name) {}
void emitEvent(Aws::String name, const Aws::Map<Aws::String, Aws::String> &attributes) override {
AWS_UNREFERENCED_PARAM(name);
AWS_UNREFERENCED_PARAM(attributes);
}
void setAttribute(Aws::String key, Aws::String value) override {
AWS_UNREFERENCED_PARAM(key);
AWS_UNREFERENCED_PARAM(value);
}
void setStatus(TraceSpanStatus status) override {
AWS_UNREFERENCED_PARAM(status);
}
void end() override {}
};
/**
* A no-op implementation of Tracer that is pass through.
*/
class NoopTracer : public Tracer {
public:
std::shared_ptr<TraceSpan> CreateSpan(Aws::String name,
const Aws::Map<Aws::String, Aws::String> &attributes,
SpanKind spanKind) override {
AWS_UNREFERENCED_PARAM(attributes);
AWS_UNREFERENCED_PARAM(spanKind);
return Aws::MakeShared<NoopTracerSpan>("NO_OP", name);
}
};
/**
* A no-op implementation of NoopTracerProvider that is pass through.
*/
class NoopTracerProvider : public TracerProvider {
public:
explicit NoopTracerProvider(std::shared_ptr<NoopTracer> tracer) : m_tracer(std::move(tracer)) {}
std::shared_ptr<Tracer> GetTracer(Aws::String scope,
const Aws::Map<Aws::String, Aws::String> &attributes) override {
AWS_UNREFERENCED_PARAM(scope);
AWS_UNREFERENCED_PARAM(attributes);
return m_tracer;
}
private:
std::shared_ptr<NoopTracer> m_tracer;
};
}
}
}

View File

@@ -0,0 +1,97 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <smithy/Smithy_EXPORTS.h>
#include <smithy/tracing/TracerProvider.h>
#include <smithy/tracing/MeterProvider.h>
#include <aws/core/utils/memory/AWSMemory.h>
#include <utility>
#include <mutex>
namespace smithy {
namespace components {
namespace tracing {
/**
* A Utility holder class that manages the creation and
* management of telemetry related operations.
*/
class SMITHY_API TelemetryProvider {
public:
/**
* Creates a Telemetry provider with given providers and a init
* and shutdown function that is run during its ctor/dtor.
* @param tracerProvider The TracerProvider to be used in the SDK.
* @param meterProvider The MeterProvider to be used in the SDK.
* @param init The initialization function that will be run at creation.
* @param shutdown The shutdown function that will be run at destruction.
*/
TelemetryProvider(Aws::UniquePtr<TracerProvider> tracerProvider,
Aws::UniquePtr<MeterProvider> meterProvider,
std::function<void()> init,
std::function<void()> shutdown) :
m_tracerProvider(std::move(tracerProvider)),
m_meterProvider(std::move(meterProvider)),
m_init(std::move(init)),
m_shutdown(std::move(shutdown))
{
RunInit();
}
virtual ~TelemetryProvider() {
RunShutDown();
}
/**
* Returns a reference to a Tracer used to create spans.
*
* @param scope The scope of the Tracer that is being used.
* @param attributes the attributes or dimensions associate with this measurement.
* @return A reference to a Tracer instance.
*/
std::shared_ptr<Tracer>
getTracer(Aws::String scope, const Aws::Map<Aws::String, Aws::String> &attributes) {
return m_tracerProvider->GetTracer(std::move(scope), attributes);
}
/**
* Returns a reference to a Meter used to create metrics.
*
* @param scope The scope of the Meter that is being used.
* @param attributes the attributes or dimensions associate with this measurement.
* @return A reference to a Meter instance.
*/
std::shared_ptr<Meter>
getMeter(Aws::String scope, const Aws::Map<Aws::String, Aws::String> &attributes) {
return m_meterProvider->GetMeter(std::move(scope), attributes);
}
/**
* Runs initialization of the Tracer Provider and the MeterProvider. Will only
* be run once during initialization.
*/
void RunInit() {
std::call_once(m_initFlag, m_init);
}
/**
* Runs shutdown of the Tracer Provider and the MeterProvider. Will only
* be run once during destruction.
*/
void RunShutDown() {
std::call_once(m_shutdownFlag, m_shutdown);
}
private:
std::once_flag m_initFlag;
std::once_flag m_shutdownFlag;
const Aws::UniquePtr<TracerProvider> m_tracerProvider;
const Aws::UniquePtr<MeterProvider> m_meterProvider;
const std::function<void()> m_init;
const std::function<void()> m_shutdown;
};
}
}
}

View File

@@ -0,0 +1,70 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSMap.h>
#include <smithy/Smithy_EXPORTS.h>
#include <memory>
#include <utility>
namespace smithy {
namespace components {
namespace tracing {
/**
* Status of the span.
*/
enum class TraceSpanStatus {
UNSET,
OK,
FAULT,
};
/**
* The basic unit of a "Trace". Represents a time period during which events
* occur. Child spans and events can take place within trace. It is a hierarchy
* and ledger of timing and events during a operation.
*/
class SMITHY_API TraceSpan {
public:
/**
* Create a Span
* @param name The name of the span.
*/
TraceSpan(Aws::String name) : m_name(std::move(name)) {}
virtual ~TraceSpan() = default;
/**
* Emit a event associated with the span.
* @param name The name of the event.
* @param attributes the attributes or dimensions associate with this measurement.
*/
virtual void emitEvent(Aws::String name, const Aws::Map<Aws::String, Aws::String> &attributes) = 0;
/**
* Set a Attribute to span.
* @param key The key of the dimension/attribute.
* @param value The value of the dimension/attribute.
*/
virtual void setAttribute(Aws::String key, Aws::String value) = 0;
/**
* Set the statue of the span.
* @param status The status to be assigned.
*/
virtual void setStatus(TraceSpanStatus status) = 0;
/**
* End the span and mark as finished.
*/
virtual void end() = 0;
private:
Aws::String m_name;
};
}
}
}

View File

@@ -0,0 +1,45 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <smithy/tracing/TraceSpan.h>
#include <smithy/Smithy_EXPORTS.h>
#include <memory>
namespace smithy {
namespace components {
namespace tracing {
/**
* The kind of span being created.
*/
enum class SpanKind {
INTERNAL,
CLIENT,
SERVER,
};
/**
* Entry point for creating a Span. Any new spans will
* be created from this.
*/
class SMITHY_API Tracer {
public:
virtual ~Tracer() = default;
/**
* Creates a span.
*
* @param name Name of the span.
* @param attributes the attributes or dimensions associate with this measurement.
* @param spanKind The kind of the span.
* @return A instance of a span.
*/
virtual std::shared_ptr<TraceSpan> CreateSpan(Aws::String name,
const Aws::Map<Aws::String, Aws::String> &attributes,
SpanKind spanKind) = 0;
};
}
}
}

View File

@@ -0,0 +1,30 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <smithy/tracing/Tracer.h>
#include <smithy/Smithy_EXPORTS.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* Entry point for creating Tracer instances.
*/
class SMITHY_API TracerProvider {
public:
virtual ~TracerProvider() = default;
/**
* Returns a reference to a Tracer instance.
* @param scope The scope of the Tracer that is being used.
* @param attributes the attributes or dimensions associate with this measurement.
* @return A reference to a Tracer instance.
*/
virtual std::shared_ptr<Tracer> GetTracer(Aws::String scope, const Aws::Map<Aws::String, Aws::String> &attributes) = 0;
};
}
}
}

View File

@@ -0,0 +1,167 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/monitoring/HttpClientMetrics.h>
#include <aws/core/utils/logging/LogMacros.h>
#include <smithy/Smithy_EXPORTS.h>
#include <smithy/tracing/Meter.h>
#include <functional>
#include <chrono>
#include <utility>
namespace smithy {
namespace components {
namespace tracing {
/**
* A utility class for common tracing activities.
*/
class SMITHY_API TracingUtils {
public:
TracingUtils() = default;
static const char COUNT_METRIC_TYPE[];
static const char MICROSECOND_METRIC_TYPE[];
static const char BYTES_PER_SECOND_METRIC_TYPE[];
static const char SMITHY_CLIENT_DURATION_METRIC[];
static const char SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC[];
static const char SMITHY_CLIENT_DESERIALIZATION_METRIC[];
static const char SMITHY_CLIENT_SIGNING_METRIC[];
static const char SMITHY_CLIENT_SERIALIZATION_METRIC[];
static const char SMITHY_CLIENT_SERVICE_CALL_METRIC[];
static const char SMITHY_CLIENT_SERVICE_BACKOFF_DELAY_METRIC[];
static const char SMITHY_CLIENT_SERVICE_ATTEMPTS_METRIC[];
static const char SMITHY_METHOD_AWS_VALUE[];
static const char SMITHY_SERVICE_DIMENSION[];
static const char SMITHY_METHOD_DIMENSION[];
static const char SMITHY_SYSTEM_DIMENSION[];
static const char SMITHY_METRICS_DNS_DURATION[];
static const char SMITHY_METRICS_CONNECT_DURATION[];
static const char SMITHY_METRICS_SSL_DURATION[];
static const char SMITHY_METRICS_DOWNLOAD_SPEED_METRIC[];
static const char SMITHY_METRICS_UPLOAD_SPEED_METRIC[];
static const char SMITHY_METRICS_UNKNOWN_METRIC[];
/**
* Will run a function and emit the duration of that function in millisecond timing to the
* meter provided as a Histogram metrics. Will return the result af the function.
* @tparam T The type that is being returned from the function.
* @param func A function that returns T.
* @param metricName The name of the metric that is being captured by the function.
* @param meter The meter making the measurement.
* @param attributes The attributes or dimensions associate with this measurement.
* @param description The description of the measurement.
* @return the result of func.
*/
template<typename T>
static T MakeCallWithTiming(std::function<T()> func,
const Aws::String &metricName,
const Meter &meter,
Aws::Map<Aws::String, Aws::String>&& attributes,
const Aws::String &description = "")
{
auto before = std::chrono::steady_clock::now();
auto returnValue = func();
auto after = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(after - before).count();
auto histogram = meter.CreateHistogram(metricName, MICROSECOND_METRIC_TYPE, description);
if (!histogram) {
AWS_LOG_ERROR("TracingUtil", "Failed to create histogram");
return {};
}
histogram->record((double) duration, std::forward<Aws::Map<Aws::String, Aws::String>>(attributes));
return returnValue;
}
/**
* Will run a function and emit the duration of that function in millisecond timing to the
* meter provided as a Histogram metrics.
* @param func a function that does not return anything but will be measured.
* @param metricName The name of the metric that is being captured by the function.
* @param meter The meter making the measurement.
* @param attributes The attributes or dimensions associate with this measurement.
* @param description The description of the measurement.
*/
static void MakeCallWithTiming(std::function<void(void)> func,
Aws::String metricName,
const Meter &meter,
Aws::Map<Aws::String, Aws::String>&& attributes,
Aws::String description = "")
{
auto before = std::chrono::steady_clock::now();
func();
auto after = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(after - before).count();
auto histogram = meter.CreateHistogram(std::move(metricName), MICROSECOND_METRIC_TYPE, std::move(description));
if (!histogram) {
AWS_LOG_ERROR("TracingUtil", "Failed to create histogram");
return;
}
histogram->record((double) duration, std::forward<Aws::Map<Aws::String, Aws::String>>(attributes));
}
/**
* Emits http metrics to a specified meter.
* @param metrics A http metrics collection that we will emit.
* @param meter The meter used for metrics emissions.
* @param attributes The attributes or dimensions associate with this measurement.
* @param description The description of the measurement.
*/
static void EmitCoreHttpMetrics(const Aws::Monitoring::HttpClientMetricsCollection &metrics,
const Meter &meter,
Aws::Map<Aws::String, Aws::String>&& attributes,
Aws::String description = "")
{
for (auto const &entry: metrics) {
auto smithyMetric = ConvertCoreMetricToSmithy(entry.first);
if (smithyMetric.first != SMITHY_METRICS_UNKNOWN_METRIC) {
auto histogram = meter.CreateHistogram(std::move(smithyMetric.first),
smithyMetric.second,
std::move(description));
if (!histogram) {
AWS_LOG_ERROR("TracingUtil", "Failed to create histogram");
}
histogram->record((double) entry.second, attributes);
}
}
}
/**
* Converts the string Representation of a Core metric to a smithy metric.
* @param name the metric name.
* @return A tuple of metric name to measurement unit.
*/
static std::pair<Aws::String, Aws::String> ConvertCoreMetricToSmithy(const Aws::String &name) {
//TODO: Make static map, Aws::Map cannot be made static with a customer memory manager as of the moment.
Aws::Map<int, std::pair<Aws::String, Aws::String>> metricsTypeToName =
{
std::pair<int, std::pair<Aws::String, Aws::String>>(
static_cast<int>(Aws::Monitoring::HttpClientMetricsType::DnsLatency),
std::make_pair(SMITHY_METRICS_DNS_DURATION, MICROSECOND_METRIC_TYPE)),
std::pair<int, std::pair<Aws::String, Aws::String>>(
static_cast<int>(Aws::Monitoring::HttpClientMetricsType::ConnectLatency),
std::make_pair(SMITHY_METRICS_CONNECT_DURATION, MICROSECOND_METRIC_TYPE)),
std::pair<int, std::pair<Aws::String, Aws::String>>(
static_cast<int>(Aws::Monitoring::HttpClientMetricsType::SslLatency),
std::make_pair(SMITHY_METRICS_SSL_DURATION, MICROSECOND_METRIC_TYPE)),
std::pair<int, std::pair<Aws::String, Aws::String>>(
static_cast<int>(Aws::Monitoring::HttpClientMetricsType::DownloadSpeed),
std::make_pair(SMITHY_METRICS_DOWNLOAD_SPEED_METRIC, BYTES_PER_SECOND_METRIC_TYPE)),
std::pair<int, std::pair<Aws::String, Aws::String>>(
static_cast<int>(Aws::Monitoring::HttpClientMetricsType::UploadSpeed),
std::make_pair(SMITHY_METRICS_UPLOAD_SPEED_METRIC, BYTES_PER_SECOND_METRIC_TYPE)),
};
auto metricType = Aws::Monitoring::GetHttpClientMetricTypeByName(name);
auto it = metricsTypeToName.find(static_cast<int>(metricType));
if (it == metricsTypeToName.end()) {
return std::make_pair(SMITHY_METRICS_UNKNOWN_METRIC, "unknown");
}
return it->second;
}
};
}
}
}

View File

@@ -0,0 +1,30 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSMap.h>
#include <smithy/Smithy_EXPORTS.h>
namespace smithy {
namespace components {
namespace tracing {
/**
* Measures a value that goes up or down.
*/
class SMITHY_API UpDownCounter {
public:
virtual ~UpDownCounter() = default;
/**
* Adds a value to counter.
* @param value the count to be added to the counter.
* @param attributes the attributes or dimensions associate with this measurement.
*/
virtual void add(long value, Aws::Map<Aws::String, Aws::String> attributes) = 0;
};
}
}
}