You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/04/03 22:43:36 UTC

[incubator-skywalking] branch log updated: Finish a new metric, log(abstract) with HTTP Access Log.

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch log
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git


The following commit(s) were added to refs/heads/log by this push:
     new 1da0c36  Finish a new metric, log(abstract) with HTTP Access Log.
1da0c36 is described below

commit 1da0c362c6e0aac2973f3ac1bb56a89ad88d6c73
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Wed Apr 3 15:43:23 2019 -0700

    Finish a new metric, log(abstract) with HTTP Access Log.
---
 .../analysis/manual/log/AbstractLogRecord.java     | 79 ++++++++++++++++++++++
 .../manual/log/HTTPAccessLogDispatcher.java        | 41 +++++++++++
 .../analysis/manual/log/HTTPAccessLogRecord.java   | 38 +++++++++++
 .../oap/server/core/query/entity/ContentType.java  | 27 +++++++-
 .../ContentType.java => source/AbstractLog.java}   | 26 +++++--
 .../oap/server/core/source/DefaultScopeDefine.java |  1 +
 .../ContentType.java => source/HTTPAccessLog.java} | 11 ++-
 7 files changed, 213 insertions(+), 10 deletions(-)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/AbstractLogRecord.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/AbstractLogRecord.java
new file mode 100644
index 0000000..6e29f82
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/AbstractLogRecord.java
@@ -0,0 +1,79 @@
+/*
+ * 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.manual.log;
+
+import java.util.*;
+import lombok.*;
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+import org.apache.skywalking.oap.server.core.analysis.record.Record;
+import org.apache.skywalking.oap.server.core.query.entity.ContentType;
+import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+
+/**
+ * @author wusheng
+ */
+
+public abstract class AbstractLogRecord extends Record {
+
+    public static final String SERVICE_ID = "service_id";
+    public static final String SERVICE_INSTANCE_ID = "service_instance_id";
+    public static final String ENDPOINT_ID = "endpoint_id";
+    public static final String IS_ERROR = "is_error";
+    public static final String STATUS_CODE = "status_code";
+    public static final String CONTENT_TYPE = "content_type";
+    public static final String CONTENT = "content";
+
+    @Setter @Getter @Column(columnName = SERVICE_ID) private int serviceId;
+    @Setter @Getter @Column(columnName = SERVICE_INSTANCE_ID) private int serviceInstanceId;
+    @Setter @Getter @Column(columnName = ENDPOINT_ID) private int endpointId;
+    @Setter @Getter @Column(columnName = IS_ERROR) private int isError;
+    @Setter @Getter @Column(columnName = STATUS_CODE) private String statusCode;
+    @Setter @Getter @Column(columnName = CONTENT_TYPE) private int contentType = ContentType.NONE.value();
+    @Setter @Getter @Column(columnName = CONTENT) private String content;
+
+    @Override public String id() {
+        throw new UnexpectedException("AbstractLogRecord doesn't provide id()");
+    }
+
+    public static abstract class Builder<T extends AbstractLogRecord> implements StorageBuilder<T> {
+        protected void map2Data(T record, Map<String, Object> dbMap) {
+            record.setServiceId(((Number)dbMap.get(SERVICE_ID)).intValue());
+            record.setServiceInstanceId(((Number)dbMap.get(SERVICE_INSTANCE_ID)).intValue());
+            record.setEndpointId(((Number)dbMap.get(ENDPOINT_ID)).intValue());
+            record.setIsError(((Number)dbMap.get(IS_ERROR)).intValue());
+            record.setStatusCode((String)dbMap.get(STATUS_CODE));
+            record.setIsError(((Number)dbMap.get(CONTENT_TYPE)).intValue());
+            record.setStatusCode((String)dbMap.get(CONTENT));
+        }
+
+        @Override public Map<String, Object> data2Map(AbstractLogRecord record) {
+            Map<String, Object> map = new HashMap<>();
+            map.put(SERVICE_ID, record.getServiceId());
+            map.put(SERVICE_INSTANCE_ID, record.getServiceInstanceId());
+            map.put(ENDPOINT_ID, record.getEndpointId());
+            map.put(IS_ERROR, record.getIsError());
+            map.put(STATUS_CODE, record.getStatusCode());
+            map.put(TIME_BUCKET, record.getTimeBucket());
+            map.put(CONTENT_TYPE, record.getContentType());
+            map.put(CONTENT, record.getContent());
+            return map;
+        }
+    }
+}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/HTTPAccessLogDispatcher.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/HTTPAccessLogDispatcher.java
new file mode 100644
index 0000000..58e53b9
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/HTTPAccessLogDispatcher.java
@@ -0,0 +1,41 @@
+/*
+ * 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.manual.log;
+
+import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
+import org.apache.skywalking.oap.server.core.analysis.worker.RecordProcess;
+import org.apache.skywalking.oap.server.core.source.HTTPAccessLog;
+
+/**
+ * @author wusheng
+ */
+public class HTTPAccessLogDispatcher implements SourceDispatcher<HTTPAccessLog> {
+    @Override public void dispatch(HTTPAccessLog source) {
+        HTTPAccessLogRecord record = new HTTPAccessLogRecord();
+        record.setServiceId(source.getServiceId());
+        record.setServiceInstanceId(source.getServiceInstanceId());
+        record.setEndpointId(source.getEndpointId());
+        record.setIsError(source.getIsError());
+        record.setStatusCode(source.getStatusCode());
+        record.setContentType(source.getContentType().value());
+        record.setContent(source.getContent());
+
+        RecordProcess.INSTANCE.in(record);
+    }
+}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/HTTPAccessLogRecord.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/HTTPAccessLogRecord.java
new file mode 100644
index 0000000..af29461
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/log/HTTPAccessLogRecord.java
@@ -0,0 +1,38 @@
+/*
+ * 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.manual.log;
+
+import java.util.Map;
+import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
+import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntity;
+
+import static org.apache.skywalking.oap.server.core.analysis.manual.log.HTTPAccessLogRecord.INDEX_NAME;
+
+@StorageEntity(name = INDEX_NAME, builder = HTTPAccessLogRecord.Builder.class, sourceScopeId = DefaultScopeDefine.HTTP_ACCESS_LOG)
+public class HTTPAccessLogRecord extends AbstractLogRecord {
+    public static final String INDEX_NAME = "http_access_log";
+
+    public static class Builder extends AbstractLogRecord.Builder<HTTPAccessLogRecord> {
+        @Override public HTTPAccessLogRecord map2Data(Map<String, Object> dbMap) {
+            HTTPAccessLogRecord record = new HTTPAccessLogRecord();
+            super.map2Data(record, dbMap);
+            return record;
+        }
+    }
+}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java
index 983e547..68db82b 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java
@@ -18,9 +18,34 @@
 
 package org.apache.skywalking.oap.server.core.query.entity;
 
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+
 /**
  * @author wusheng
  */
 public enum ContentType {
-    TEXT, JSON, NONE
+    TEXT(1), JSON(2), NONE(0);
+
+    private int value;
+
+    ContentType(int value) {
+        this.value = value;
+    }
+
+    public int value() {
+        return value;
+    }
+
+    public static ContentType instanceOf(int value) {
+        switch (value) {
+            case 1:
+                return TEXT;
+            case 2:
+                return JSON;
+            case 0:
+                return NONE;
+            default:
+                throw new UnexpectedException("unexpected value=" + value);
+        }
+    }
 }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/AbstractLog.java
