Skip to content

Commit

Permalink
Pull request #210: RUM-20521 Adding int64_t for WebTracer bytesSent a…
Browse files Browse the repository at this point in the history
…nd bytesReceived

Merge in OP/openkit-native from feature/RUM-20521-openkit-java-.net-native-should-use-long-instead-of-int-for-bytessent-and to main

* commit '88c6ec9571953c39b090f16a2375d4167d912f22':
  RUM-20521 Forgot to update header for sample
  RUM-20521 Sample Fix
  RUM-20521 Adding int64_t for WebTracer bytesSent and bytesReceived

GitOrigin-RevId: dda941a86175fb2885fbe4614720905184d113be
  • Loading branch information
TheHighriser authored and openkitdt committed Jul 18, 2024
1 parent 7940ed3 commit a08d10a
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 25 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

## [Unreleased](https://github.com/Dynatrace/openkit-native/compare/v3.2.0...HEAD)

### Added

- `IWebRequestTracer::setBytesSent(int64_t bytes)` to increase the size range
- `IWebRequestTracer::setBytesReceived(int64_t bytes)` to increase the size range
- `setBytesSentLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytes)` to increase the size range
- `setBytesReceivedLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytes)` to increase the size range

### Changed

- Deprecated `IWebRequestTracer::setBytesSent(int32_t bytes)` due to datatype limitations
- Deprecated `IWebRequestTracer::setBytesReceived(int32_t bytes)` due to datatype limitations
- Deprecated `setBytesSent(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytes)` due to datatype limitations
- Deprecated `setBytesReceived(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytes)` due to datatype limitations

## 3.2.0 [Release date: 2023-12-06]
[GitHub Releases](https://github.com/Dynatrace/openkit-native/releases/tag/v3.2.0)

Expand Down
8 changes: 4 additions & 4 deletions docs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ webRequestTracer->start();

// perform the request here & do not forget to add the HTTP header

webRequestTracer->setBytesSent(12345); // 12345 bytes sent
webRequestTracer->setBytesReceived(67890); // 67890 bytes received
webRequestTracer->setBytesSent(12345L); // 12345 bytes sent
webRequestTracer->setBytesReceived(67890L); // 67890 bytes received
webRequestTracer->stop(200); // 200 was the response code

// also reset the shared pointer after stop() method has been called
Expand Down Expand Up @@ -752,8 +752,8 @@ startWebRequest(webRequestTracer);
// perform the request here & do not forget to add the HTTP header
setBytesSent(webRequestTracer, 12345); // 12345 bytes sent
setBytesReceived(webRequestTracer, 67890); // 67890 bytes received
setBytesSent(webRequestTracer, 12345L); // 12345 bytes sent
setBytesReceived(webRequestTracer, 67890L); // 67890 bytes received
stopWebRequestWithResponseCode(webRequestTracer, 200); // 200 was the response code
// since webRequestTracer now points to an invalid memory
Expand Down
20 changes: 20 additions & 0 deletions include/OpenKit/IWebRequestTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,37 @@ namespace openkit
///
/// @param[in] bytesSent number of bytes sent
/// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call
/// @deprecated This method should no longer be used due its datatype limitation. Use IWebRequestTracer::setBytesSent(int64_t) instead.
///
OPENKIT_DEPRECATED
virtual std::shared_ptr<IWebRequestTracer> setBytesSent(int32_t bytesSent) = 0;

///
/// Sets the amount of sent data of this web request. Has to be called before @ref openkit::IWebRequestTracer::stop(int).
///
/// @param[in] bytesSent number of bytes sent
/// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call
///
virtual std::shared_ptr<IWebRequestTracer> setBytesSent(int64_t bytesSent) = 0;

///
/// Sets the amount of received data of this web request. Has to be called before @ref openkit::IWebRequestTracer::stop(int).
///
/// @param[in] bytesReceived number of bytes received
/// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call
/// @deprecated This method should no longer be used due its datatype limitation. Use IWebRequestTracer::setBytesReceived(int64_t) instead.
///
OPENKIT_DEPRECATED
virtual std::shared_ptr<IWebRequestTracer> setBytesReceived(int32_t bytesReceived) = 0;

///
/// Sets the amount of received data of this web request. Has to be called before @ref openkit::IWebRequestTracer::stop(int).
///
/// @param[in] bytesReceived number of bytes received
/// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call
///
virtual std::shared_ptr<IWebRequestTracer> setBytesReceived(int64_t bytesReceived) = 0;

///
/// Starts the web request timing. Should be called when the web request is initiated.
///
Expand Down
20 changes: 20 additions & 0 deletions include/OpenKit/OpenKit-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,17 +969,37 @@ extern "C" {
///
/// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction
/// @param[in] bytesSent number of bytes sent
/// @deprecated This method should no longer be used due its datatype limitation. Use setBytesSent(struct WebRequestTracerHandle*, int64_t) instead.
///
OPENKIT_DEPRECATED
OPENKIT_EXPORT void setBytesSent(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesSent);

///
/// Sets the amount of received data of this web request. Has to be called before @ref stopWebRequest().
///
/// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction
/// @param[in] bytesReceived number of bytes received
/// @deprecated This method should no longer be used due its datatype limitation. Use setBytesSent(struct WebRequestTracerHandle*, int64_t) instead.
///
OPENKIT_DEPRECATED
OPENKIT_EXPORT void setBytesReceived(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesReceived);

///
/// Sets the amount of sent data of this web request. Has to be called before @ref stopWebRequest().
///
/// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction
/// @param[in] bytesSent number of bytes sent
///
OPENKIT_EXPORT void setBytesSentLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesSent);

///
/// Sets the amount of received data of this web request. Has to be called before @ref stopWebRequest().
///
/// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction
/// @param[in] bytesReceived number of bytes received
///
OPENKIT_EXPORT void setBytesReceivedLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesReceived);


