Can't delete metric. error "The metric was modified during the request." - google-cloud-functions

I want to delete log-based metric programmatically with a cloud functions. I wrote the following script:
for metric in client_metric.list_metrics():
if metric.name not in item_list:
metric.delete()
print('delete {}'.format(metric.name))
item_list contains the list of the metric I don't want to delete.
When testing the function I have the following error:
status = StatusCode.FAILED_PRECONDITION
details = "The metric was modified during the request."
debug_error_string = "{"created":"#1636482330.781263800","description":"Error received from peer ipv4:172.217.20.202:443","file":"src/core/lib/surface/call.cc","file_line":1069,"grpc_message":"The metric was modified during the request.","grpc_status":9}"
What's wrong here?

ok I need to define the metric before using it like this:
metric = client_metric.metric(
metric.name
)
Ultimately the code looks like this:
for metric in client_metric.list_metrics():
if metric.name not in item_list:
metric = client_metric.metric(
metric.name
)
metric.delete()
still I'm not sure I understand why it needs to be done like this.

Related

Power Query M - Expression Error - list to text

I'm doing a API request using Web.Contents. I submit a dynamic access token, which I get from a function.
let
Source =
Json.Document(
Web.Contents(
{"https://api-url.com/endpoint/id"},
[Headers=[Authorization="Bearer "& GetToken()]]))
in Source
This works in all of my other instances, but for some reason I get an error with a specific endpoint, to which I submit a id. The error is:
Expression.Error: We cannot convert a value of type List to type Text.
Details:
Value=[List]
Type=[Type]
I have checked the documentation for the API, and the response is composed of the following
id - Id of the device
lastServicedDate - The last time the service was done.
trip -
total -
stateLastUpdated - the timestamp of the state.
Previous assistance have informed me that I need to expand the list, but I cannot seem to make this work.
Any assistance is highly appreciated. Thank you.
You are supplying a list to Web.Contents instead of text. {} denotes a list. Remove your braces:
Web.Contents(
"https://api-url.com/endpoint/id",
[Headers=[Authorization="Bearer "& GetToken()]])

Wavefront Alerting when no data sent

I have wavefront alerts set up with the following alert condition:
ts(mytimeseries)<20000
Recently the datasource stopped sending data to wavefront but I did not receive an alert. I cannot figure out why this did not alert. Do I need to set up a separate alert for when data is not sent. Thanks
Yes in scenarios where there is no data sent you explicitly need to define the condition for that. Well the best approach is to create a new availability alert but still if you want to manipulate the same condition you can do something like below
default( 20001 ,ts(mytimeseries))<20000
In case there is no data found it will exceed your limit and will raise the alert

CSV Import task status in Netsuite