similarity index 55%
copy from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java
copy to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/AbstractLog.java
index 983e547..f73fca7 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/AbstractLog.java
@@ -16,11 +16,25 @@
  *
  */
 
-package org.apache.skywalking.oap.server.core.query.entity;
+package org.apache.skywalking.oap.server.core.source;
 
-/**
- * @author wusheng
- */
-public enum ContentType {
-    TEXT, JSON, NONE
+import lombok.*;
+import org.apache.skywalking.oap.server.core.UnexpectedException;
+import org.apache.skywalking.oap.server.core.query.entity.ContentType;
+
+@Setter
+@Getter
+public abstract class AbstractLog extends Source {
+
+    private int serviceId;
+    private int serviceInstanceId;
+    private int endpointId;
+    private int isError;
+    private String statusCode;
+    private ContentType contentType = ContentType.NONE;
+    private String content;
+
+    @Override public String getEntityId() {
+        throw new UnexpectedException("getEntityId is not supported in AbstractLog source");
+    }
 }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java
index b9c3239..4508868 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java
@@ -61,6 +61,7 @@ public class DefaultScopeDefine {
     public static final int ENVOY_INSTANCE_METRIC = 22;
     public static final int ZIPKIN_SPAN = 23;
     public static final int JAEGER_SPAN = 24;
+    public static final int HTTP_ACCESS_LOG = 25;
 
     /**
      * Catalog of scope, the indicator processor could use this to group all generated indicators by oal tool.
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/HTTPAccessLog.java
similarity index 71%
copy from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java
copy to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/HTTPAccessLog.java
index 983e547..3d163b4 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/ContentType.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/HTTPAccessLog.java
@@ -16,11 +16,16 @@
  *
  */
 
-package org.apache.skywalking.oap.server.core.query.entity;
+package org.apache.skywalking.oap.server.core.source;
+
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.HTTP_ACCESS_LOG;
 
 /**
  * @author wusheng
  */
-public enum ContentType {
-    TEXT, JSON, NONE
+@ScopeDeclaration(id = HTTP_ACCESS_LOG, name = "HTTPAccessLog")
+public class HTTPAccessLog extends AbstractLog {
+    @Override public int scope() {
+        return HTTP_ACCESS_LOG;
+    }
 }