Skip to content

Commit

Permalink
chore(ui, api): adding Kafka example to Pokeshop demo (#3086)
Browse files Browse the repository at this point in the history
* wip adding kafkabroker field to the server

* Update OpenAPI specs

* Fix wrong attribute name for demo on server

* Fixing demo attribute mapping on UI

* Updating installer scripts to consider Kafka on Pokeshop
  • Loading branch information
danielbdias committed Aug 21, 2023
1 parent 88d3e9a commit 847caca
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 18 deletions.
3 changes: 3 additions & 0 deletions api/config.yaml
Expand Up @@ -133,6 +133,9 @@ components:
grpcEndpoint:
type: string
description: "gRPC endpoint for Pokeshop API"
kafkaBroker:
type: string
description: "kafka broker for Pokeshop API"
DemoOpenTelemetryStore:
type: object
description: "Represents the settings of the Open Telemetry Store demonstration."
Expand Down
3 changes: 2 additions & 1 deletion cli/installer/templates/provision.yaml.tpl
Expand Up @@ -50,7 +50,8 @@ spec:
enabled: true
pokeshop:
httpEndpoint: {{ .pokeshopHttp }}
grpcEndpoint: {{ .pokeshopGrpc }}{{end}}{{ if eq .enableOtelDemo "true" }}
grpcEndpoint: {{ .pokeshopGrpc }}
kafkaBroker: {{ .pokeshopKafka }}{{end}}{{ if eq .enableOtelDemo "true" }}
---
type: Demo
spec:
Expand Down
3 changes: 3 additions & 0 deletions cli/installer/tracetest.go
Expand Up @@ -18,13 +18,15 @@ func configureDemoApp(conf configuration, ui cliUI.UI) configuration {
case "docker-compose":
conf.set("demo.endpoint.pokeshop.http", "http://demo-api:8081")
conf.set("demo.endpoint.pokeshop.grpc", "demo-rpc:8082")
conf.set("demo.endpoint.pokeshop.kafka", "stream:9092")
conf.set("demo.endpoint.otel.frontend", "http://otel-frontend:8084")
conf.set("demo.endpoint.otel.product_catalog", "otel-productcatalogservice:3550")
conf.set("demo.endpoint.otel.cart", "otel-cartservice:7070")
conf.set("demo.endpoint.otel.checkout", "otel-checkoutservice:5050")
case "kubernetes":
conf.set("demo.endpoint.pokeshop.http", "http://demo-pokemon-api.demo")
conf.set("demo.endpoint.pokeshop.grpc", "demo-pokemon-api.demo:8082")
conf.set("demo.endpoint.pokeshop.kafka", "stream.demo:9092")
conf.set("demo.endpoint.otel.frontend", "http://otel-frontend.otel-demo:8084")
conf.set("demo.endpoint.otel.product_catalog", "otel-productcatalogservice.otel-demo:3550")
conf.set("demo.endpoint.otel.cart", "otel-cartservice.otel-demo:7070")
Expand Down Expand Up @@ -111,6 +113,7 @@ func getTracetestProvisionFileContents(ui cliUI.UI, config configuration) []byte
"enableOtelDemo": fmt.Sprintf("%t", config.Bool("demo.enable.otel")),
"pokeshopHttp": config.String("demo.endpoint.pokeshop.http"),
"pokeshopGrpc": config.String("demo.endpoint.pokeshop.grpc"),
"pokeshopKafka": config.String("demo.endpoint.pokeshop.kafka"),
"otelFrontend": config.String("demo.endpoint.otel.frontend"),
"otelProductCatalog": config.String("demo.endpoint.otel.product_catalog"),
"otelCart": config.String("demo.endpoint.otel.cart"),
Expand Down
5 changes: 2 additions & 3 deletions cli/openapi/api_resource_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions cli/openapi/model_demo_pokeshop.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions examples/docker-compose.demo.yaml
Expand Up @@ -18,6 +18,34 @@ services:
timeout: 5s
retries: 60

stream:
image: confluentinc/cp-kafka:latest-ubi8
ports:
- 29092:29092
environment:
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://stream:9092,PLAINTEXT_HOST://127.0.0.1:29092
- KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093,PLAINTEXT_HOST://:29092
- KAFKA_CONTROLLER_QUORUM_VOTERS=1@0.0.0.0:9093
- KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
- KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0
- KAFKA_PROCESS_ROLES=controller,broker
- KAFKA_NODE_ID=1
- KAFKA_METADATA_LOG_SEGMENT_MS=15000
- KAFKA_METADATA_MAX_RETENTION_MS=60000
- KAFKA_METADATA_LOG_MAX_RECORD_BYTES_BETWEEN_SNAPSHOTS=2800
- KAFKA_AUTO_CREATE_TOPICS_ENABLE=true
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
- KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1
- KAFKA_HEAP_OPTS=-Xmx200m -Xms200m
- CLUSTER_ID=ckjPoprWQzOf0-FuNkGfFQ
healthcheck:
test: nc -z stream 9092
start_period: 10s
interval: 5s
timeout: 10s
retries: 10

demo-api:
image: kubeshop/demo-pokemon-api:latest
restart: unless-stopped
Expand Down Expand Up @@ -88,3 +116,25 @@ services:
condition: service_healthy
queue:
condition: service_healthy

demo-streaming-worker:
image: kubeshop/demo-pokemon-api:latest
environment:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/postgres?schema=public
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
ZIPKIN_URL: http://localhost:9411
NPM_RUN_COMMAND: stream-worker
KAFKA_BROKER: 'stream:9092'
KAFKA_TOPIC: 'pokemon'
KAFKA_CLIENT_ID: 'streaming-worker'
REDIS_URL: cache
depends_on:
postgres:
condition: service_healthy
stream:
condition: service_healthy
cache:
condition: service_healthy
otel-collector:
condition: service_started
1 change: 1 addition & 0 deletions server/config/demo/demo_entities.go
Expand Up @@ -40,6 +40,7 @@ func (d Demo) Validate() error {
type PokeshopDemo struct {
HTTPEndpoint string `json:"httpEndpoint,omitempty"`
GRPCEndpoint string `json:"grpcEndpoint,omitempty"`
KafkaBroker string `json:"kafkaBroker,omitempty"`
}

type OpenTelemetryStoreDemo struct {
Expand Down
9 changes: 7 additions & 2 deletions server/config/demo/demo_repository_test.go
Expand Up @@ -21,6 +21,7 @@ func TestPokeshopDemoResource(t *testing.T) {
Pokeshop: &demo.PokeshopDemo{
HTTPEndpoint: "http://dev-endpoint:1234",
GRPCEndpoint: "dev-grpc:9091",
KafkaBroker: "dev-kafka:9092",
},
}

Expand All @@ -32,6 +33,7 @@ func TestPokeshopDemoResource(t *testing.T) {
Pokeshop: &demo.PokeshopDemo{
HTTPEndpoint: "http://stg-endpoint:1234",
GRPCEndpoint: "stg-grpc:9091",
KafkaBroker: "stg-kafka:9092",
},
}

Expand All @@ -43,6 +45,7 @@ func TestPokeshopDemoResource(t *testing.T) {
Pokeshop: &demo.PokeshopDemo{
HTTPEndpoint: "http://prod-endpoint:1234",
GRPCEndpoint: "prod-grpc:9091",
KafkaBroker: "prod-kafka:9092",
},
}

Expand Down Expand Up @@ -85,7 +88,8 @@ func TestPokeshopDemoResource(t *testing.T) {
"type": "pokeshop",
"pokeshop": {
"httpEndpoint": "http://dev-endpoint:1234",
"grpcEndpoint": "dev-grpc:9091"
"grpcEndpoint": "dev-grpc:9091",
"kafkaBroker": "dev-kafka:9092"
}
}
}`,
Expand All @@ -98,7 +102,8 @@ func TestPokeshopDemoResource(t *testing.T) {
"type": "pokeshop",
"pokeshop": {
"httpEndpoint": "http://new-dev-endpoint:1234",
"grpcEndpoint": "new-dev-grpc:9091"
"grpcEndpoint": "new-dev-grpc:9091",
"kafkaBroker": "new-dev-kafka:9092"
}
}
}`,
Expand Down
2 changes: 1 addition & 1 deletion server/go.mod
Expand Up @@ -97,12 +97,12 @@ require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.0 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.3 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jackc/puddle/v2 v2.2.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.16.6 // indirect
github.com/knadh/koanf v1.4.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion server/openapi/api_resource_api.go
Expand Up @@ -463,7 +463,7 @@ func (c *ResourceApiApiController) DeleteTestSuite(w http.ResponseWriter, r *htt

}

// DeleteVariableSet - Delete an variable set
// DeleteVariableSet - Delete a variable set
func (c *ResourceApiApiController) DeleteVariableSet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
variableSetIdParam := params["variableSetId"]
Expand Down
2 changes: 1 addition & 1 deletion server/openapi/api_resource_api_service.go
Expand Up @@ -178,7 +178,7 @@ func (s *ResourceApiApiService) DeleteTestSuite(ctx context.Context, testSuiteId
return Response(http.StatusNotImplemented, nil), errors.New("DeleteTestSuite method not implemented")
}

// DeleteVariableSet - Delete an variable set
// DeleteVariableSet - Delete a variable set
func (s *ResourceApiApiService) DeleteVariableSet(ctx context.Context, variableSetId string) (ImplResponse, error) {
// TODO - update DeleteVariableSet with the required logic for this service method.
// Add api_resource_api_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
Expand Down
3 changes: 3 additions & 0 deletions server/openapi/model_demo_pokeshop.go
Expand Up @@ -17,6 +17,9 @@ type DemoPokeshop struct {

// gRPC endpoint for Pokeshop API
GrpcEndpoint string `json:"grpcEndpoint,omitempty"`

// kafka broker for Pokeshop API
KafkaBroker string `json:"kafkaBroker,omitempty"`
}

// AssertDemoPokeshopRequired checks if the required fields are not zero-ed
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/Settings/Demo/PokeshopFields.tsx
Expand Up @@ -17,6 +17,12 @@ const PokeshopFields = () => {
<Input placeholder="demo-pokemon-api.demo:8082" />
</Form.Item>
</Col>

<Col span={12}>
<Form.Item label="Kafka Broker" name={[...baseName, 'kafkaBroker']}>
<Input placeholder="stream.demo:9092" />
</Form.Item>
</Col>
</Row>
);
};
Expand Down
19 changes: 17 additions & 2 deletions web/src/constants/Demo.constants.ts
Expand Up @@ -14,7 +14,11 @@ const userId = '2491f868-88f1-4345-8836-d5d8511a9f83';

export function getPokeshopDemo(demoSettings: Demo) {
const {
pokeshop: {httpEndpoint: pokeshopHttp = '', grpcEndpoint: pokeshopGrpc = ''},
pokeshop: {
httpEndpoint: pokeshopHttp = '',
grpcEndpoint: pokeshopGrpc = '',
kafkaBroker: pokeshopKafka = '',
},
} = demoSettings;

return {
Expand Down Expand Up @@ -114,6 +118,17 @@ export function getPokeshopDemo(demoSettings: Demo) {
command: `curl -XPOST -H "Content-type: application/json" --data '{"id":52}' '${pokeshopHttp}/pokemon/import'`,
},
],
[SupportedPlugins.Kafka]: [
{
name: 'Pokeshop - Import from Stream',
brokerUrls: [ `${pokeshopKafka}` ],
topic: 'pokemon',
headers: [],
messageKey: 'snorlax-key',
messageValue: '{"id":143}',
description: 'Import a Pokemon via Stream',
}
]
};
}

Expand Down Expand Up @@ -267,7 +282,7 @@ export function getDemoByPluginMap(demos: Demo[]) {
[SupportedPlugins.Postman]: (pokeshopDemoMap && pokeshopDemoMap[SupportedPlugins.Postman]) || [],
[SupportedPlugins.CURL]: (pokeshopDemoMap && pokeshopDemoMap[SupportedPlugins.CURL]) || [],
[SupportedPlugins.TraceID]: [],
[SupportedPlugins.Kafka]: [],
[SupportedPlugins.Kafka]: (pokeshopDemoMap && pokeshopDemoMap[SupportedPlugins.Kafka]) || [],
[SupportedPlugins.OpenAPI]: [],
};
}
3 changes: 2 additions & 1 deletion web/src/models/Demo.model.ts
Expand Up @@ -9,7 +9,7 @@ const Demo = ({
name = '',
type = 'pokeshop',
enabled,
pokeshop: {httpEndpoint = '', grpcEndpoint = ''} = {},
pokeshop: {httpEndpoint = '', grpcEndpoint = '', kafkaBroker = ''} = {},
opentelemetryStore: {
frontendEndpoint = '',
productCatalogEndpoint = '',
Expand All @@ -26,6 +26,7 @@ const Demo = ({
pokeshop: {
httpEndpoint,
grpcEndpoint,
kafkaBroker,
},
opentelemetryStore: {
frontendEndpoint,
Expand Down

0 comments on commit 847caca

Please sign in to comment.