I am creating a task using the Scriptlet as below and submitting the task. This task may need 30 Sec to 5 min for completion. Now once I submit the job I dont have a control except the task id. I want to know the status or the message once the cob is finished or completed.
var cvsScriptTask = task.create({
taskType : task.TaskType.CSV_IMPORT ,
mappingId : cvsTask.mappingId ,
importFile : cvsFileObj ,
name : cvsFileObj.name ,
});
var csvImportTaskId = cvsScriptTask.submit();
Can I get the status of this task/job from some table/record ?
I think you are looking for Setup>Import/Export>View CSV Import Status
You can get the task status programmatically by using the N/task module and call task.checkStatus(taskID). See https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4345805891.html
Note that status COMPLETE only means that the CSV Import is done, not that it was successful. To see if all rows were imported you need to either check the UI Setup>Import/Export>View CSV Import Status (like #vVinceth suggested) or you can use SuiteQL to query SentEmail and parse the text in that email…
And even if you do find the SentEmail for the corresponding CSV Import it still doesn't say why some rows failed. That information is only available via the UI as far as I know. Very frustrating!

StudentSubmissions.Patch UpdateMask Error

Trying to use the StudentSubmissions.Patch part of the Classroom API in Google Apps Script and keeping running across this error
updateMask: updateMask may only contain "draftGrade" or
"assignedGrade"
Here is my code for that particular section:
var studentSubmission = {'draft_grade':'88'}
var patchC = Classroom.Courses.CourseWork.StudentSubmissions.patch(studentSubmission, courseId, cwId, submissionId);
There is clearly something wrong with the way I am passing the StudentSubmission Resource parameter, but I can't figure out why...
This is clearly the documentation I am referring to - https://developers.google.com/classroom/reference/rest/v1/courses.courseWork.studentSubmissions/patch
UPDATE
I was able to change the code a bit to reflect what you both were saying. Obviously, I didn't use exactly what you both said because KENdi's example is in Python and Ein2012, it would error out on the var patchC = Classroom... line.
I changed some things that now look like this:
var studentSubmission = {'draftGrade':'88'}
var extra = {'updateMask':'draftGrade'};
var patchC = Classroom.Courses.CourseWork.StudentSubmissions.patch(studentSubmission, courseId, cwId, submissionId, extra);
But now I get a different error "#ProjectPermissionDenied The Developer Console project is not permitted to make this request". So, now I'm unsure if that formatting is correct and there is some Developer Console situation I haven't resolved (although feel as though I'm correct), or that new formatting is wrong and I'm just getting the wild permission error.
I saw this Similar Error but what if the course work was one created normally through classroom and not via a script? Ahh.
specify update mask fields and later execute and also specify names as instructed in the documentation ("draftGrade","assignedGrade")
var studentSubmission = {'draftGrade':'88'}
var patchC = Classroom.Courses.CourseWork.StudentSubmissions.patch(studentSubmission, courseId, cwId, submissionId);
patchC.UpdateMask = "draftGrade";
var response = submisionObj.Execute();
From your error, it is stated that the updateMask must only contain "draftGrade" or "assignedGrade". So from your code, you need only that two value for the updateMask.
The updateMask identifies which fields on the student submission to update. This field is required to do an update. The update fails if invalid fields are specified
From this documentation, The StudentSubmission resource has two fields to store grades: assignedGrade, which is the grade reported to students, and draftGrade, which is a tentative grade visible only to teachers. These fields are updated using courses.courseWork.studentSubmissions.patch with a field mask containing the appropriate fields.
Here is the example code on how to do that.
studentSubmission = {
'assignedGrade': 99,
'draftGrade': 80
}
service.courses().courseWork().studentSubmission().patch(
courseId=<course ID or alias>,
courseWorkId=<courseWork ID>,
id=<studentSubmission ID>,
updateMask='assignedGrade,draftGrade',
body=studentSubmission).execute()

using reservation identification number in python script

When I initiate a new instance using boto, I get the reservation ID. But how do I use that reservation ID in the python script?
myreservation = conn.run_instances('ami-999c9999', placement='us-east-1a', key_name='nov15_key',instance_type='m1.xlarge',security_groups=['NuoDB-1-0-1-AutogenByAWSMP-'])
The next line does not work as expected:
myinstanceid = conn.get_all_instances(filters={'reservation-id':myreservation})[0].instances[0]
If I add the reservation ID in the code, it will work without any problem.
myinstanceid = conn.get_all_instances(filters={'reservation-id':'r-1e654a79'})[0].instances[0]
I will like to know what is the type of the reservation id and how to use it.
From the docs, run_instances returns this:
Returns:
The boto.ec2.instance.Reservation associated with the request for machines
Reservation has, also according to the docs, an instances slot which contains a list of boto.ec2.instance.Instance objects. It also has an "id" slot.
If you need the reservation id:
myreservation.id
And if you want the instance id:
myreservation.instances[0].id
So the Reservation object already has all the info you are looking for, no need to do a followup lookup call. But if you need to, you may want to try this:
myinstance = conn.get_all_instances(filters={'reservation-id':myreservation.id})[0]
Or better yet, this:
myinstanceid = conn.get_all_instances(filters={'reservation-id':myreservation.id})[0].id