wu-sheng commented on a change in pull request #6183:
URL: https://github.com/apache/skywalking/pull/6183#discussion_r570632299



##########
File path: 
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/event/Event.java
##########
@@ -0,0 +1,231 @@
+/*
+ * 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.event;
+
+import java.util.HashMap;
+import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.skywalking.apm.util.StringUtil;
+import org.apache.skywalking.oap.server.core.analysis.MetricsExtension;
+import org.apache.skywalking.oap.server.core.analysis.Stream;
+import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import 
org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
+import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
+import org.apache.skywalking.oap.server.core.source.ScopeDeclaration;
+import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+
+import static 
org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.EVENT;
+
+@Getter
+@Setter
+@ScopeDeclaration(id = EVENT, name = "Event")
+@Stream(name = Event.INDEX_NAME, scopeId = EVENT, builder = 
Event.Builder.class, processor = MetricsStreamProcessor.class)
+@EqualsAndHashCode(
+    callSuper = false,
+    of = "uuid"
+)
+@MetricsExtension(supportDownSampling = false, supportUpdate = true)
+public class Event extends Metrics {
+
+    public static final String INDEX_NAME = "events";
+
+    public static final String UUID = "uuid";
+
+    public static final String SERVICE = "service";
+
+    public static final String SERVICE_INSTANCE = "service_instance";
+
+    public static final String ENDPOINT = "endpoint";
+
+    public static final String NAME = "name";
+
+    public static final String TYPE = "type";
+
+    public static final String MESSAGE = "message";
+
+    public static final String PARAMETERS = "parameters";
+
+    public static final String START_TIME = "start_time";
+
+    public static final String END_TIME = "end_time";
+
+    @Override
+    public String id() {
+        return getUuid();
+    }
+
+    @Column(columnName = UUID)
+    private String uuid;
+
+    @Column(columnName = SERVICE)
+    private String service;
+
+    @Column(columnName = SERVICE_INSTANCE)
+    private String serviceInstance;
+
+    @Column(columnName = ENDPOINT)
+    private String endpoint;
+
+    @Column(columnName = NAME)
+    private String name;
+
+    @Column(columnName = TYPE)
+    private String type;
+
+    @Column(columnName = MESSAGE)
+    private String message;
+
+    @Column(columnName = PARAMETERS, storageOnly = true)
+    private String parameters;
+
+    @Column(columnName = START_TIME)
+    private long startTime;
+
+    @Column(columnName = END_TIME)
+    private long endTime;
+
+    @Override
+    public boolean combine(final Metrics metrics) {
+        final Event event = (Event) metrics;
+
+        // Set time bucket only when it's never set.
+        if (getTimeBucket() <= 0) {
+            if (event.getStartTime() > 0) {
+                
setTimeBucket(TimeBucket.getMinuteTimeBucket(event.getStartTime()));
+            } else if (event.getEndTime() > 0) {
+                
setTimeBucket(TimeBucket.getMinuteTimeBucket(event.getEndTime()));
+            }
+        }
+
+        // Set start time only when it's never set, (`start` event may come 
after `end` event).
+        if (getStartTime() <= 0 && event.getStartTime() > 0) {
+            setStartTime(event.getStartTime());
+        }
+
+        if (event.getEndTime() > 0) {
+            setEndTime(event.getEndTime());
+        }
+
+        if (StringUtil.isNotBlank(event.getType())) {
+            setType(event.getType());
+        }
+        if (StringUtil.isNotBlank(event.getMessage())) {
+            setType(event.getMessage());
+        }
+        if (StringUtil.isNotBlank(event.getParameters())) {
+            setParameters(event.getParameters());
+        }
+        return true;

Review comment:
       So, we still always return `true`, right? timebucket will be there 
always.

##########
File path: 
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/event/Event.java
##########
@@ -0,0 +1,231 @@
+/*
+ * 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.event;
+
+import java.util.HashMap;
+import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.skywalking.apm.util.StringUtil;
+import org.apache.skywalking.oap.server.core.analysis.MetricsExtension;
+import org.apache.skywalking.oap.server.core.analysis.Stream;
+import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import 
org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
+import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
+import org.apache.skywalking.oap.server.core.source.ScopeDeclaration;
+import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+
+import static 
org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.EVENT;
+
+@Getter
+@Setter
+@ScopeDeclaration(id = EVENT, name = "Event")
+@Stream(name = Event.INDEX_NAME, scopeId = EVENT, builder = 
Event.Builder.class, processor = MetricsStreamProcessor.class)
+@EqualsAndHashCode(
+    callSuper = false,
+    of = "uuid"
+)
+@MetricsExtension(supportDownSampling = false, supportUpdate = true)
+public class Event extends Metrics {
+
+    public static final String INDEX_NAME = "events";
+
+    public static final String UUID = "uuid";
+
+    public static final String SERVICE = "service";
+
+    public static final String SERVICE_INSTANCE = "service_instance";
+
+    public static final String ENDPOINT = "endpoint";
+
+    public static final String NAME = "name";
+
+    public static final String TYPE = "type";
+
+    public static final String MESSAGE = "message";
+
+    public static final String PARAMETERS = "parameters";
+
+    public static final String START_TIME = "start_time";
+
+    public static final String END_TIME = "end_time";
+
+    @Override
+    public String id() {
+        return getUuid();
+    }
+
+    @Column(columnName = UUID)
+    private String uuid;
+
+    @Column(columnName = SERVICE)
+    private String service;
+
+    @Column(columnName = SERVICE_INSTANCE)
+    private String serviceInstance;
+
+    @Column(columnName = ENDPOINT)
+    private String endpoint;
+
+    @Column(columnName = NAME)
+    private String name;
+
+    @Column(columnName = TYPE)
+    private String type;
+
+    @Column(columnName = MESSAGE)
+    private String message;
+
+    @Column(columnName = PARAMETERS, storageOnly = true)
+    private String parameters;
+
+    @Column(columnName = START_TIME)
+    private long startTime;
+
+    @Column(columnName = END_TIME)
+    private long endTime;
+
+    @Override
+    public boolean combine(final Metrics metrics) {

Review comment:
       Let's update this protocol doc a little to map this logic, 
https://github.com/apache/skywalking-query-protocol/blob/master/event.graphqls#L26-L29

##########
File path: 
oap-server/analyzer/event-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/event/listener/EventRecordAnalyzerListener.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.analyzer.event.listener;
+
+import com.google.gson.Gson;
+import lombok.RequiredArgsConstructor;
+import org.apache.skywalking.apm.network.event.v3.Source;
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
+import 
org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
+import org.apache.skywalking.oap.server.core.config.NamingControl;
+import org.apache.skywalking.oap.server.core.event.Event;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+
+/**
+ * EventRecordAnalyzerListener forwards the event data to the persistence 
layer with the query required conditions.
+ */
+@RequiredArgsConstructor
+public class EventRecordAnalyzerListener implements EventAnalyzerListener {
+    private static final Gson GSON = new Gson();
+
+    private final NamingControl namingControl;
+
+    private final Event event = new Event();
+
+    @Override
+    public void build() {
+        MetricsStreamProcessor.getInstance().in(event);
+    }
+
+    @Override
+    public void parse(final org.apache.skywalking.apm.network.event.v3.Event 
e) {
+        event.setUuid(e.getUuid());
+
+        if (e.hasSource()) {
+            final Source source = e.getSource();
+            
event.setService(namingControl.formatServiceName(source.getService()));
+            
event.setServiceInstance(namingControl.formatInstanceName(source.getServiceInstance()));
+            
event.setEndpoint(namingControl.formatEndpointName(source.getService(), 
source.getEndpoint()));
+        }
+
+        event.setName(e.getName());
+        event.setType(e.getType().name());
+        event.setMessage(e.getMessage());
+        if (e.getParametersCount() > 0) {
+            event.setParameters(GSON.toJson(e.getParametersMap()));
+        }
+        event.setStartTime(e.getStartTime());
+        event.setEndTime(e.getEndTime());
+        event.setTimeBucket(TimeBucket.getMinuteTimeBucket(e.getStartTime()));

Review comment:
       I think you need some start time / end time / bucket check logic here. 
If this event(same UUID) reports at the first time, and only once, the 
`combine` wouldn't execute.

##########
File path: 
oap-server/analyzer/event-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/event/listener/EventRecordAnalyzerListener.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.analyzer.event.listener;
+
+import com.google.gson.Gson;
+import lombok.RequiredArgsConstructor;
+import org.apache.skywalking.apm.network.event.v3.Source;
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
+import 
org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor;
+import org.apache.skywalking.oap.server.core.config.NamingControl;
+import org.apache.skywalking.oap.server.core.event.Event;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+
+/**
+ * EventRecordAnalyzerListener forwards the event data to the persistence 
layer with the query required conditions.
+ */
+@RequiredArgsConstructor
+public class EventRecordAnalyzerListener implements EventAnalyzerListener {
+    private static final Gson GSON = new Gson();
+
+    private final NamingControl namingControl;
+
+    private final Event event = new Event();
+
+    @Override
+    public void build() {
+        MetricsStreamProcessor.getInstance().in(event);
+    }
+
+    @Override
+    public void parse(final org.apache.skywalking.apm.network.event.v3.Event 
e) {
+        event.setUuid(e.getUuid());
+
+        if (e.hasSource()) {
+            final Source source = e.getSource();
+            
event.setService(namingControl.formatServiceName(source.getService()));
+            
event.setServiceInstance(namingControl.formatInstanceName(source.getServiceInstance()));
+            
event.setEndpoint(namingControl.formatEndpointName(source.getService(), 
source.getEndpoint()));
+        }
+
+        event.setName(e.getName());
+        event.setType(e.getType().name());
+        event.setMessage(e.getMessage());
+        if (e.getParametersCount() > 0) {
+            event.setParameters(GSON.toJson(e.getParametersMap()));
+        }
+        event.setStartTime(e.getStartTime());
+        event.setEndTime(e.getEndTime());
+        if (e.getStartTime() > 0) {
+            
event.setTimeBucket(TimeBucket.getMinuteTimeBucket(e.getStartTime()));
+        } else if (e.getEndTime() > 0) {
+            
event.setTimeBucket(TimeBucket.getMinuteTimeBucket(e.getEndTime()));
+        }

Review comment:
       With all of our long discussion about start time and end time, we may 
need to set up a set of validators to check the trace/metric/log/event data if 
some necessary fields are illegal or NULL.
   
   Just FYI. If you agree, we could add a new issue to track this.




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


Reply via email to