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

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


The following commit(s) were added to refs/heads/main by this push:
     new c2ed53a  Adding go service (#145)
c2ed53a is described below

commit c2ed53a750b18e363b3ee1fb08ac09b060ff228d
Author: mrproliu <741550...@qq.com>
AuthorDate: Mon Jul 24 22:07:12 2023 +0800

    Adding go service (#145)
---
 .github/workflows/publish-images.yaml              |  2 +-
 Makefile.in                                        |  1 +
 deploy/platform/docker/docker-compose.agent.yaml   | 16 +++++++
 deploy/platform/docker/docker-compose.cluster.yaml |  2 +-
 .../docker/docker-compose.single-node.yaml         |  2 +-
 .../templates/feature-agent/resources.yaml         | 46 +++++++++++++++++++
 docs/readme.md                                     |  1 +
 services/rating-service/Dockerfile                 | 28 ++++++++++++
 services/rating-service/Dockerfile.agentless       | 25 +++++++++++
 services/rating-service/Makefile                   | 34 ++++++++++++++
 services/rating-service/go.mod                     |  3 ++
 services/rating-service/go.sum                     |  0
 services/rating-service/main.go                    | 52 ++++++++++++++++++++++
 services/recommendation-service/src/app.py         | 20 +++++++--
 14 files changed, 226 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/publish-images.yaml 
b/.github/workflows/publish-images.yaml
index 30960a0..3e95c27 100644
--- a/.github/workflows/publish-images.yaml
+++ b/.github/workflows/publish-images.yaml
@@ -47,4 +47,4 @@ jobs:
           distribution: 'temurin'
           java-version: '8'
       - name: Build and push Docker image
-        run: make push -j 6 || make push -j 6
+        run: make push -j 7 || make push -j 7
diff --git a/Makefile.in b/Makefile.in
index b578d17..d86bbe5 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -37,6 +37,7 @@ SW_UI_IMAGE_TAG ?= e0068154c1253500720651dca5c80c3ae10ca87b
 SW_CLI_IMAGE ?= 
ghcr.io/apache/skywalking-cli/skywalking-cli:0883266bfaa36612927b69e35781b64ea181758d
 SW_EVENT_EXPORTER_IMAGE ?= 
ghcr.io/apache/skywalking-kubernetes-event-exporter/skywalking-kubernetes-event-exporter:8a012a3f968cb139f817189afb9b3748841bba22
 SW_AGENT_JAVA_IMAGE ?= 
ghcr.io/apache/skywalking-java/skywalking-java:81afeddd084d614c1cfcbcc7c24d0238e9aaab25-java8
+SW_AGENT_GO_IMAGE ?= 
ghcr.io/apache/skywalking-go/skywalking-go:637845b76c9949a495a14ecf0e7e2f0e385701c8-go1.18
 
 SW_AGENT_NODEJS_BACKEND_VERSION ?= 59ef1aed6a404e2e8afffbb4b81ea849ae4f3026
 SW_AGENT_NODEJS_FRONTEND_VERSION ?= 1e31bd17dcebb616163d848fc435f3a2d4822fb8
diff --git a/deploy/platform/docker/docker-compose.agent.yaml 
b/deploy/platform/docker/docker-compose.agent.yaml
index 43d2122..459526b 100644
--- a/deploy/platform/docker/docker-compose.agent.yaml
+++ b/deploy/platform/docker/docker-compose.agent.yaml
@@ -116,5 +116,21 @@ services:
       timeout: 10s
       retries: 3    
 
+  # Go agent
+  rating:
+    image: ${HUB}/rating-service:${TAG}
+    networks: [ sw ]
+    environment:
+      SW_AGENT_NAME: rating
+      SW_AGENT_REPORTER_GRPC_BACKEND_SERVICE: ${BACKEND_SERVICE}:11800
+    healthcheck:
+      test: [ "CMD-SHELL", "curl http://localhost/rating"; ]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+    depends_on:
+      oap:
+        condition: service_healthy
+
 networks:
   sw:
diff --git a/deploy/platform/docker/docker-compose.cluster.yaml 
b/deploy/platform/docker/docker-compose.cluster.yaml
index 856d83c..07b7f65 100644
--- a/deploy/platform/docker/docker-compose.cluster.yaml
+++ b/deploy/platform/docker/docker-compose.cluster.yaml
@@ -59,7 +59,7 @@ services:
       SW_TELEMETRY: prometheus # @feature: so11y; expose the metrics of self 
o11y through prometheus
       SW_PROMETHEUS_FETCHER: default # @feature: so11y; fetch the metrics of 
self o11y through prometheus
       JAVA_OPTS: "-Dmode=no-init -Xms2048m -Xmx2048m" # @feature: cluster; 
start the cluster nodes in no-init mode
-      SW_METER_ANALYZER_ACTIVE_FILES: 
datasource,threadpool,satellite,spring-sleuth
+      SW_METER_ANALYZER_ACTIVE_FILES: 
datasource,threadpool,satellite,spring-sleuth,go-runtime
     healthcheck:
       test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
       interval: 30s
diff --git a/deploy/platform/docker/docker-compose.single-node.yaml 
b/deploy/platform/docker/docker-compose.single-node.yaml
index 8ffc978..1aa6fc6 100644
--- a/deploy/platform/docker/docker-compose.single-node.yaml
+++ b/deploy/platform/docker/docker-compose.single-node.yaml
@@ -49,7 +49,7 @@ services:
       SW_TELEMETRY: prometheus # @feature: so11y; expose the metrics of self 
o11y through prometheus
       SW_PROMETHEUS_FETCHER: default # @feature: so11y; fetch the metrics of 
self o11y through prometheus
       JAVA_OPTS: "-Xms2048m -Xmx2048m"
-      SW_METER_ANALYZER_ACTIVE_FILES: 
datasource,threadpool,satellite,spring-sleuth
+      SW_METER_ANALYZER_ACTIVE_FILES: 
datasource,threadpool,satellite,spring-sleuth,go-runtime
     healthcheck:
       test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
       interval: 30s
diff --git a/deploy/platform/kubernetes/templates/feature-agent/resources.yaml 
b/deploy/platform/kubernetes/templates/feature-agent/resources.yaml
index 868891d..b6963c8 100644
--- a/deploy/platform/kubernetes/templates/feature-agent/resources.yaml
+++ b/deploy/platform/kubernetes/templates/feature-agent/resources.yaml
@@ -465,3 +465,49 @@ spec:
       targetPort: 61616
 
 {{- end }}
+
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: rating-deployment
+  namespace: {{ .Values.sampleServices.namespace }}
+  labels:
+    app: rating
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: rating
+  template:
+    metadata:
+      labels:
+        app: rating
+      annotations:
+        sidecar.istio.io/inject: "{{ or .Values.features.als.enabled 
.Values.features.istiodMonitor.enabled .Values.features.meshWithAgent }}"
+    spec:
+      containers:
+        - name: rating
+          image: "{{ .Values.sampleServices.hub }}/rating-service:{{ 
.Values.sampleServices.tag }}"
+          imagePullPolicy: IfNotPresent
+          ports:
+            - containerPort: 80
+          env:
+            - name: SW_AGENT_NAME
+              value: agent::rating
+            - name: SW_AGENT_REPORTER_GRPC_BACKEND_SERVICE
+              value: {{ template "skywalking.collector.address" . }}
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: rating
+  namespace: {{ .Values.sampleServices.namespace }}
+spec:
+  selector:
+    app: rating
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 80
\ No newline at end of file
diff --git a/docs/readme.md b/docs/readme.md
index 07aeb24..948422f 100644
--- a/docs/readme.md
+++ b/docs/readme.md
@@ -13,6 +13,7 @@ graph LR;
  --> app("app server (NodeJS)") --> gateway("gateway (Spring)");
   ui("UI (React)") --> Traffic2("HTTP Request for UI codes") --> 
