Skip to content

Conversation

dimitris-athanasiou
Copy link
Contributor

This commit extracts the inner class ModelStats of InferenceFeatureSetUsage into its own file.

There are 2 reasons for doing this:

  • Allows testing of the InferenceFeatureSetUsage class
  • Introduces a usage package under inference that can be used to accommodate additional usage data.

This commit extracts the inner class `ModelStats` of
`InferenceFeatureSetUsage` into its own file.

There are 2 reasons for doing this:

  - Allows testing of the `InferenceFeatureSetUsage` class
  - Introduces a `usage` package under `inference` that can be
  used to accommodate additional usage data.
@elasticsearchmachine elasticsearchmachine added the Team:ML Meta label for the ML team label Sep 12, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

Comment on lines +28 to +33
@Override
protected ModelStats mutateInstance(ModelStats modelStats) throws IOException {
ModelStats newModelStats = new ModelStats(modelStats);
newModelStats.add();
return newModelStats;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This implementation will only test that changes to count in ModelStats are correctly accounted for in the equals() method. Since the equals() method also considers the service and taskType fields, those should be included here too to give full coverage. Something like this maybe:

protected ModelStats mutateInstance(ModelStats modelStats) throws IOException {
    String service = modelStats.service();
    TaskType taskType = modelStats.taskType();
    long count = modelStats.count();
    return switch (randomInt(2)) {
        case 0 -> new ModelStats(randomValueOtherThan(service, ESTestCase::randomIdentifier), taskType, count);
        case 1 -> new ModelStats(service, randomValueOtherThan(taskType, () -> randomFrom(TaskType.values())), count);
        case 2 -> new ModelStats(service, taskType, randomValueOtherThan(count, ESTestCase::randomLong));
        default -> throw new IllegalArgumentException();
    };
}

}

public static ModelStats createRandomInstance() {
return new ModelStats(randomIdentifier(), TaskType.values()[randomInt(TaskType.values().length - 1)], randomInt(10));
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick, but the second argument here would be more readable as randomFrom(TaskType.values())

Comment on lines +46 to +48
public void add() {
count++;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a very minor point, but could there be a test of this method added to ModelStatsTests?

@dimitris-athanasiou
Copy link
Contributor Author

dimitris-athanasiou commented Sep 12, 2025

@DonalEvans I appreciate and agree with all your points. But all the code they refer to was just moved. I would like to keep this move PR simple like this, I did minimal changes I had to do. Would it be ok if I address all your points in a follow-up improve ModelStatsTests or something PR?

@DonalEvans
Copy link
Contributor

@DonalEvans I appreciate and agree with all your points. But all the code they refer to was just moved. I would like to keep this move PR simple like this, I did minimal changes I had to do. Would it be ok if I address all your points in a follow-up improve ModelStatsTests or something PR?

Absolutely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:ml Machine learning >refactoring Team:ML Meta label for the ML team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants