Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update new metrics #64

Merged
merged 23 commits into from
Jun 8, 2023

Conversation

duyhungtnn
Copy link
Collaborator

@duyhungtnn duyhungtnn commented May 29, 2023

#56

Changes

  • For get_evaluations, we will report all metrics events, Including the latency and size metrics events.
  • For register_events, we will only report error metrics, such as timeout, network, server errors, etc.
  • Remove the InternalErrorMetricsEvent, and use InternalServerErrorMetricsEvent for 500 internal server errors and InternalSdkErrorMetricsEvent for SDK internal errors.
  • In the metric data labels, we will set the same tag that is used to initialize the SDK.
  • Update test cases
    • Testcase: for ApiIDApdater (NEW)
    • Testcase: Validate mapping from Exception to Error Metrics (NEW)
    • Testcase: MetricsEventAdapterFactoryTest (Update)
    • Testcase: For register_events, we will only report error metrics, such as timeout, network, server errors, etc. (already covered by current test cases)
    • Testcase: For get_evaluations, we will report all metrics events, Including the latency and size metrics events. (already covered by current test cases)

@duyhungtnn
Copy link
Collaborator Author

Hi @cre8ivejp This PR has finished all changes required in #56, and all current test cases passed.

But I am adding more test cases to cover all the new changes

@duyhungtnn
Copy link
Collaborator Author

hi @cre8ivejp this PR is ready for review , please help me to take a look

sizeByte: Int? = null,
): MetricsEventData {
// note: featureTag only available from `GET_EVALUATIONS`
val labels = if (featureTag != null) mapOf("tag" to featureTag) else mapOf()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must set the tag also for REGISTER_EVENTS API.

Copy link
Collaborator Author

@duyhungtnn duyhungtnn Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cre8ivejp
I was thinking about **"featureTag" could be null and the REGISTER_EVENTS API did not have the tag**_

  1. We register events to a server in batch.
    EventInteractor.kt#L89
  • That means each event in the batch will have a "featureTag"
  • Did we support featureTag could be an array of String?
  • Could featureTag have many different values?
  • Could the SDK's user change the featureTag?
  1. On the BKTConfig.kt, featureTag could be null (I was looking in the wrong class ~ The Builder)

  2. I was checking on the iOS repo and JS repo to find a reference

What do you think about this?

Copy link
Contributor

@yshrsmz yshrsmz Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the BKTConfig.kt, featureTag could be null

BKTConfig.featureTag is non-null, and we throw error when it is not configured.

require(!this.featureTag.isNullOrEmpty()) { "featureTag is required" }

So featureTag should always exist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could featureTag have many different values?
Could the SDK's user change the featureTag?

BKTConfig is a data class, and featureTag is declared as val, so it's immutable.

BKTClient should be recreated when changing the featureTag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that means we may have a case that will has many featureTag values @yshrsmz

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand correctly, but each event should have a featureTag(from BKTConfig) of the time it is recorded. You always use featureTag from BKTConfig.

So register_events request may include many different featureTags, but success/failure metrics event of that register_events request does nothing to do with featureTags inside the request. You can just use BKTConfig.featureTag to create success/failure event.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duyhungtnn, as @yshrsmz said, we should always use the BKTConfig.featureTag for both cases when creating metric events.

For example, if we have metric events in the DB with the tag android, and before sending them, the app initializes the SDK again using a different tag, android-tv, it will send metric events with different tags, which is ok.

I'm not sure if this clarifies your question, but please let me know if it doesn't.

Copy link
Collaborator Author

@duyhungtnn duyhungtnn Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cre8ivejp
on your example :

  • In the DB has metric events with the tag "android"
    ["tag: android", "tag: android"]
    If sending them fails will create an error metric event with the tag "android"
  • before sending them, the app initializes the SDK again using a different tag, "android-tv"
  • after that, some metric events were tracked with the new tag "android-tv"
  • Now in the DB, we have metrics events with tags "android", and "android-tv".
    ["tag: android", "tag: android", "tag: android-tv", "tag: android-tv"]
  • Now it is time to "register_events" in batch ... and we may get some errors.
  • The question: new error metric will be tracked with what tags?
    1. Option 1: Tags cached in the database. One error metric event with the tag "android", and one error metric event with the tag "android-tv"
    2. Option 2: Or tag in the current BKTConfig.featureTag "android-tv"

If 1) we will have more than 1 new error metric event tracked depending on how many unique featured tags
If 2) we will only have one error metric, but the tag only has the current, not the previous cached.

