Copilot commented on code in PR #13624:
URL: https://github.com/apache/skywalking/pull/13624#discussion_r2625270546


##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/meter/function/latest/LatestLabeledFunction.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.skywalking.oap.server.core.analysis.meter.function.latest;
+
+import java.util.Objects;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+import 
org.apache.skywalking.oap.server.core.analysis.manual.instance.InstanceTraffic;
+import org.apache.skywalking.oap.server.core.analysis.meter.Meter;
+import org.apache.skywalking.oap.server.core.analysis.meter.MeterEntity;
+import 
org.apache.skywalking.oap.server.core.analysis.meter.function.AcceptableValue;
+import 
org.apache.skywalking.oap.server.core.analysis.meter.function.MeterFunction;
+import org.apache.skywalking.oap.server.core.analysis.metrics.DataTable;
+import 
org.apache.skywalking.oap.server.core.analysis.metrics.LabeledValueHolder;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
+import org.apache.skywalking.oap.server.core.storage.StorageID;
+import org.apache.skywalking.oap.server.core.storage.annotation.BanyanDB;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+import org.apache.skywalking.oap.server.core.storage.annotation.ElasticSearch;
+import org.apache.skywalking.oap.server.core.storage.type.Convert2Entity;
+import org.apache.skywalking.oap.server.core.storage.type.Convert2Storage;
+import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder;
+
+@MeterFunction(functionName = "latestLabeled")
+@ToString
+public abstract class LatestLabeledFunction extends Meter implements 
AcceptableValue<DataTable>, LabeledValueHolder {
+
+    public static final String VALUE = "datatable_value";
+
+    @Setter
+    @Getter
+    @ElasticSearch.EnableDocValues
+    @Column(name = ENTITY_ID, length = 512)
+    @BanyanDB.SeriesID(index = 0)
+    private String entityId;
+

Review Comment:
   This method overrides [Meter.getEntityId](1); it is advisable to add an 
Override annotation.
   ```suggestion
       @ElasticSearch.EnableDocValues
       @Column(name = ENTITY_ID, length = 512)
       @BanyanDB.SeriesID(index = 0)
       private String entityId;
   
       @Override
       public String getEntityId() {
           return entityId;
       }
   ```



##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/meter/function/latest/LatestLabeledFunction.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.skywalking.oap.server.core.analysis.meter.function.latest;
+
+import java.util.Objects;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+import 
org.apache.skywalking.oap.server.core.analysis.manual.instance.InstanceTraffic;
+import org.apache.skywalking.oap.server.core.analysis.meter.Meter;
+import org.apache.skywalking.oap.server.core.analysis.meter.MeterEntity;
+import 
org.apache.skywalking.oap.server.core.analysis.meter.function.AcceptableValue;
+import 
org.apache.skywalking.oap.server.core.analysis.meter.function.MeterFunction;
+import org.apache.skywalking.oap.server.core.analysis.metrics.DataTable;
+import 
org.apache.skywalking.oap.server.core.analysis.metrics.LabeledValueHolder;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
+import org.apache.skywalking.oap.server.core.storage.StorageID;
+import org.apache.skywalking.oap.server.core.storage.annotation.BanyanDB;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+import org.apache.skywalking.oap.server.core.storage.annotation.ElasticSearch;
+import org.apache.skywalking.oap.server.core.storage.type.Convert2Entity;
+import org.apache.skywalking.oap.server.core.storage.type.Convert2Storage;
+import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder;
+
+@MeterFunction(functionName = "latestLabeled")
+@ToString
+public abstract class LatestLabeledFunction extends Meter implements 
AcceptableValue<DataTable>, LabeledValueHolder {
+
+    public static final String VALUE = "datatable_value";
+
+    @Setter
+    @Getter
+    @ElasticSearch.EnableDocValues
+    @Column(name = ENTITY_ID, length = 512)
+    @BanyanDB.SeriesID(index = 0)
+    private String entityId;
+
+    /**
+     * Service ID is required for sort query.
+     */
+    @Setter
+    @Getter
+    @Column(name = InstanceTraffic.SERVICE_ID)
+    private String serviceId;
+
+    @Getter

Review Comment:
   This method overrides [LabeledValueHolder.getValue](1); it is advisable to 
add an Override annotation.



##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/meter/function/latest/LatestLabeledFunction.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.skywalking.oap.server.core.analysis.meter.function.latest;
+
+import java.util.Objects;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+import 
org.apache.skywalking.oap.server.core.analysis.manual.instance.InstanceTraffic;
+import org.apache.skywalking.oap.server.core.analysis.meter.Meter;
+import org.apache.skywalking.oap.server.core.analysis.meter.MeterEntity;
+import 
org.apache.skywalking.oap.server.core.analysis.meter.function.AcceptableValue;
+import 
org.apache.skywalking.oap.server.core.analysis.meter.function.MeterFunction;
+import org.apache.skywalking.oap.server.core.analysis.metrics.DataTable;
+import 
org.apache.skywalking.oap.server.core.analysis.metrics.LabeledValueHolder;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
+import org.apache.skywalking.oap.server.core.storage.StorageID;
+import org.apache.skywalking.oap.server.core.storage.annotation.BanyanDB;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+import org.apache.skywalking.oap.server.core.storage.annotation.ElasticSearch;
+import org.apache.skywalking.oap.server.core.storage.type.Convert2Entity;
+import org.apache.skywalking.oap.server.core.storage.type.Convert2Storage;
+import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder;
+
+@MeterFunction(functionName = "latestLabeled")
+@ToString
+public abstract class LatestLabeledFunction extends Meter implements 
AcceptableValue<DataTable>, LabeledValueHolder {
+
+    public static final String VALUE = "datatable_value";
+
+    @Setter
+    @Getter
+    @ElasticSearch.EnableDocValues
+    @Column(name = ENTITY_ID, length = 512)
+    @BanyanDB.SeriesID(index = 0)
+    private String entityId;
+
+    /**
+     * Service ID is required for sort query.
+     */
+    @Setter
+    @Getter
+    @Column(name = InstanceTraffic.SERVICE_ID)
+    private String serviceId;
+
+    @Getter
+    @Setter
+    @Column(name = VALUE, dataType = Column.ValueDataType.LABELED_VALUE, 
storageOnly = true)
+    @BanyanDB.MeasureField
+    private DataTable value = new DataTable(30);
+
+    @Override
+    public void accept(final MeterEntity entity, final DataTable value) {
+        setEntityId(entity.id());
+        setServiceId(entity.serviceId());
+        this.value = value;
+    }
+
+    @Override
+    public final boolean combine(Metrics metrics) {
+        final LatestLabeledFunction latestLabeledFunction = 
(LatestLabeledFunction) metrics;
+        this.value = latestLabeledFunction.getValue();
+        return true;
+    }
+
+    @Override
+    public final void calculate() {
+
+    }
+
+    @Override
+    public Metrics toHour() {
+        LatestLabeledFunction metrics = (LatestLabeledFunction) createNew();
+        metrics.setEntityId(getEntityId());
+        metrics.setTimeBucket(toTimeBucketInHour());
+        metrics.setServiceId(getServiceId());
+        metrics.getValue().copyFrom(getValue());
+        return metrics;
+    }
+
+    @Override
+    public Metrics toDay() {
+        LatestLabeledFunction metrics = (LatestLabeledFunction) createNew();
+        metrics.setEntityId(getEntityId());
+        metrics.setTimeBucket(toTimeBucketInDay());
+        metrics.setServiceId(getServiceId());
+        metrics.getValue().copyFrom(getValue());
+        return metrics;
+    }
+
+    @Override
+    protected StorageID id0() {
+        return new StorageID()
+                .append(TIME_BUCKET, getTimeBucket())
+                .append(ENTITY_ID, getEntityId());
+    }
+
+    @Override
+    public void deserialize(final RemoteData remoteData) {
+        setValue(new DataTable(remoteData.getDataObjectStrings(0)));
+        setTimeBucket(remoteData.getDataLongs(0));
+
+        setEntityId(remoteData.getDataStrings(0));
+        setServiceId(remoteData.getDataStrings(1));
+    }
+
+    @Override
+    public RemoteData.Builder serialize() {
+        final RemoteData.Builder remoteBuilder = RemoteData.newBuilder();
+        remoteBuilder.addDataObjectStrings(value.toStorageData());
+        remoteBuilder.addDataLongs(getTimeBucket());
+
+        remoteBuilder.addDataStrings(entityId);
+        remoteBuilder.addDataStrings(serviceId);
+
+        return remoteBuilder;
+    }
+
+    @Override
+    public int remoteHashCode() {
+        return entityId.hashCode();
+    }
+
+    @Override
+    public Class<? extends MaxLabeledStorageBuilder> builder() {
+        return MaxLabeledStorageBuilder.class;
+    }
+
+    public static class MaxLabeledStorageBuilder implements 
StorageBuilder<LatestLabeledFunction> {

Review Comment:
   The inner class name `MaxLabeledStorageBuilder` is incorrect for 
`LatestLabeledFunction`. Based on the naming convention used by other meter 
functions in the codebase (e.g., `LatestFunction` uses `LatestStorageBuilder`, 
`AvgLabeledFunction` uses `AvgLabeledStorageBuilder`), this should be named 
`LatestLabeledStorageBuilder` to match the parent class name.
   ```suggestion
       public Class<? extends LatestLabeledStorageBuilder> builder() {
           return LatestLabeledStorageBuilder.class;
       }
   
       public static class LatestLabeledStorageBuilder implements 
StorageBuilder<LatestLabeledFunction> {
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to