Skip to content

Commit

Permalink
Merge branch 'main' into sanitize-environment
Browse files Browse the repository at this point in the history
  • Loading branch information
kanderson250 authored Oct 29, 2024
2 parents a0e9161 + ec234dd commit e3b8d0e
Show file tree
Hide file tree
Showing 57 changed files with 1,869 additions and 42 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow: Dependency Graph Submission and Vulnerability Reporting
#
# Trigger: This workflow runs on every merge to the main branch.
#
# Purpose: It generates and submits a dependency graph to the GitHub Dependency Submission API. The graph is used to
# trigger Dependabot Alerts for vulnerable dependencies, and to populate the Dependency Graph insights view in GitHub.
#
# Excludes:
# - Test-only dependencies

name: Dependency Submission

on:
push:
branches: [ 'main' ]

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # pin@v4
with:
ref: 'main'

- name: Set gradle.properties Workaround
shell: bash
run: |
echo "jdk8=/tmp" >> gradle.properties
echo "jdk11=/tmp" >> gradle.properties
echo "jdk17=/tmp" >> gradle.properties
echo "jdk21=/tmp" >> gradle.properties
- name: Setup Java
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # pin@v4
with:
distribution: 'temurin'
java-version: '11'

- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@d156388eb19639ec20ade50009f3d199ce1e2808 # pin@v4
with:
dependency-graph-exclude-configurations: '.*[Tt]est(Compile|Runtime)Classpath'
dependency-graph-include-configurations: '.*(includeInJar|shadowIntoJar).*'
build-scan-publish: true
build-scan-terms-of-use-url: "https://gralde.com/help/legal-terms-of-use"
build-scan-terms-of-use-agree: "yes"
33 changes: 0 additions & 33 deletions .github/workflows/snyk_scan.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public final class AgentBridge {

public static volatile AsyncApi asyncApi = new NoOpAsyncApi();

public static volatile CloudApi cloud = NoOpCloud.INSTANCE;

public static volatile CollectionFactory collectionFactory = new DefaultCollectionFactory();

/**
Expand Down
31 changes: 31 additions & 0 deletions agent-bridge/src/main/java/com/newrelic/agent/bridge/CloudApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package com.newrelic.agent.bridge;

import com.newrelic.api.agent.Cloud;
import com.newrelic.api.agent.CloudAccountInfo;

/**
* Internal Cloud API. This extends the public Cloud API and adds methods
* for retrieving the data set by the public API methods.
*/
public interface CloudApi extends Cloud {

/**
* Return the general account information of the provided type.
* This data is either set by {@link Cloud#setAccountInfo(CloudAccountInfo, String)}
* or the agent config.
*/
String getAccountInfo(CloudAccountInfo cloudAccountInfo);

/**
* Retrieves the account information for a cloud service SDK client.
* If no data was recorded for the SDK client, the general account information will be returned.
*/
String getAccountInfo(Object sdkClient, CloudAccountInfo cloudAccountInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.newrelic.agent.bridge;

import com.newrelic.api.agent.AiMonitoring;
import com.newrelic.api.agent.Cloud;
import com.newrelic.api.agent.Config;
import com.newrelic.api.agent.ErrorApi;
import com.newrelic.api.agent.Insights;
Expand Down Expand Up @@ -73,6 +74,11 @@ public AiMonitoring getAiMonitoring() {
return NoOpAiMonitoring.INSTANCE;
}

@Override
public Cloud getCloud() {
return NoOpCloud.INSTANCE;
}

@Override
public ErrorApi getErrorApi() {
return NoOpErrorApi.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package com.newrelic.agent.bridge;

import com.newrelic.api.agent.CloudAccountInfo;

public class NoOpCloud implements CloudApi {

public static final CloudApi INSTANCE = new NoOpCloud();

private NoOpCloud() {
// only instance should be the INSTANCE
}

@Override
public void setAccountInfo(CloudAccountInfo cloudAccountInfo, String value) {
}

@Override
public void setAccountInfo(Object sdkClient, CloudAccountInfo cloudAccountInfo, String value) {
}

@Override
public String getAccountInfo(CloudAccountInfo cloudAccountInfo) {
return null;
}

@Override
public String getAccountInfo(Object sdkClient, CloudAccountInfo cloudAccountInfo) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.newrelic.agent.bridge.TracedMethod;
import com.newrelic.agent.bridge.Transaction;
import com.newrelic.api.agent.AiMonitoring;
import com.newrelic.api.agent.Cloud;
import com.newrelic.api.agent.Config;
import com.newrelic.api.agent.ErrorApi;
import com.newrelic.api.agent.Insights;
Expand Down Expand Up @@ -44,6 +45,11 @@ public AiMonitoring getAiMonitoring() {
return null;
}

@Override
public Cloud getCloud() {
return null;
}

@Override
public ErrorApi getErrorApi() { throw new RuntimeException(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.newrelic.agent.InstrumentationProxy;
import com.newrelic.agent.core.CoreService;
import com.newrelic.agent.service.AbstractService;
import com.newrelic.agent.superagent.HealthDataChangeListener;
import com.newrelic.agent.superagent.HealthDataProducer;

class IntrospectorCoreService extends AbstractService implements CoreService {
class IntrospectorCoreService extends AbstractService implements CoreService, HealthDataProducer {
private InstrumentationProxy instrumentation = null;

public IntrospectorCoreService() {
Expand Down Expand Up @@ -48,4 +50,7 @@ public boolean isEnabled() {
return true;
}

@Override
public void registerHealthDataChangeListener(HealthDataChangeListener listener) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.newrelic.agent.service.module.JarData;
import com.newrelic.agent.sql.SqlTrace;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.trace.TransactionTrace;
import com.newrelic.agent.transaction.TransactionNamingScheme;

Expand Down Expand Up @@ -162,6 +163,11 @@ public void sendErrorEvents(int reservoirSize, int eventsSeen, Collection<ErrorE
public void sendErrorData(List<TracedError> tracedErrors) {
}

@Override
public HealthDataProducer getHttpDataSenderAsHealthDataProducer() {
return null;
}

@Override
public String getEntityGuid() {
return "";
Expand Down
7 changes: 6 additions & 1 deletion newrelic-agent/src/main/java/com/newrelic/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.newrelic.agent.service.ServiceManagerImpl;
import com.newrelic.agent.stats.StatsService;
import com.newrelic.agent.stats.StatsWorks;
import com.newrelic.agent.superagent.AgentHealth;
import com.newrelic.agent.superagent.SuperAgentIntegrationUtils;
import com.newrelic.agent.util.UnwindableInstrumentation;
import com.newrelic.agent.util.UnwindableInstrumentationImpl;
import com.newrelic.agent.util.asm.ClassStructure;
Expand Down Expand Up @@ -290,12 +292,15 @@ private static boolean tryToInitializeServiceManager(Instrumentation inst) {
ServiceManager serviceManager = new ServiceManagerImpl(coreService, configService);
ServiceFactory.setServiceManager(serviceManager);

if (isLicenseKeyEmpty(serviceManager.getConfigService().getDefaultAgentConfig().getLicenseKey())) {
AgentConfig agentConfig = serviceManager.getConfigService().getDefaultAgentConfig();
if (isLicenseKeyEmpty(agentConfig.getLicenseKey())) {
SuperAgentIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(agentConfig, AgentHealth.Status.MISSING_LICENSE);
LOG.error("license_key is empty in the config. Not starting New Relic Agent.");
return false;
}

if (!serviceManager.getConfigService().getDefaultAgentConfig().isAgentEnabled()) {
SuperAgentIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(agentConfig, AgentHealth.Status.AGENT_DISABLED);
LOG.warning("agent_enabled is false in the config. Not starting New Relic Agent.");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.agent.tracers.Tracer;
import com.newrelic.api.agent.AiMonitoring;
import com.newrelic.api.agent.Cloud;
import com.newrelic.api.agent.ErrorApi;
import com.newrelic.api.agent.Insights;
import com.newrelic.api.agent.Logger;
Expand Down Expand Up @@ -144,6 +145,11 @@ public AiMonitoring getAiMonitoring() {
return new AiMonitoringImpl();
}

@Override
public Cloud getCloud() {
return AgentBridge.cloud;
}

@Override
public Logs getLogSender() {
return ServiceFactory.getServiceManager().getLogSenderService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.newrelic.agent.service.module.JarData;
import com.newrelic.agent.sql.SqlTrace;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.trace.TransactionTrace;
import com.newrelic.agent.transaction.TransactionNamingScheme;

Expand Down Expand Up @@ -90,4 +91,6 @@ public interface IRPMService extends Service {
void sendSpanEvents(int reservoirSize, int eventsSeen, final Collection<SpanEvent> events) throws Exception;

void sendErrorData(List<TracedError> tracedErrors) throws Exception;

HealthDataProducer getHttpDataSenderAsHealthDataProducer();
}
10 changes: 10 additions & 0 deletions newrelic-agent/src/main/java/com/newrelic/agent/MetricNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ public class MetricNames {

public static final String TIMEOUT_ASYNC = "Java/Timeout/asyncActivityNotStarted";

public static final String SUPPORTABILITY_AZURE_SITE_EXT_INSTALL_TYPE = "Supportability/Java/InstallType";

public static final String SUPPORTABILITY_JAVA_AGENTVERSION = "Supportability/Java/AgentVersion/{0}";

public static final String SUPPORTABILITY_HARVEST_SERVICE_RESPONSE_TIME = "Supportability/Harvest";
Expand Down Expand Up @@ -361,6 +363,11 @@ public class MetricNames {
public static final String SUPPORTABILITY_API_SET_ACCOUNT_NAME = "SetAccountName";
public static final String SUPPORTABILITY_API_SET_USER_ID = "SetUserId";

// Cloud API
public static final String SUPPORTABILITY_API_CLOUD_SET_ACCOUNT_INFO_CLIENT = "Cloud/SetAccountInfoClient/";
public static final String SUPPORTABILITY_API_CLOUD_SET_ACCOUNT_INFO = "Cloud/SetAccountInfo/";
public static final String SUPPORTABILITY_CONFIG_AWS_ACCOUNT_ID = "Supportability/Cloud/ConfigAccountInfo/aws_account_id";

//Transaction supportability metrics
public static final String SUPPORTABILITY_TRANSACTION_STARTED = "Supportability/Transaction/StartedCount";
public static final String SUPPORTABILITY_TRANSACTION_FINISHED = "Supportability/Transaction/FinishedCount";
Expand Down Expand Up @@ -501,6 +508,9 @@ public class MetricNames {
// AiMonitoring Callback Set
public static final String SUPPORTABILITY_AI_MONITORING_TOKEN_COUNT_CALLBACK_SET = "Supportability/AiMonitoringTokenCountCallback/Set";

// Super Agent Integration
public static final String SUPPORTABILITY_SUPERAGENT_HEALTH_REPORTING_ENABLED = "Supportability/SuperAgent/Health/enabled";

/**
* Utility method for adding supportability metrics to APIs
*
Expand Down
13 changes: 11 additions & 2 deletions newrelic-agent/src/main/java/com/newrelic/agent/RPMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import com.newrelic.agent.service.module.JarData;
import com.newrelic.agent.sql.SqlTrace;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.AgentHealth;
import com.newrelic.agent.superagent.HealthDataChangeListener;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.trace.TransactionTrace;
import com.newrelic.agent.transaction.TransactionNamingScheme;
import com.newrelic.agent.transport.ConnectionResponse;
Expand All @@ -58,14 +61,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;

/**
* The RPMService acts as a stub for communication between the agent and New Relic.
*/
public class RPMService extends AbstractService implements IRPMService, EnvironmentChangeListener, AgentConfigListener {
public class RPMService extends AbstractService implements IRPMService, EnvironmentChangeListener,
AgentConfigListener {

public static final String COLLECT_TRACES_KEY = "collect_traces";
public static final String COLLECT_ERRORS_KEY = "collect_errors";
Expand Down Expand Up @@ -986,6 +991,11 @@ private void removeHarvestablesFromServices(String appName) {
ServiceFactory.getHarvestService().removeHarvestablesByAppName(appName);
}

@Override
public HealthDataProducer getHttpDataSenderAsHealthDataProducer() {
return (HealthDataProducer) dataSender;
}

@Override
public long getConnectionTimestamp() {
return connectionTimestamp;
Expand All @@ -1004,5 +1014,4 @@ public void configChanged(String appName, AgentConfig agentConfig) {
// reset our error logging so that something will show up at info level if data failures persist
last503Error.set(0);
}

}
Loading

0 comments on commit e3b8d0e

Please sign in to comment.