The problem with (2) is, error metrics events have a tag that seems not correct with cached events when they logged into DB

Hope it clearly my question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say you instantiated BKTClient with "android-3" featureTag, and you have 2 events in DB.
BKTClient tries to create a register_events request.

{
  "events": [
    {
      "eventType": 4, // METRICS
      "event": {
        "labels": { "tag": "android" },
        // other values go here...
      }
    }, 
    {
      "eventType": 1, // GOAL
      "event": {
        "labels": { "tag": "android-2" },
        // other values go here...
      }
    }
  ]
}

And the response is returned with error(all registration is failed), so you save failure metrics event.

Then after several minutes, BKTClient tries to send another register_events. In this case, we have 3 events in a DB.

The request looks like this.

{
  "events": [
    {
      "eventType": 4, // METRICS
      "event": {
        "labels": { "tag": "android" },
        // other values go here...
      }
    }, 
    {
      "eventType": 1, // GOAL
      "event": {
        "labels": { "tag": "android-2" },
        // other values go here...
      }
    },
    {
      "eventType": 4, // METRICS
      "event": {
        // here you save new failure metrics event with `android-3` tag
        "labels": { "tag": "android-3" },
        // other values go here...
      }
    }
  ]
}

So feature tag is in each event, and you don't need to care about multiple featureTag in a single labels map.

Copy link
Contributor

@yshrsmz yshrsmz Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question: new error metric will be tracked with what tags?

You should use BKTConfig.featureTag. new event should always use that value.

apiID: ApiID,
type: MetricsEventType,
// note: only available on success request
latencySecond: Long? = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be better if we split the function or refactor it. One for success and another for failure, so we can avoid those checking for latencySecond and sizeByte throwing an exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its ready now

sdkVersion = BuildConfig.SDK_VERSION,
metadata = newMetadata(appVersion),
),
)
}
internal fun newMetricsEventData(
featureTag: String?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The featureTag shouldn't be optional at this point.

@cre8ivejp cre8ivejp requested a review from yshrsmz June 2, 2023 00:22
@duyhungtnn
Copy link
Collaborator Author

duyhungtnn commented Jun 2, 2023 via email

data class GetEvaluationLatencyMetricsEvent(
@JsonClass(generateAdapter = true)
data class LatencyMetricsEvent(
val apiID: ApiID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val apiID: ApiID,
val apiId: ApiID,

(not sure if API is updated though)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks , I updated that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private fun trackSendEventsFailure(
error: BKTException,
) = trackMetricsEventWhenRequestAPIFailure(
featureTag = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the BKTConfig.featureTag as discussed here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@duyhungtnn
Copy link
Collaborator Author

duyhungtnn commented Jun 2, 2023 via email

@duyhungtnn
Copy link
Collaborator Author

@cre8ivejp @yshrsmz
I fixed the problem with the error metric tags and updated testcase.
Please help me to review this PR once again.
Thank you.

@@ -12,6 +12,7 @@ import io.bucketeer.sdk.android.internal.remote.ApiClient

internal class InteractorModule(
val mainHandler: Handler,
val featureTag: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this parameter to fun eventInteractor? BKTConfig belongs to DataModule, so we want to ensure we use a value from it.

Just like appVersion parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check it @yshrsmz

duyhungtnn and others added 2 commits June 6, 2023 09:52
Co-authored-by: Yasuhiro SHIMIZU <the.phantom.bane@gmail.com>
@duyhungtnn
Copy link
Collaborator Author

hi @yshrsmz I make the changes as per your suggestion.
Please help me to take a look

@duyhungtnn duyhungtnn requested a review from yshrsmz June 6, 2023 02:57
Copy link
Contributor

@yshrsmz yshrsmz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small suggestion.

but overall, looks good to me.

duyhungtnn and others added 2 commits June 6, 2023 21:03
…droid/internal/event/EventInteractor.kt

Co-authored-by: Yasuhiro SHIMIZU <the.phantom.bane@gmail.com>
@duyhungtnn
Copy link
Collaborator Author

@yshrsmz I applied your suggestion.
Please continue reviewing . Thank

@duyhungtnn duyhungtnn requested a review from yshrsmz June 6, 2023 14:09
Copy link
Contributor

@yshrsmz yshrsmz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! 👍

Copy link
Member

@cre8ivejp cre8ivejp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@cre8ivejp cre8ivejp merged commit 61c574b into bucketeer-io:main Jun 8, 2023
@duyhungtnn duyhungtnn deleted the 56-feat/update-new-metrics branch June 3, 2024 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants