Elastic apm - Disable transaction/span programatically for specific endpoint - java

I am using elastic-apm with spring application to monitor API requests and track all SQL's executed for given endpoint. The problem is give the amount of traffic elastic search is collecting huge magnitude of data and I would like to enable capturing span only for specific endpoints.
I tried using public api of elastic-apm https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html
I can customize a transaction and span but I couldn't find a way to enable/disable to specific endpoints.
I have tried this but no luck -
ElasticApm.currentSpan().startSpan();
ElasticApm.currentSpan().end();

Looks like it can be done using drop_event processor in api-server.yml.
processors:
- drop_event:
when:
equals:
transaction.custom.transactions_sampled: false
and in code set custom context:
Transaction elasticTransaction = ElasticApm.currentTransaction();
elasticTransaction.addCustomContext("transactions.sampled", false);

Related

How to use secret manager endpoint in lambda handler?

I want to make a write to RDS from lambda. As they both are in different accounts, I created a peering connection between them and also created a secret endpoint to access it. I have a non-rotational secret manager endpoint, I have a lambda handler like
LambdaHandler:
Type: AWS::Serverless::Function
Properties:
Handler: 'com.handle.lambda.handler.LambdaHandler::handleInputFeed'
Runtime: java8
CodeUri:
# Why are we using this instead of BATS::SAM::CodeS3Bucket
Bucket: {'Fn::If' : ['UseBatsKey', 'BATS::SAM::CodeS3Bucket', {"Fn::ImportValue" : {Ref: 'DeploymentBucketImportName'}}]}
Key: BATS::SAM::CodeS3Key
Description: Example lambda that takes an x and y value and returns the result of adding them.
Timeout: 20
Role:
Fn::GetAtt: [LambdaRole, Arn]
VpcConfig:
Fn::If:
- RunLambdaInVPC
- SecurityGroupIds: [{Ref: LambdaSecurityGroup}]
SubnetIds:
- {'Fn::ImportValue': PrivateSubnet01}
- {'Fn::ImportValue': PrivateSubnet02}
- {Ref: 'AWS::NoValue'}
How the secret endpoint will be used in this handler and how can I refer to the tables via that? As I am new to this any sample code or doc would be helpful. Not able to find.
You don't need to do anything1 , if the Lambda function is running inside the VPC with the endpoint accessible. Depending on the kind of Endpoint (Interface or Gateway) there are some DNS-tricks (Private Hosted Zones set up for you by AWS) employed by AWS to make this seem seamless.
Essentially the code doesn't need to know it's talking to a VPC endpoint, that's handled in the background. There are a couple exceptions that have bitten me in the past - see the footnote. If it doesn't work, make sure the security groups of the endpoint allow connections from the Lambda functions on Port 443.
1: The exception being IAM and other global services, here you should specify a regional endpoint when instantiating the client.

How can you do a persistent search using the Apache 2.0.1 LDAP API in JAVA

I am wondering if there is a way to connect to ldap (389 server) through the apache 2.0.1 java ldap api and then continuously listen for changes to a specific attribute on a set of entries (in this case people with specific qualifications)?
Ideally I would like to run a query on ou=people,dc=test,dc=local
this might initially return
dn: uid=tester1,ou=people,dc=test,dc=local
givenName: tester1
dn: uid=tester2,ou=people,dc=test,dc=local
givenName: tester2
dn: uid=tester3,ou=people,dc=test,dc=local
givenName: tester3
If I then in the background changed tester3's givenName to userTester3 I would like to have a listener that would return some userModified event telling me that tester3 was modified.
As an example of what I would like to happen (psuedo code / non functioning code) I would like to do something along the lines of :
{
PersistentSearch ps = new PersistentSearch();
ps.setChangeType(ChangeType.MODIFY);
SearchRequest sr = ldaputility.createPersistentSearch(qualifiers, attributes, etc, ps);
PersistentSearchListener psl = new PersistentSearchListener(sr){
#Override
public void entryChanged(Entry e){
Log.info("The entry just changed");
}
}
}
There however from what I can tell in the apache 2.0.1 api is not any persistent search listener nor is there any type of listener for search requests in general and the search request gets results and then completes. I know that in the netscape api there is a search listener and that in the apache directory server api there is a persistent search listener. So what I am asking is does anyone know if the apache 2.0.1 ldap api supports a behavior where you make an initial query and any time the results of the query change you can have a listener that is notified of the new changes?
I unfortunately have no debugging code / output since I am not even sure what code to try right now.
It appears that by adding a PersistentSearch control (with changes only set to true and change types set to modifications) to the search request the ldap server won't ever set isDone to true on the search request so then the search request will continue to return the updates as they are available.

Couchbase Client Configuration for enhanced durability

I am trying to implement ATPlus scan consistency within my couchbase java application. I have updated my queries to include the consistentWith(mutationState):
RawJsonDocument courseJsonDocument = toRawJsonDocument(course, true);
RawJsonDocument insertedJsonDocument = bucket.insert(courseJsonDocument);
MutationState insertMutationState = MutationState.from(insertedJsonDocument);
.....
N1qlQuery.simple(GET_COURSE_BY_ID_QUERY, N1qlParams.build().consistentWith(mutationState));
I'm trying to achieve read-your-own-write, but when I run the query immediately after inserting the document, nothing is found, so I must be doing something wrong. I think what I am missing is actually enabling enhanced durability on the client configuration.
I see examples of how to do it in .NET, but I can't figure out how to 'enable enhanced durability' in JAVA. Here is my cluster configuration:
Cluster cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder()
.queryServiceConfig(QueryServiceConfig.create(1, 100))
.mutationTokensEnabled(true)
.observeIntervalDelay(Delay.fixed(100, TimeUnit.MICROSECONDS))
.connectTimeout(timeout)
.build(),
clusterHost);

Fetching info from JVM MBeans

I was trying to fetch the below details for my monitoring application using JVM MBeans
thread-states.blocked
thread-states.waiting
gc.ConcurrentMarkSweep.runs
gc.ParNew.runs
thread_count
daemon_thread_count
memory.heap_usage
memory.non_heap_usage
I am able to fetch most of them except
thread-states.blocked
thread-states.waiting
gc.ConcurrentMarkSweep.runs
gc.ParNew.runs
Does anybody know what MBean and attribute can be used to collect these values?
PS: i have googled this before posting it here
thread-states.blocked
thread-states.waiting
you can use getAllThreadIds() and get each Thread's information getThreadInfo() and filter based on the state
gc.ConcurrentMarkSweep.runs
gc.ParNew.runs
get getGarbageCollectorMXBeans() filter them for CMS and ParNew and getCollectionCount()

In java, how can I get an Amazon EC2 Instance to see its own tags?

So I have a java program running within an Amazon EC2 instance. Is there a way to programatically get its own tags? I have tried instantiating a new AmazonEC2Client to us the describeTags() function but it only gives me null. Any help would be appreciated thank you.
Edit: To make things clearer, the instances are going to be unmanned worker machines spun up to solely do some computations
This should help you get started...
String instanceId = EC2MetadataUtils.getInstanceId();
AmazonEC2 client = AmazonEC2ClientBuilder.standard()
.withCredentials(new DefaultAWSCredentialsProviderChain())
.build();
DescribeTagsRequest req = new DescribeTagsRequest()
.withFilters(new Filter("resource-id", Collections.singletonList(instanceId)));
DescribeTagsResult describeTagsResult = client.describeTags(req);
List<TagDescription> tags = describeTagsResult.getTags()
You should be able to get the current instance id by sending a request to: http://169.254.169.254/latest/meta-data/instance-id. This only works within ec2. With this you can access quite a bit of information about the instance. However, tags do not appear to be included.
You should be able to take the instance id along with the correct authentication to get the instance tags. If you are going to run this on an instance, you may want to provide an IAM user with limited access instead of a user which has access to everything in case the instance is compromised.
While using user-data may be the simplest solution, the OP was asking specifically about the tagging, and unfortunately amazon hasn't made this as easy as it could be. However, It can be done. You want to use a combination of 2 amazon services.
First you need to retrieve the Instance ID. This can be achieved by hitting the URL from within your instance:
http://169.254.169.254/latest/meta-data/instance-id
Once you have the resource ID, you'll want to use Amazon's EC2 API to access the tags. Since you said you're using Java, I would suggest the Using the AWS SDK amazon makes available. Within this SDK you'll find a method called describeTags (documentation). You can use a Resource ID as one of the filters to get the specific tags to your instance. Supported filters are
tag key
resource-id
resource-type
I suggest doing this retrieval at boot using something like cloud-init and caching the tags on your server for use later if necessary.

Categories

Resources