Skip to content

Commit

Permalink
feat: run simulator with redis backend (#1016)
Browse files Browse the repository at this point in the history
<!--
Thank you for contributing to the project! 💜
Please make sure to:
- Chat with us first if this is a big change
  - Open a new issue (or comment on an existing one)
- We want to make sure you don't spend time implementing something we
might have to say No to
- Add unit tests
- Mention any relevant issues in the PR description (e.g. "Fixes #123")

Please see our [OSS process
document](https://github.com/honeycombio/home/blob/main/honeycomb-oss-lifecycle-and-practices.md#)
to get an idea of how we operate.
-->

## Which problem is this PR solving?

This PR enables the simulator to be able to run with a redis backend 

## Short description of the changes

- added opts.HnyEndpoint to enable sending traces to other honeycomb
environments
- redis returns the status field as `float64`. Handle that scenario in
the decider logic.
  • Loading branch information
VinozzZ authored and kentquirk committed Mar 15, 2024
1 parent c1bf0fe commit 8f094ff
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
34 changes: 28 additions & 6 deletions cmd/test_stores/fake_refinery.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,35 @@ func (fri *FakeRefineryInstance) runDecider(opts CmdLineOptions, nodeIndex int,
// * traces with POST spans having status >= 400 && <= 403
keep := false
for _, span := range trace.Spans {
if span.KeyFields["status"].(int) >= 500 {
keep = true
break
operationField, ok := span.KeyFields["operation"]
if !ok {
addException(span3, fmt.Errorf("missing operation field in span"))
continue
}
if span.KeyFields["status"].(int) >= 400 && span.KeyFields["status"].(int) <= 403 && span.KeyFields["operation"].(string) == "POST" {
keep = true
break
operationValue := operationField.(string)
statusField := span.KeyFields["status"]
switch value := statusField.(type) {
case int:
if value >= 500 {
keep = true
break
}
if value >= 400 && value <= 403 && operationValue == "POST" {
keep = true
break
}
case float64:
if value >= 500 {
keep = true
break
}
if value >= 400 && value <= 403 && operationValue == "POST" {
keep = true
break
}

default:
addException(span3, fmt.Errorf("unexpected type for status field: %T", value))
}
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/test_stores/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ func makeRemoteStore(storeType string) centralstore.BasicStorer {
case "local":
return centralstore.NewLocalRemoteStore()
case "redis":
return centralstore.NewRedisBasicStore(&centralstore.RedisBasicStoreOptions{
Host: "localhost:6379",
})
return centralstore.NewRedisBasicStore(&centralstore.RedisBasicStoreOptions{})
default:
panic("unknown store type " + storeType)
}
Expand All @@ -111,6 +109,7 @@ type CmdLineOptions struct {
NodeIndex int `long:"node-number" description:"Index of this node if Total > 1" default:"0"`
DecisionReqSize int `long:"decision-req-size" description:"Number of traces to request for decision" default:"10"`
HnyAPIKey string `long:"hny-api-key" description:"API key for traces in Honeycomb" default:"" env:"HONEYCOMB_API_KEY"`
HnyEndpoint string `long:"hny-endpoint" description:"Endpoint for traces in Honeycomb" default:"https://api.honeycomb.io" env:"HONEYCOMB_ENDPOINT"`
HnyDataset string `long:"hny-dataset" description:"Dataset/service name for traces in Honeycomb" default:"refinery-store-test" env:"HONEYCOMB_DATASET"`
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/test_stores/otel_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"strings"
"time"

"github.com/honeycombio/otel-config-go/otelconfig"
Expand Down Expand Up @@ -61,10 +62,13 @@ func setupTracing(opts CmdLineOptions) (tracer trace.Tracer, shutdown func()) {
if opts.HnyAPIKey != "" {
var protocol otelconfig.Protocol = otelconfig.ProtocolHTTPProto

opts.HnyEndpoint = strings.TrimSuffix(opts.HnyEndpoint, "/")
endpoint := fmt.Sprintf("%s:443", opts.HnyEndpoint)

otelshutdown, err := otelconfig.ConfigureOpenTelemetry(
otelconfig.WithExporterProtocol(protocol),
otelconfig.WithServiceName(opts.HnyDataset),
otelconfig.WithTracesExporterEndpoint("https://api-dogfood.honeycomb.io:443"),
otelconfig.WithTracesExporterEndpoint(endpoint),
otelconfig.WithMetricsEnabled(false),
otelconfig.WithTracesEnabled(true),
otelconfig.WithHeaders(map[string]string{
Expand Down

0 comments on commit 8f094ff

Please sign in to comment.