Skip to content

Commit

Permalink
Merge branch 'main' into shippingservice-fix-context-prop
Browse files Browse the repository at this point in the history
  • Loading branch information
julianocosta89 authored Mar 27, 2024
2 parents 69a35e4 + 9ffee33 commit 0b00b61
Show file tree
Hide file tree
Showing 22 changed files with 307 additions and 38 deletions.
1 change: 1 addition & 0 deletions .github/workflows/assign-reviewers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:

jobs:
assign-reviewers:
if: github.repository == 'open-telemetry/opentelemetry-demo'
runs-on: ubuntu-latest
steps:
- uses: dyladan/component-owners@main
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:

jobs:
build_and_push_images:
if: github.repository == 'open-telemetry/opentelemetry-demo'
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: gradle/[email protected].1
- uses: gradle/[email protected].2
59 changes: 59 additions & 0 deletions .github/workflows/label-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
# adds a label to a pull request if certain files are changed
name: Label Pull Requests

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Check for changed files
id: file_changes
uses: dorny/paths-filter@v2
with:
list-files: shell
filters: |
docsUpdateRequired:
- 'src/flagd/**'
helmUpdateRequired:
- '.env'
- 'docker-compose*.yml'
- 'src/flagd/**'
- 'src/grafana/**'
- 'src/otelcollector/**'
- 'src/prometheus/**'
- name: "Add Label: docs-update-required"
if: steps.file_changes.outputs.docsUpdateRequired == 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue_number = context.issue.number;
github.issues.addLabels({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['docs-update-required']
})
- name: "Add Label: helm-update-required"
if: steps.file_changes.outputs.helmUpdateRequired == 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue_number = context.issue.number;
github.issues.addLabels({
issue_number: issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['helm-update-required']
})
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
jobs:
build_and_push_images:
uses: ./.github/workflows/build-images.yml
if: github.repository == 'open-telemetry/opentelemetry-demo'
with:
push: true
version: ${{ github.event.release.tag_name }}
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ the release.
([#1448](https://github.com/open-telemetry/opentelemetry-demo/pull/1448))
* [cartservice] update .NET to .NET 8.0.3
([#1460](https://github.com/open-telemetry/opentelemetry-demo/pull/1460))
* [adservice] add adServiceManualGC feature flag
([#1463](https://github.com/open-telemetry/opentelemetry-demo/pull/1463))
* [frontendproxy] remove deprecated start_child_span option
([#1469](https://github.com/open-telemetry/opentelemetry-demo/pull/1469))
* [currency] fix metric name
([#1470](https://github.com/open-telemetry/opentelemetry-demo/pull/1470))
* [frontend] disable instrumentation-fs library
([#1473](https://github.com/open-telemetry/opentelemetry-demo/pull/1473))

## 1.8.0

Expand Down
1 change: 0 additions & 1 deletion ide-gen-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ gen_proto_dotnet cartservice
gen_proto_go checkoutservice
# gen_proto_cpp currencyservice
# gen_proto_ruby emailservice
gen_proto_elixir featureflagservice
gen_proto_ts frontend
gen_proto_js paymentservice
gen_proto_go productcatalogservice
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/opentelemetry-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3214,7 +3214,7 @@ data:
"type": "prometheus",
"uid": "webstore-metrics"
},
"description": "Sent by Exporter\notelcol_exporter_send_failed_spans",
"description": "Sent by Exporter\notelcol_exporter_send_failed_metric_points",
"fieldConfig": {
"defaults": {
"color": {
Expand Down
4 changes: 2 additions & 2 deletions src/accountingservice/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
google.golang.org/grpc v1.62.0
google.golang.org/grpc v1.62.1
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.32.0
google.golang.org/protobuf v1.33.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions src/accountingservice/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe h1:
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe h1:bQnxqljG/wqi4NTXu2+DJ3n7APcEA882QZ1JvhQAq9o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
24 changes: 20 additions & 4 deletions src/adservice/src/main/java/oteldemo/AdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import oteldemo.Demo.Ad;
import oteldemo.Demo.AdRequest;
import oteldemo.Demo.AdResponse;
import oteldemo.problempattern.GarbageCollectionTrigger;
import dev.openfeature.contrib.providers.flagd.FlagdOptions;
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
import dev.openfeature.sdk.Client;
Expand Down Expand Up @@ -127,6 +128,9 @@ private enum AdResponseType {

private static class AdServiceImpl extends oteldemo.AdServiceGrpc.AdServiceImplBase {

private static final String ADSERVICE_FAILURE = "adServiceFailure";
private static final String ADSERVICE_MANUAL_GC_FEATURE_FLAG = "adServiceManualGc";

private AdServiceImpl() {}

/**
Expand Down Expand Up @@ -177,8 +181,14 @@ public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {
Attributes.of(
adRequestTypeKey, adRequestType.name(), adResponseTypeKey, adResponseType.name()));

if (checkAdFailure()) {
throw new StatusRuntimeException(Status.RESOURCE_EXHAUSTED);
if (getFeatureFlagEnabled(ADSERVICE_FAILURE)) {
throw new StatusRuntimeException(Status.UNAVAILABLE);
}

if (getFeatureFlagEnabled(ADSERVICE_MANUAL_GC_FEATURE_FLAG)) {
logger.warn("Feature Flag " + ADSERVICE_MANUAL_GC_FEATURE_FLAG + " enabled, performing a manual gc now");
GarbageCollectionTrigger gct = new GarbageCollectionTrigger();
gct.doExecute();
}

AdResponse reply = AdResponse.newBuilder().addAllAds(allAds).build();
Expand All @@ -193,12 +203,18 @@ public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {
}
}

boolean checkAdFailure() {
/**
* Retrieves the status of a feature flag from the Feature Flag service.
*
* @param ff The name of the feature flag to retrieve.
* @return {@code true} if the feature flag is enabled, {@code false} otherwise or in case of errors.
*/
boolean getFeatureFlagEnabled(String ff) {
Client client = OpenFeatureAPI.getInstance().getClient();
// TODO: Plumb the actual session ID from the frontend via baggage?
UUID uuid = UUID.randomUUID();
client.setEvaluationContext(new MutableContext().add("session", uuid.toString()));
Boolean boolValue = client.getBooleanValue("adServiceFailure", false);
Boolean boolValue = client.getBooleanValue(ff, false);
return boolValue;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package oteldemo.problempattern;

import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* The GarbageCollectionTrigger class is responsible for triggering manual garbage collection
* at specified intervals to simulate memory pressure and measure the impact on performance.
*/
public class GarbageCollectionTrigger {
private static final Logger logger = LogManager.getLogger(GarbageCollectionTrigger.class.getName());

private final long gc_delay;
private final int finalize_delay;
private final int maxObjects;

private long lastGC = 0;

private final MemoryUtils memUtils;

/**
* Constructs a new GarbageCollectionTrigger with default values.
*/
public GarbageCollectionTrigger() {
memUtils = new MemoryUtils(ManagementFactory.getMemoryMXBean());
gc_delay = TimeUnit.SECONDS.toMillis(10);
finalize_delay = 500;
maxObjects = 500000;
}

/**
* Triggers manual garbage collection at specified intervals and measures the impact on performance.
* It creates Entry objects to fill up memory and initiates garbage collection.
*/
public void doExecute() {
if (System.currentTimeMillis() - lastGC > gc_delay) {
logger.info("Triggering a manual garbage collection, next one in " + (gc_delay/1000) + " seconds.");
// clear old data, we want to clear old Entry objects, because their finalization is expensive
System.gc();

long total = 0;
for (int i = 0; i < 10; i++) {
while (memUtils.getHeapUsage() < 0.9 && memUtils.getObjectPendingFinalizationCount() < maxObjects) {
new Entry();
}
long start = System.currentTimeMillis();
System.gc();
total += System.currentTimeMillis() - start;
}
logger.info("The artificially triggered GCs took: " + total + " ms");
lastGC = System.currentTimeMillis();
}

}

/**
* The Entry class represents objects created for the purpose of triggering garbage collection.
*/
private class Entry {
/**
* Overrides the finalize method to introduce a delay, simulating finalization during garbage collection.
*
* @throws Throwable If an exception occurs during finalization.
*/
@SuppressWarnings("removal")
@Override
protected void finalize() throws Throwable {
TimeUnit.MILLISECONDS.sleep(finalize_delay);
super.finalize();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package oteldemo.problempattern;

import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


/**
* This class provides JVM heap related utility methods.
*/
public class MemoryUtils {

private static final Logger logger = LogManager.getLogger(MemoryUtils.class.getName());

private static final long NO_HEAP_LIMIT = -1;

private final MemoryMXBean memoryBean;

/**
* @param memoryBean defines which {@link MemoryMXBean} is to use
*/
public MemoryUtils(MemoryMXBean memoryBean) {
this.memoryBean = memoryBean;
}


/**
* @return The current heap usage as a decimal number between 0.0 and 1.0.
* That is, if the returned value is 0.85, 85% of the max heap is used.
*
* If no max heap is set, the method returns -1.0.
*/
public double getHeapUsage() {
MemoryUsage heapProps = memoryBean.getHeapMemoryUsage();
long heapUsed = heapProps.getUsed();
long heapMax = heapProps.getMax();

if (heapMax == NO_HEAP_LIMIT) {
if (logger.isDebugEnabled()) {
logger.debug("No maximum heap is set");
}
return NO_HEAP_LIMIT;
}


double heapUsage = (double) heapUsed / heapMax;
if (logger.isDebugEnabled()) {
logger.debug("Current heap usage is {0} percent" + (heapUsage * 100));
}
return heapUsage;
}

/**
* see {@link MemoryMXBean#getObjectPendingFinalizationCount()}
*/
public int getObjectPendingFinalizationCount() {
return memoryBean.getObjectPendingFinalizationCount();
}
}
10 changes: 5 additions & 5 deletions src/checkoutservice/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ go 1.22.0
require (
github.com/IBM/sarama v1.42.1
github.com/google/uuid v1.6.0
github.com/open-feature/go-sdk v1.10.0
github.com/open-feature/go-sdk-contrib/hooks/open-telemetry v0.3.1
github.com/open-feature/go-sdk-contrib/providers/flagd v0.1.22
github.com/sirupsen/logrus v1.9.3
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0
Expand All @@ -15,9 +18,9 @@ require (
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/sdk/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
google.golang.org/grpc v1.62.0
google.golang.org/grpc v1.62.1
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.32.0
google.golang.org/protobuf v1.33.0
)

require (
Expand Down Expand Up @@ -59,9 +62,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/open-feature/flagd/core v0.7.4 // indirect
github.com/open-feature/go-sdk v1.10.0 // indirect
github.com/open-feature/go-sdk-contrib/hooks/open-telemetry v0.3.1 // indirect
github.com/open-feature/go-sdk-contrib/providers/flagd v0.1.22 // indirect
github.com/open-feature/schemas v0.2.8 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
Expand Down
Loading

0 comments on commit 0b00b61

Please sign in to comment.