Skip to content

Commit

Permalink
Merge pull request #21 from honeycombio/robb.tweaks-in-service-to-con…
Browse files Browse the repository at this point in the history
…tainerization

tweaks in service to containerization
  • Loading branch information
robbkidd authored Jul 8, 2021
2 parents 7ce8f8d + 9044048 commit 7f30bd1
Show file tree
Hide file tree
Showing 14 changed files with 387 additions and 355 deletions.
12 changes: 7 additions & 5 deletions golang/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ import (
"github.com/honeycombio/opentelemetry-exporter-go/honeycomb"
)

const (
nameServiceUrl = "http://localhost:8000/name"
messageServiceUrl = "http://localhost:9000/message"
var (
apiKey = os.Getenv("HONEYCOMB_API_KEY")
dataset = os.Getenv("HONEYCOMB_DATASET")
nameServiceUrl = os.Getenv("NAME_ENDPOINT") + "/name"
messageServiceUrl = os.Getenv("MESSAGE_ENDPOINT") + "/message"
)

func main() {
exp, err := honeycomb.NewExporter(
honeycomb.Config{
APIKey: os.Getenv("HONEYCOMB_API_KEY"),
APIKey: apiKey,
},
honeycomb.TargetingDataset(os.Getenv("HONEYCOMB_DATASET")),
honeycomb.TargetingDataset(dataset),
honeycomb.WithServiceName("frontend-go"),
)
if err != nil {
Expand Down
12 changes: 9 additions & 3 deletions golang/name-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ import (
"go.opentelemetry.io/otel/instrumentation/httptrace"
)

var (
apiKey = os.Getenv("HONEYCOMB_API_KEY")
dataset = os.Getenv("HONEYCOMB_DATASET")
yearServiceUrl = os.Getenv("YEAR_ENDPOINT") + "/year"
)

func main() {
beeline.Init(beeline.Config{
WriteKey: os.Getenv("HONEYCOMB_API_KEY"),
Dataset: os.Getenv("HONEYCOMB_DATASET"),
WriteKey: apiKey,
Dataset: dataset,
ServiceName: "name-go",
})
defer beeline.Close()
Expand Down Expand Up @@ -72,7 +78,7 @@ func propagateTraceHook(r *http.Request, prop *propagation.PropagationContext) m
func getYear(ctx context.Context) (int, context.Context) {
ctx, span := beeline.StartSpan(ctx, "✨ call /year ✨")
defer span.Send()
req, _ := http.NewRequest("GET", "http://localhost:6001/year", nil)
req, _ := http.NewRequest("GET", yearServiceUrl, nil)
ctx, req = httptrace.W3C(ctx, req)
httptrace.Inject(ctx, req)
client := &http.Client{
Expand Down
9 changes: 6 additions & 3 deletions python/frontend/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
__version__ = '0.1.0'

import os

from werkzeug.routing import Map, Rule
from werkzeug.wrappers import Request, Response
from http.client import HTTPException
Expand All @@ -9,7 +11,8 @@


class Greeting(object):

NAME_ENDPOINT = os.environ.get('NAME_ENDPOINT', 'http://localhost:8000') + '/name'
MESSAGE_ENDPOINT = os.environ.get('MESSAGE_ENDPOINT', 'http://localhost:9000') + '/message'
def __init__(self):
self.url_map = Map([
Rule('/greeting', endpoint='greeting'),
Expand All @@ -29,11 +32,11 @@ def dispatch_request(self, request):
return e

def get_name(self):
with urllib.request.urlopen('http://localhost:8000/name') as f:
with urllib.request.urlopen(self.NAME_ENDPOINT) as f:
return f.read().decode('utf-8')

def get_message(self):
with urllib.request.urlopen('http://localhost:9000/message') as f:
with urllib.request.urlopen(self.MESSAGE_ENDPOINT) as f:
return f.read().decode('utf-8')

def wsgi_app(self, environ, start_response):
Expand Down
2 changes: 1 addition & 1 deletion python/frontend/frontend/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@


app = HoneyWSGIMiddleware(create_app())
run_simple('127.0.0.1', 7000, app, use_debugger=True, use_reloader=True)
run_simple('0.0.0.0', 7000, app, use_debugger=True, use_reloader=True)
2 changes: 1 addition & 1 deletion python/message-service/message_service/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def message():

app = HoneyWSGIMiddleware(app)

run(app=app, host='127.0.0.1', port=9000)
run(app=app, host='0.0.0.0', port=9000)
3 changes: 2 additions & 1 deletion python/name-service/name_service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
2020: ['olivia', 'noah', 'emma', 'liam', 'ava', 'elijah', 'isabella', 'oliver', 'sophia', 'lucas']
}

YEAR_ENDPOINT = os.environ.get('YEAR_ENDPOINT', 'http://localhost:6001') + '/year'

@beeline.traced(name="✨ call /year ✨")
def get_year():
r = requests.get('http://localhost:6001/year')
r = requests.get(YEAR_ENDPOINT)
return int(r.text)


Expand Down
Loading

0 comments on commit 7f30bd1

Please sign in to comment.