Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweaks in service to containerization #21

Merged
merged 8 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these have defaults set somewhere (a la the Python code)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nnnnno. You're right; they should get some!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to update this has turned into a yak shave and I don't know why.

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