Skip to content

Commit

Permalink
doc: fix formatting for code samples (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan authored Dec 18, 2020
1 parent e4d0b2c commit d0cd94f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
68 changes: 39 additions & 29 deletions docs/cpp-metrics-api-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ A `MeterProvider` interface must support a `global.SetMeterProvider(MeterProvid
* name (required): identifies the instrumentation library.
* version (optional): specifies the version of the instrumenting library (the library injecting OpenTelemetry calls into the code)

```
```cc
# meter_provider.h
class Provider
{
Expand Down Expand Up @@ -94,7 +94,7 @@ private:



```
```cc
# meter_provider.h
class MeterProvider
{
Expand Down Expand Up @@ -126,9 +126,9 @@ This interface consists of a set of **instrument constructors**, and a **facilit



```
```cc
# meter.h
Class Meter {
class Meter {
public:

/////////////////////////Metric Instrument Constructors////////////////////////////
Expand Down Expand Up @@ -184,7 +184,7 @@ public:
* of labels with a single API call. Implementations should find bound metric
* instruments that match the key-value pairs in the labels.
*
* Arugments:
* Arguments:
* labels, labels associated with all measurements in the batch.
* instruments, a span of pointers to instruments to record to.
* values, a synchronized span of values to record to those instruments.
Expand Down Expand Up @@ -275,7 +275,7 @@ Direct calling must also be supported. The user can specify labels with the cap
MUST support `RecordBatch` calling (where a single set of labels is applied to several metric instruments).
```
```cc
# metric.h
/*
Expand Down Expand Up @@ -340,15 +340,16 @@ public:



```
```cc
template <class T>
class SynchronousInstrument: public Instrument {
public:
SynchronousInstrument() = default;

SynchronousInstrument(nostd::string_view name, nostd::string_view description, nostd::string_view unit, bool enabled);
SynchronousInstrument(nostd::string_view name, nostd::string_view description, nostd::string_view unit,
bool enabled);

/**
/**
* Returns a Bound Instrument associated with the specified labels.
* Multiples requests with the same set of labels may return the same
* Bound Instrument instance.
Expand All @@ -358,53 +359,56 @@ public:
*
* @param labels the set of labels, as key-value pairs.
* @return a Bound Instrument
*/
*/
BoundSynchronousInstrument bind(nostd::KeyValueIterable labels);

/**
/**
* Records a single synchronous metric event.
* Since this is an unbound synchronous instrument, labels are required in * metric capture calls.
*
*
* @param labels the set of labels, as key-value pairs.
* @param value the numerical representation of the metric being captured
* @return void
*/
*/
void update(T value, nostd::KeyValueIterable labels); //add or record

};

template <class T>
class BoundSynchronousInstrument: public Instrument {
public:
BoundSynchronousInstrument() = default;

// Will also call the processor to acquire the correct aggregator for this instrument
BoundSynchronousInstrument(nostd::string_view name, nostd::string_view description, nostd::string_view unit, bool enabled);
BoundSynchronousInstrument(nostd::string_view name, nostd::string_view description, nostd::string_view unit,
bool enabled);

/**
/**
* Frees the resources associated with this Bound Instrument.
* The Metric from which this instrument was created is not impacted.
*
* @param none
* @return void
*/
*/
void unbind();

/**
/**
* Records a single synchronous metric event. //Call to aggregator
* Since this is a bound synchronous instrument, labels are notrequired in * metric capture calls.
*
* @param value the numerical representation of the metric being captured
* @return void
*/
*/
void update(T value); //add or record

};

template <class T>
class AsynchronousInstrument: public Instrument{
public:
AsynchronousInstrument(nostd::string_view name, nostd::string_view description, nostd::string_view unit, bool enabled, void (*callback)(ObserverResult<T>));
AsynchronousInstrument(nostd::string_view name, nostd::string_view description, nostd::string_view unit,
bool enabled, void (*callback)(ObserverResult<T>));

/**
* Captures data by activating the callback function associated with the
Expand All @@ -416,7 +420,7 @@ public:
*/
void observe();

/**
/**
* Captures data from the stored callback function. The callback itself
* makes use of the instrument's observe function to take capture
* responsibilities out of the user's hands.
Expand All @@ -439,14 +443,16 @@ private:
The Counter below is an example of one Metric instrument. It is important to note that in the Counter’s add function, it binds the labels to the instrument before calling add, then unbinds. Therefore all interactions with the aggregator take place through bound instruments and by extension, the BaseBoundInstrument Class.
```
```cc
template <class T>
class BoundCounter: public BoundSynchronousInstrument{ //override bind?
public:
BoundCounter() = default;
BoundCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, bool enabled);
/*
* Add adds the value to the counter's sum. The labels are already linked * to the instrument and are not specified.
/*
* Add adds the value to the counter's sum. The labels are already linked
* to the instrument and are not specified.
*
* @param value the numerical representation of the metric being captured
* @param labels the set of labels, as key-value pairs
Expand All @@ -455,23 +461,26 @@ public:
void unbind();
};
template <class T>
class Counter: public SynchronousInstrument{
public:
Counter() = default;
Counter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, bool enabled);
/*
/*
* Bind creates a bound instrument for this counter. The labels are
* associated with values recorded via subsequent calls to Record.
*
* @param labels the set of labels, as key-value pairs.
* @return a BoundIntCounter tied to the specified labels
*/
BoundCounter bind(nostd::KeyValueIterable labels);
/*
/*
* Add adds the value to the counter's sum by sending to aggregator. The labels should contain
* the keys and values to be associated with this value. Counters only * accept positive valued updates.
* the keys and values to be associated with this value. Counters only
* accept positive valued updates.
*
* @param value the numerical representation of the metric being captured
* @param labels the set of labels, as key-value pairs
Expand All @@ -482,9 +491,10 @@ public:
template <class T>
class ValueObserver: public AsynchronousInstrument{
public:
/*
/*
* Add adds the value to the counter's sum. The labels should contain
* the keys and values to be associated with this value. Counters only * accept positive valued updates.
* the keys and values to be associated with this value. Counters only
* accept positive valued updates.
*
* @param value the numerical representation of the metric being captured
* @param labels the set of labels, as key-value pairs
Expand All @@ -495,7 +505,7 @@ public:



```
```cc
// The above Counter and BoundCounter are examples of 1 metric instrument.
// The remaining 5 will also be implemented in a similar fashion.
class UpDownCounter: public SynchronousInstrument;
Expand Down
23 changes: 12 additions & 11 deletions docs/cpp-metrics-sdk-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ A `MeterProvider` interface must support a `global.SetMeterProvider(MeterProvid
The Provider class offers static functions to both get and set the global MeterProvider. Once a user sets the MeterProvider, it will replace the default No-op implementation stored as a private variable and persist for the remainder of the program’s execution. This pattern imitates the TracerProvider used in the Tracing portion of this SDK.


```
```cc
# meter_provider.cc
class MeterProvider
{
Expand Down Expand Up @@ -99,9 +99,9 @@ Each distinctly named Meter (i.e. Meters derived from different instrumentation

### Implementation

```
```cc
# meter.h / meter.cc
Class Meter : public API::Meter {
class Meter : public API::Meter {
public:
/*
* Constructor for Meter class
Expand Down Expand Up @@ -206,7 +206,7 @@ private:
* of labels with a single API call. Implementations should find bound metric
* instruments that match the key-value pairs in the labels.
*
* Arugments:
* Arguments:
* labels, labels associated with all measurements in the batch.
* records, a KeyValueIterable containing metric instrument names such as
* "IntCounter" or "DoubleSumObserver" and the corresponding value
Expand Down Expand Up @@ -239,7 +239,7 @@ private:
```
```cc
# record.h
/*
* This class is used to pass checkpointed values from the Meter
Expand Down Expand Up @@ -372,7 +372,7 @@ The SDK must include the Counter aggregator which maintains a sum and the gauge
All operations should be atomic in languages that support them.


```
```cc
# aggregator.cc
class Aggregator {
public:
Expand All @@ -381,7 +381,7 @@ public:
self.checkpoint_ = nullptr
}

/*
/*
* Update
*
* Updates the current value with the new value.
Expand Down Expand Up @@ -480,7 +480,7 @@ Note: Josh MacDonald is working on implementing a [‘basic’ Processor](https:
Design choice: We recommend that we implement the ‘simple’ Processor first as apart of the MVP and then will also implement the ‘basic’ Processor later on. Josh recommended having both for doing different processes.


```
```cc
#processor.cc
class Processor {
public:
Expand Down Expand Up @@ -555,7 +555,7 @@ There are two different controllers: Push and Pull. The “Push” Controller wi
We recommend implementing the PushController as the initial implementation of the Controller. This Controller is the base controller in the specification. We may also implement the PullController if we have the time to do it.
```
```cc
#push_controller.cc
class PushController {
Expand All @@ -577,6 +577,7 @@ class PushController {
MeterProvider Provider {
return this.provider_;
}
/*
* Start (THREAD SAFE)
*
Expand Down Expand Up @@ -635,7 +636,7 @@ There is very little left for the exporter to do other than format the metric up
Design choice: Our idea is to take the simple trace example [StdoutExporter](https://github.com/open-telemetry/opentelemetry-cpp/blob/master/examples/simple/stdout_exporter.h) and add Metric functionality to it. This will allow us to verify that what we are implementing in the API and SDK works as intended. The exporter will go through the different metric instruments and print the value stored in their aggregators to stdout, **for simplicity only Sum is shown here, but all aggregators will be implemented**.


```
```cc
# stdout_exporter.cc
class StdoutExporter: public exporter {
/*
Expand All @@ -662,7 +663,7 @@ class StdoutExporter: public exporter {
```
```cc
enum class ExportResult {
kSuccess,
kFailure,
Expand Down
4 changes: 2 additions & 2 deletions docs/cpp-ostream-exporter-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Shuts down the exporter. Called when SDK is shut down. This is an opportunity fo

In the OStreamExporter there is no cleanup to be done, so there is no need to use the timeout within the `Shutdown` function as it will never be blocking.

```
```cc
class StreamSpanExporter final : public sdktrace::SpanExporter
{

Expand Down Expand Up @@ -142,7 +142,7 @@ The MetricsExporter is called through the Controller in the SDK data path. The e

Shutdown() is currently not required for the OStreamMetricsExporter.

```
```cc
class StreamMetricsExporter final : public sdkmeter::MetricsExporter
{

Expand Down

0 comments on commit d0cd94f

Please sign in to comment.