apisix("APISIX with  UI container")
   gateway --> songs("songs (Spring)") & rcmd("recommendations (Python)");
+  rcmd --> rating("rating (Go)");
   songs --> activeMQ
   activeMQ --> songs
   rcmd --> songs;
diff --git a/services/rating-service/Dockerfile 
b/services/rating-service/Dockerfile
new file mode 100644
index 0000000..f4dcbb1
--- /dev/null
+++ b/services/rating-service/Dockerfile
@@ -0,0 +1,28 @@
+# 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.
+#
+
+ARG SW_AGENT_GO_IMAGE
+FROM ${SW_AGENT_GO_IMAGE}
+
+WORKDIR /workspace
+
+COPY . .
+
+RUN skywalking-go-agent -inject ./ && go build -o rating -a -toolexec 
"skywalking-go-agent"
+
+CMD ["./rating"]
diff --git a/services/rating-service/Dockerfile.agentless 
b/services/rating-service/Dockerfile.agentless
new file mode 100644
index 0000000..f0ff661
--- /dev/null
+++ b/services/rating-service/Dockerfile.agentless
@@ -0,0 +1,25 @@
+# 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.
+#
+
+FROM golang:1.18
+
+WORKDIR /workspace
+
+COPY . .
+
+CMD go build . -o rating && ./rating
diff --git a/services/rating-service/Makefile b/services/rating-service/Makefile
new file mode 100644
index 0000000..1d0963c
--- /dev/null
+++ b/services/rating-service/Makefile
@@ -0,0 +1,34 @@
+# 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.
+#
+
+include ../../Makefile.in
+
+.PHONY: build
+build:
+
+.PHONY: docker docker.build docker.push
+
+docker: docker.build
+
+docker.build:
+       docker build --build-arg SW_AGENT_GO_IMAGE=${SW_AGENT_GO_IMAGE} . -t 
$(HUB)/rating-service:$(TAG)
+       docker build . -t $(HUB)/rating-service:$(TAG)-agentless -f 
Dockerfile.agentless
+
+docker.push: docker.build
+       docker push $(HUB)/rating-service:$(TAG)
+       docker push $(HUB)/rating-service:$(TAG)-agentless
diff --git a/services/rating-service/go.mod b/services/rating-service/go.mod
new file mode 100644
index 0000000..cb814bb
--- /dev/null
+++ b/services/rating-service/go.mod
@@ -0,0 +1,3 @@
+module rating
+
+go 1.18
diff --git a/services/rating-service/go.sum b/services/rating-service/go.sum
new file mode 100644
index 0000000..e69de29
diff --git a/services/rating-service/main.go b/services/rating-service/main.go
new file mode 100644
index 0000000..b3e72bf
--- /dev/null
+++ b/services/rating-service/main.go
@@ -0,0 +1,52 @@
+// Licensed to 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. Apache Software Foundation (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 main
+
+import (
+       "encoding/json"
+       "log"
+       "net/http"
+)
+
+type SongRating struct {
+       ID     int     `json:"id"`
+       Rating float64 `json:"rating"`
+}
+
+var data = []*SongRating{
+       {1, 7.99},
+       {2, 8.99},
+       {3, 9.99},
+       {4, 9.99},
+}
+
+func main() {
+       http.HandleFunc("/rating", func(writer http.ResponseWriter, request 
*http.Request) {
+               marshal, err := json.Marshal(data)
+               if err != nil {
+                       log.Printf("format data error: %v", err)
+                       writer.Write([]byte("[]"))
+                       return
+               }
+               writer.Write(marshal)
+       })
+
+       if err := http.ListenAndServe(":80", nil); err != nil {
+               log.Fatalf("rating service start error: %v \n", err)
+       }
+}
diff --git a/services/recommendation-service/src/app.py 
b/services/recommendation-service/src/app.py
index 9c12180..f43df06 100644
--- a/services/recommendation-service/src/app.py
+++ b/services/recommendation-service/src/app.py
@@ -43,9 +43,23 @@ if __name__ == '__main__':
             if val is not None:
                 headers[key] = request.headers[key]
 
-        r = requests.get('http://songs/songs', headers=headers)
-        recommendations = r.json()
-        return jsonify(recommendations)
+        songsResponse = requests.get('http://songs/songs', headers=headers)
+        songs = songsResponse.json()
+        ratingResponse = requests.get('http://rating/rating', headers=headers)
+        ratings = ratingResponse.json()
+
+        # combine ratings to songs
+        ratings_dict = {}
+        for rating_data in ratings:
+            song_id = rating_data['id']
+            ratings_dict[song_id] = rating_data['rating']
+        for song_data in songs:
+            song_id = song_data['id']
+            rating = ratings_dict.get(song_id)
+            if rating is not None:
+                song_data['rating'] = rating
+
+        return jsonify(songs)
 
 
     PORT = os.getenv('PORT', 80)

Reply via email to