#ifdef __cplusplus
} // extern "C"
Expand Down
4 changes: 2 additions & 2 deletions samples/sample1/src/openkit-sample.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ int32_t main(int32_t argc, char** argv)

std::this_thread::sleep_for(std::chrono::milliseconds(144));

webRequest->setBytesSent(123);
webRequest->setBytesReceived(45);
webRequest->setBytesSent(123L);
webRequest->setBytesReceived(45L);
webRequest->stop(200);

childAction1->leaveAction();
Expand Down
4 changes: 2 additions & 2 deletions samples/sample2/src/openkit-sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ int32_t main(int32_t argc, char** argv)
#else
usleep(144 * 1000);
#endif
setBytesSent(webRequest, 123);
setBytesReceived(webRequest, 45);
setBytesSent(webRequest, 123L);
setBytesReceived(webRequest, 45L);
stopWebRequestWithResponseCode(webRequest, 200);

leaveAction(actionHandle);
Expand Down
10 changes: 10 additions & 0 deletions src/api-c/OpenKit-c.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,11 @@ extern "C" {
}

void setBytesSent(WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesSent)
{
setBytesSentLong(webRequestTracerHandle, bytesSent);
}

void setBytesSentLong(WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesSent)
{
TRY
{
Expand All @@ -1744,6 +1749,11 @@ extern "C" {
}

void setBytesReceived(WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesReceived)
{
setBytesReceivedLong(webRequestTracerHandle, bytesReceived);
}

void setBytesReceivedLong(WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesReceived)
{
TRY
{
Expand Down
8 changes: 6 additions & 2 deletions src/core/objects/IWebRequestTracerInternals.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace core

std::shared_ptr<IWebRequestTracer> setBytesReceived(int32_t bytesReceived) override = 0;

std::shared_ptr<IWebRequestTracer> setBytesSent(int64_t bytesSent) override = 0;

std::shared_ptr<IWebRequestTracer> setBytesReceived(int64_t bytesReceived) override = 0;

std::shared_ptr<IWebRequestTracer> start() override = 0;

void stop(int32_t responseCode) override = 0;
Expand Down Expand Up @@ -87,13 +91,13 @@ namespace core
/// Returns the number of bytes sent
/// @returns amount of bytes sent
///
virtual int32_t getBytesSent() const = 0;
virtual int64_t getBytesSent() const = 0;

///
/// Returns the number of bytes received
/// @returns amount of bytes received
///
virtual int32_t getBytesReceived() const = 0;
virtual int64_t getBytesReceived() const = 0;

///
/// Returns a flag if stop() has already been called
Expand Down
10 changes: 10 additions & 0 deletions src/core/objects/NullWebRequestTracer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ std::shared_ptr<openkit::IWebRequestTracer> NullWebRequestTracer::setBytesReceiv
return shared_from_this();
}

std::shared_ptr<openkit::IWebRequestTracer> NullWebRequestTracer::setBytesSent(int64_t /*bytesSent*/)
{
return shared_from_this();
}

std::shared_ptr<openkit::IWebRequestTracer> NullWebRequestTracer::setBytesReceived(int64_t /*bytesReceived*/)
{
return shared_from_this();
}

std::shared_ptr<openkit::IWebRequestTracer> NullWebRequestTracer::start()
{
return shared_from_this();
Expand Down
4 changes: 4 additions & 0 deletions src/core/objects/NullWebRequestTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ namespace core

std::shared_ptr<openkit::IWebRequestTracer> setBytesReceived(int32_t /*bytesReceived*/) override;

std::shared_ptr<openkit::IWebRequestTracer> setBytesSent(int64_t /*bytesSent*/) override;

std::shared_ptr<openkit::IWebRequestTracer> setBytesReceived(int64_t /*bytesReceived*/) override;

std::shared_ptr<openkit::IWebRequestTracer> start() override;

void stop(int32_t /*responseCode*/) override;
Expand Down
14 changes: 12 additions & 2 deletions src/core/objects/WebRequestTracer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ const char* WebRequestTracer::getTag() const
}

std::shared_ptr<openkit::IWebRequestTracer> WebRequestTracer::setBytesSent(int32_t bytesSent)
{
return this->setBytesSent((int64_t) bytesSent);
}

std::shared_ptr<openkit::IWebRequestTracer> WebRequestTracer::setBytesSent(int64_t bytesSent)
{
// synchronized scope
{
Expand All @@ -96,6 +101,11 @@ std::shared_ptr<openkit::IWebRequestTracer> WebRequestTracer::setBytesSent(int32
}

std::shared_ptr<openkit::IWebRequestTracer> WebRequestTracer::setBytesReceived(int32_t bytesReceived)
{
return this->setBytesReceived((int64_t) bytesReceived);
}

std::shared_ptr<openkit::IWebRequestTracer> WebRequestTracer::setBytesReceived(int64_t bytesReceived)
{
// synchronized scope
{
Expand Down Expand Up @@ -208,12 +218,12 @@ int32_t WebRequestTracer::getEndSequenceNo() const
return mEndSequenceNo;
}

int32_t WebRequestTracer::getBytesSent() const
int64_t WebRequestTracer::getBytesSent() const
{
return mBytesSent;
}

int32_t WebRequestTracer::getBytesReceived() const
int64_t WebRequestTracer::getBytesReceived() const
{
return mBytesReceived;
}
Expand Down
12 changes: 8 additions & 4 deletions src/core/objects/WebRequestTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ namespace core

std::shared_ptr<IWebRequestTracer> setBytesReceived(int32_t bytesReceived) override;

std::shared_ptr<IWebRequestTracer> setBytesSent(int64_t bytesSent) override;

std::shared_ptr<IWebRequestTracer> setBytesReceived(int64_t bytesReceived) override;

std::shared_ptr<IWebRequestTracer> start() override;

void stop(int32_t responseCode) override;
Expand Down Expand Up @@ -133,13 +137,13 @@ namespace core
/// Returns the number of bytes sent
/// @returns amount of bytes sent
///
int32_t getBytesSent() const override;
int64_t getBytesSent() const override;

///
/// Returns the number of bytes received
/// @returns amount of bytes received
///
int32_t getBytesReceived() const override;
int64_t getBytesReceived() const override;

///
/// Returns a flag if stop() has already been called
Expand Down Expand Up @@ -190,10 +194,10 @@ namespace core
int32_t mResponseCode;

/// Number of bytes sent for the web request
int32_t mBytesSent;
int64_t mBytesSent;

/// Number of bytes received for the web request
int32_t mBytesReceived;
int64_t mBytesReceived;

/// web request start time
int64_t mStartTime;
Expand Down
4 changes: 4 additions & 0 deletions test/api/mock/MockIWebRequestTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ namespace test

MOCK_METHOD(std::shared_ptr<openkit::IWebRequestTracer>, setBytesReceived, (int32_t), (override));

MOCK_METHOD(std::shared_ptr<openkit::IWebRequestTracer>, setBytesSent, (int64_t), (override));

MOCK_METHOD(std::shared_ptr<openkit::IWebRequestTracer>, setBytesReceived, (int64_t), (override));

MOCK_METHOD(std::shared_ptr<openkit::IWebRequestTracer>, start, (), (override));

MOCK_METHOD(void, stop, (int32_t), (override));
Expand Down
28 changes: 28 additions & 0 deletions test/core/objects/NullWebRequestTracerTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ TEST_F(NullWebRequestTracerTest, setBytesReceivedReturnsSelf)
ASSERT_THAT(nullTracer, testing::Eq(target));
}

TEST_F(NullWebRequestTracerTest, setBytesSentLongReturnsSelf)
{
// given
auto target = NullWebRequestTracer_t::instance();

// when
auto obtained = target->setBytesSent(37L);

// then
auto nullTracer = std::dynamic_pointer_cast<NullWebRequestTracer_t>(obtained);
ASSERT_THAT(nullTracer, testing::NotNull());
ASSERT_THAT(nullTracer, testing::Eq(target));
}

TEST_F(NullWebRequestTracerTest, setBytesReceivedLongReturnsSelf)
{
// given
auto target = NullWebRequestTracer_t::instance();

// when
auto obtained = target->setBytesReceived(73L);

// then
auto nullTracer = std::dynamic_pointer_cast<NullWebRequestTracer_t>(obtained);
ASSERT_THAT(nullTracer, testing::NotNull());
ASSERT_THAT(nullTracer, testing::Eq(target));
}

TEST_F(NullWebRequestTracerTest, startReturnsSelf)
{
// given
Expand Down
Loading

0 comments on commit a08d10a

Please sign in to comment.