markap14 commented on a change in pull request #3681: NIFI-6510 - Analytics framework URL: https://github.com/apache/nifi/pull/3681#discussion_r320936286
########## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/analytics/StatusMetricExtractFunction.java ########## @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.controller.status.analytics; + +import java.util.stream.Stream; + +import org.apache.nifi.controller.status.history.StatusHistory; +import org.apache.nifi.util.Tuple; + +public interface StatusMetricExtractFunction { + + /** + * Searches through status history to extract observations for a given metric + * @param metric metric value that should be extracted + * @param statusHistory StatusHistory object used to search metrics + * @return a Tuple with extracted observations (features and targets/labels) + */ + Tuple<Stream<Double[]>, Stream<Double>> extractMetric(String metric, StatusHistory statusHistory); Review comment: It is generally unadvisable to introduce the notion of a `Tuple` into an interface. `Tuple` is convenient for private member variables that are not exposed, or for correlating two objects with an inline variable. However, when being exposed in an API, an object should be preferred with more intuitive names. Given that this is used in `StatusMetricExtractFunction` I would suggest that this method should probably return a `StatusMetric` object. That object should then have a `List<Double[]> getFeatures()` method and a `List<Double> getLabels()` method, for instance. If `Stream` is in fact preferred over `List` (though I would tend to prefer a `List` here, based on the code that I've reviewed thus far), I would recommend using a `DoubleStream` instead of a `Stream<Double>`. Or, depending on how the values are to be used, if the values in the first Stream are expected to be iterated over in tandem with the the values of the second Stream, it may make more sense to have the method return a `StatusMetrics` object that provides a `List` of `StatusMetric`, which then has `Double[] getFeatures()` and `Double getLabel()` methods... ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
