Skip to content

Commit

Permalink
Adding go service (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Jul 24, 2023
1 parent e56df1c commit c2ed53a
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions deploy/platform/docker/docker-compose.agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
2 changes: 1 addition & 1 deletion deploy/platform/docker/docker-compose.cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deploy/platform/docker/docker-compose.single-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions deploy/platform/kubernetes/templates/feature-agent/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions services/rating-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
25 changes: 25 additions & 0 deletions services/rating-service/Dockerfile.agentless
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions services/rating-service/Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions services/rating-service/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module rating

go 1.18
Empty file added services/rating-service/go.sum
Empty file.
52 changes: 52 additions & 0 deletions services/rating-service/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
20 changes: 17 additions & 3 deletions services/recommendation-service/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,23 @@ def application():
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)
Expand Down

0 comments on commit c2ed53a

Please sign in to comment.