Skip to content

Instantly share code, notes, and snippets.

@michaelawyu
michaelawyu / istio-dr-crd.yaml
Created October 14, 2025 09:38
Istio DR CRD (for Demo Purposes)
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
"helm.sh/resource-policy": keep
labels:
app: istio-pilot
chart: istio
heritage: Tiller
release: istio
public class StreamingJob {
public static void main(String[] args) throws Exception {
// Set up the streaming execution environment
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.enableCheckpointing(4000);
// Set up a Cloud Pub/Sub topic as input
// deserializer controls how Apache Flink deserializes the message
// A wrapper for rejecting dead-lettered events.
module.exports = functions.https.onRequest(async (req, res) => {
try {
return await fulfill(req, res);
} catch (err) {
console.log(err.message);
// Stripe webhook events are delivered via HTTP. Here it is wrapped in
// a Cloud Event and rejected to DLQ via Cloud Pub/Sub.
const stripeWebhookEventRejected = utils.createStripeWebhookEventRejectedEvent(SOURCE, req.headers, req.body, err.message);
await utils.publishEvent(pubSubClient, DLQ, stripeWebhookEventRejected);
const tracing = require('@opencensus/nodejs');
const { StackdriverTraceExporter } = require('@opencensus/exporter-stackdriver');
const exporter = new StackdriverTraceExporter({projectId: "YOUR-GCP-PROJECT"});
const tracer = tracing.registerExporter(exporter).start({ samplingRate: 1 }).tracer();
function A () {
let traceId;
tracer.startRootSpan({ name: 'A' }, rootSpan => {
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
// const logName = 'customLog';
// const resourceType = 'cloud_function';
// const labels = {
// 'source': 'fulfillment',
// 'orderId': 'myOrderId'
// };
async function fulfill (req, res) {
...
// Rejects stale events.
utils.checkForExpiredEvents('POSIX', paymentIntent.created, EVENT_MAX_AGE);
// Checks if the event is duplicated.
await utils.guaranteeExactlyOnceDelivery(firestoreClient, EVENT_COLLECTION, paymentIntent.id, JSON.stringify(paymentIntent));
...
}
from mypackage import Basic
# Attributes id and time will be auto-populated
# If not specified, attributes source, type, and specversion use their respective default values
event = Basic(data = 'Hello World!')
event_json_str = event.to_JSON()
import datetime
import json
import uuid
event = {}
event['id'] = str(uuid.uuid4())
event['source'] = 'my-event-source'
event[type] = 'my-event-type'
event['specversion'] = '0.3'
event['time'] = datetime.datetime.utcnow().isoformat('T') + 'Z'
Attribute Name Type Note
id String Required. The ID of the event. A CloudEvent is uniquely identified with its source and id.
source String (URI-reference) Required. The source of the event.
specversion String Required. The version of CloudEvents Specification the Cloud Event uses.
type String Required. The type of the event.
datacontentencoding String (RFC 2045 Section 6.1) Optional. The encoding of
events:
# Define an event type, basic
basic:
attributes:
# Set up an attribute id which is auto-poulated with UUIDv4 string
id:
type: string
format: UUIDv4
auto: true
# Set up an attribute source with a default value