Skip to content

Instantly share code, notes, and snippets.

View sumanthkumarc's full-sized avatar

Sumanth Reddy sumanthkumarc

View GitHub Profile
@sumanthkumarc
sumanthkumarc / vacuum_stats.sql
Created July 12, 2024 09:57
Query to get auto vacuum/auto analyze stats from postgres database
SELECT pg_stat_all_tables.relname AS table_name,
COALESCE(NULLIF(pg_class.reltuples, -1), 0)::bigint AS live_tuples,
pg_stat_all_tables.n_dead_tup AS dead_tuples,
pg_stat_all_tables.n_ins_since_vacuum AS rows_inserted_since_vacuum,
pg_stat_all_tables.n_mod_since_analyze AS rows_modified_since_analyze,
(
COALESCE(NULLIF(pg_class.reltuples, -1), 0) * (
SELECT setting
FROM pg_settings
WHERE name = 'autovacuum_vacuum_scale_factor'
@sumanthkumarc
sumanthkumarc / GetMaterializedViewSize.sql
Created June 7, 2024 06:31 — forked from dadhi/GetMaterializedViewSize.sql
Find disk size of Postgres materialized view
/*
https://dba.stackexchange.com/questions/96534/postgres-check-disk-space-taken-by-materialized-view?newreg=6b1d58604fce4a1fbe3033ddbb52d7ca
relkind:
r = ordinary table,
i = index,
S = sequence,
v = view,
m = materialized view,
c = composite type,
@sumanthkumarc
sumanthkumarc / argocd-cm-full.yaml
Created May 12, 2023 11:17
argocd - custom actions added with upstream actions
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/component: server
app.kubernetes.io/instance: argocd
app.kubernetes.io/name: argocd-cm
name: argocd-cm
namespace: argocd
data:
@sumanthkumarc
sumanthkumarc / argocd-cm.yaml
Last active May 12, 2023 10:54
ArgoCD - custom action on deployment
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/component: server
app.kubernetes.io/name: argocd-cm
app.kubernetes.io/part-of: argocd
name: argocd-cm
namespace: argocd
data:
@sumanthkumarc
sumanthkumarc / dbconfig.yaml
Created February 10, 2023 06:45
Database config file sample for usql
databases:
my_handy_db_alias: # SOME HANDY IDENTIFIER KEY TO USE IN CLI ARGS FOR --db. USEFUL WHEN TWO DB'S ACROSS HOSTS HAS SAME NAME.
name: <DATABASE_NAME> # THIS IS THE ACTUAL DATABASE NAME
host: <WRITER_HOST_URL> # THIS IS THE DEFAULT HOST BEING USED FOR OPERATIONS.
reader_host: <READER_HOST_URL> # IDEA IS TO USE THIS AUTOMATICALLY FOR READER USER ROLE. THIS IS TODO FOR NOW.
port: <DB_PORT>
db_type: <DATABASE_TYPE> # THIS IS DIRECT RELATED TO USQL DRIVER NAMES. THE SCHEME PART OF DSN.
credentials:
- username: root
role: admin # USED IN CLI ARGS FOR --role.
# Copied from https://github.com/kumahq/kuma/blob/master/pkg/core/tokens/validator.go#L65
revoked, err := j.revocations.IsRevoked(ctx, claims.ID())
if err != nil {
return errors.Wrap(err, "could not check if the token is revoked")
}
if revoked {
return errors.New("token is revoked")
}
req, err := http.NewRequest("POST", "/tokens/dataplane", bytes.NewReader(reqBytes))
if err != nil {
return "", errors.Wrap(err, "could not construct the request")
}
@sumanthkumarc
sumanthkumarc / generate_signing_key.go
Created August 3, 2022 17:16
Code to ensure dp token signing key
// Copied from https://github.com/kumahq/kuma/blob/master/pkg/defaults/mesh/mesh.go#L60
created, err := ensureDataplaneTokenSigningKey(ctx, resManager, meshName)
if err != nil {
return errors.Wrap(err, "could not create default Dataplane Token Signing Key")
}
if created {
resKey := tokens.SigningKeyResourceKey(issuer.DataplaneTokenSigningKeyPrefix(meshName), tokens.DefaultSerialNumber, meshName)
@sumanthkumarc
sumanthkumarc / dataplane_token_auth.go
Created August 3, 2022 17:13
Function responsible for authenticating data plane token
// Copied from https://github.com/kumahq/kuma/blob/master/pkg/xds/auth/universal/authenticator.go
func (u *universalAuthenticator) authDataplane(ctx context.Context, dataplane *core_mesh.DataplaneResource, credential auth.Credential) error {
dpIdentity, err := u.dataplaneValidator.Validate(ctx, credential, dataplane.Meta.GetMesh())
if err != nil {
return err
}
if dpIdentity.Name != "" && dataplane.Meta.GetName() != dpIdentity.Name {
return errors.Errorf("proxy name from requestor: %s is different than in token: %s", dataplane.Meta.GetName(), dpIdentity.Name)
# each mapRoles entry maps an IAM role to a username and set of groups
# Each username and group can optionally contain template parameters:
# 1) "{{AccountID}}" is the 12 digit AWS ID.
# 2) "{{SessionName}}" is the role session name, with `@` characters
# transliterated to `-` characters.
# 3) "{{SessionNameRaw}}" is the role session name, without character
# transliteration (available in version >= 0.5).
mapRoles:
# statically map arn:aws:iam::000000000000:role/KubernetesAdmin to cluster admin
- roleARN: arn:aws:iam::000000000000:role/KubernetesAdmin